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.

1 Answer 1

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();
}
Sign up to request clarification or add additional context in comments.

2 Comments

"from an application that is not already a Qt application", but you're assuming that a QMake .pro file already exists.
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.