#include #include #include class ModalDialog : public QDialog { Q_OBJECT public: ModalDialog(QWidget *parent = 0); public slots: void slotLongOperation(); }; class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); public slots: void slotShowModalDialog(); }; ModalDialog::ModalDialog(QWidget *parent) : QDialog(parent) { setWindowTitle("ModalDialog"); setModal(true); resize(400, 400); QPushButton *btnLO = new QPushButton("Begin Long Task!", this); btnLO->resize(200, 35); connect(btnLO, SIGNAL(clicked()), this, SLOT(slotLongOperation())); } void ModalDialog::slotLongOperation() { qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); QThread::sleep(3); qApp->restoreOverrideCursor(); QMessageBox mBox(this); mBox.setText("Long Task Completed!"); mBox.exec(); } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setWindowTitle("MainWindow"); QPushButton* btn = new QPushButton("Open Dialog", this); btn->resize(200, 35); QHBoxLayout *layout = new QHBoxLayout; layout->setMargin(10); layout->addWidget(btn); setLayout(layout); connect(btn, SIGNAL(clicked()), this, SLOT(slotShowModalDialog())); } void MainWindow::slotShowModalDialog() { ModalDialog dlg(this); dlg.exec(); } #include "main.moc" int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.resize(800, 400); w.show(); return a.exec(); }