0

Referencing an earlier question: GTK implementation of MessageBox

I have a question very much like that one, except substituting Qt for GTK.

As in that question, what is the least I would need to do to show a message dialog using Qt, from an application that is not already a Qt application?

I presume something like the following would need to occur:

  • Initialize Qt and its event loop
  • Install idle callback to invoke dialog
  • Quit event loop and finalize Qt when dialog is dismissed.
Community
  • 1
  • 1
kbluck
  • 11,530
  • 4
  • 25
  • 25

1 Answers1

0

You are tring to show a message box from a console application right ?

If this is correct you need to add this line in your pro file:

QT += gui

After you have done that in your main.cpp file write something like this. Qt creates an event loop for you

#include <QtCore/QCoreApplication>
#include <QTextStream>
#include <QMessageBox>
#include <QApplication>




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

    QMessageBox::information(NULL,"Hello","Salut","Ok");

    return a.exec();
}
opc0de
  • 11,557
  • 14
  • 94
  • 187
  • "from an application that is not already a Qt application", but you're assuming that a QMake `.pro` file already exists. – MSalters Oct 16 '12 at 11:43
  • Yes, I would not be using QMake. Build config is not a concern for me. I don't see anything here that would tell the main event loop to terminate. Does the message box become the "main window," thus causing the event loop to terminate when it closes? – kbluck Oct 16 '12 at 15:06