QT学习笔记(五)登录注册、打开保存文件

// 模态对话框
void Widget::on_pushButton_2_clicked()
{
    Login dlg;
 
  
    // 会接管 app  exec,处理消息事件
    int ret = dlg.exec();
    if (ret == QDialog::Accepted)      // 调用accept函数结束窗口返回  Accepted
        qDebug() << "登录成功";
    else if (ret == QDialog::Rejected) // 调用reject函数结束窗口返回  Rejected
        qDebug() << "登录失败";
}
 
  
void Widget::on_pushButton_3_clicked()
{
    QColorDialog dlg;
    QColor c = dlg.getColor();
    qDebug() << c;
}
 
  
void Widget::on_pushButton_4_clicked()
{
    QFontDialog dlg;
    bool ok;
    QFont f = dlg.getFont(&ok);
    qDebug() << f;
}
 
  
void Widget::on_pushButton_5_clicked()
{
    QString fileName = QFileDialog::getOpenFileName(this, "Open File",
                                                    "../",
                                                    "Images (*.png *.xpm *.jpg);;"
                                                    "source files (*.c *.cpp *.hpp *.cc);;"
                                                    "header files (*.h);;"
                                                    "ALL(*)");
    qDebug() << "要打开的文件:" << fileName;
}
void Widget::on_pushButton_6_clicked()
{
    QString fileName = QFileDialog::getSaveFileName(this, "save File",
                                                    "../",
                                                    "Images (*.png *.xpm *.jpg);;"
                                                    "source files (*.c *.cpp *.hpp *.cc);;"
                                                    "header files (*.h);;"
                                                    "ALL(*)");
    qDebug() << "要保存的文件:" << fileName;
}

需要头文件

#ifndef LOGIN_H
#define LOGIN_H
 
  
#include 
 
  
namespace Ui {
class Login;
}
 
  
class Login : public QDialog
{
    Q_OBJECT
 
  
public:
    explicit Login(QWidget *parent = 0);
    ~Login();
 
  
private slots:
    void on_pushButton_clicked();
 
  
private:
    Ui::Login *ui;
};
 
  
#endif // LOGIN_H
 
  

你可能感兴趣的:(QT)