qt多窗口程序

 


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;
}


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值