日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

qt show widget_Qt中show()与exec()

發布時間:2025/3/13 64 豆豆
生活随笔 收集整理的這篇文章主要介紹了 qt show widget_Qt中show()与exec() 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.?show()默認顯示的是非模態對話框,即此對話框出現后你還可以對其他窗口進行操作,可以用setModal函數進行設置窗口為模態,即無法操作其他窗口,即被阻塞. 而exec()出現的只能是模態對話框.

2. show()顯示的窗口無論是否模態,都立刻將操作權返回, 運行下面代碼;而exec()則是得等待exec出的窗口關閉后再運行下面代碼.

qt幫助文檔那個中寫的是:Shows the dialog as a modal dialog, blocking until the user closes it. The function returns a DialogCode result., 返回的DialogCode 有QDialog::Accepted和QDialog::Rejected,可以根據返回值來進行判斷等操作.

下面是一個小程序:

#ifndef DIALOG1_H

#define DIALOG1_H

#include

#include "ui_dialog1.h"

class dialog1 : public QDialog

{

Q_OBJECT

public:

dialog1(QWidget *parent = 0);

protected slots:

void buttonClicked();

private:

Ui::dialog1 ui;

};

#endif // DIALOG1_H

/*multiwindow.h*/#ifndef MULTIWINDOW_H

#define MULTIWINDOW_H

#include "dialog1.h"

#include

#include "ui_multiwindow.h"

class multiWindow : public QMainWindow

{

Q_OBJECT

public:

multiWindow(QWidget *parent = 0);

public slots:

void button1Clicked();

private:

Ui::multiWindowClass ui;

dialog1 *dialog;

};

#endif // MULTIWINDOW_H

/*dialog1.cpp*/#include "dialog1.h"

dialog1::dialog1(QWidget *parent)

: QDialog(parent)

{

ui.setupUi(this);

connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));

}

void dialog1::buttonClicked()

{

this->close();

}

/*multiwindow.cpp*/#include "multiwindow.h"

multiWindow::multiWindow(QWidget *parent)

: QMainWindow(parent)

{

ui.setupUi(this);

connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(button1Clicked()));

connect(ui.pushButton_3, SIGNAL(clicked()), this, SLOT(close()));

dialog = new dialog1(this);

}

void multiWindow::button1Clicked()

{

this->hide();

//dialog->show();

dialog->exec();

this->show();

}/*main.cpp*/#include "multiwindow.h"

#include

int main(int argc, char *argv[])

{

QApplication a(argc, argv);

multiWindow w;

w.show();

return a.exec();

}

重點是multiwindow.cpp中的this->hide();

dialog->exec();

this->show();當按下按鈕時,先將主窗口隱藏,然后顯示exec的模態對話框,不繼續執行下面代碼,等待對話框的操作, 按下對話框的按鈕后,對話框關閉,繼續執行主對話框代碼,將主對話框顯示,即實現對話框的調用.

若將exec替換為show,則會出現兩個對話框并存的現象.

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的qt show widget_Qt中show()与exec()的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。