1、QDialog的显示
QDialog的显示有两个函数show()和exec()。他们的区别在参考文档上的解释如下:
show():
显示一个非模式对话框。控制权即刻返回给调用函数。
弹出窗口是否模式对话框,取决于modal属性的值。
(原文:Shows the dialog as a modeless dialog. Control returns immediately to the calling code.
The dialog will be modal or modeless according to the value of the modal property. )
exec():
显示一个模式对话框,并且锁住程序直到用户关闭该对话框为止。函数返回一个DialogCode结果。
在对话框弹出期间,用户不可以切换同程序下的其它窗口,直到该对话框被关闭。
(原文:Shows the dialog as a modal dialog, blocking until the user closes it. The function returns a DialogCode result.
Users cannot interact with any other window in the same application until they close the dialog. )
可以指定mode=ture来调用show(),也会停在当前对话框,但是还是会执行后面的代码
exec()会停在当前对话框,而不会执行下面的代码
2、定义一个对话框类
选择: qt设计者界面类
3、两种信号和槽关联的方法
一是:直接在设计器中实现其关联
在信号与槽编辑器中编辑
二是:自己写槽函数语句
右击按钮选择进入槽编辑
比方说要单击按钮关闭当前界面并进入主界面
在按钮的accept方法下
void logindlg::on_loginbtn_clicked()
{
accept();
}
在主函数中
#include <QtGui/QApplication>
#include "widget.h"
#include "logindlg.h" //对话框类
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
logindlg login; //对话框对象
if(login.exec() == QDialog::Accepted)
{
w.show();
return a.exec();
}
else
return 0;
}