Showing a messagebox from library

444 views Asked by At

I need to show a messagebox to user from my static library but using QMessageBox needs QApplication;

How can I show a message box without QApplication?

1

There are 1 answers

0
selbie On BEST ANSWER

Just instantiate an instance of QApplication for the lifetime of the app. (e.g. in your "main", "WinMain", or somewhere early in your app initialization sequence)

From then on, you can create modal instances of QMessageBox all you want. It should co-exist fine with your own message pump as long as you are using a recent version of Qt.

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QMessageBox msgBox;
    msgBox.setText("Hello World");
    msgBox.exec();  // blocks until the user finishes interacting with the message box

    return 0;
}