For my event log, I wanted to display an error message box. I avoided WinAPI (in which it is really easy...) for portability.
After downloading and building Qt, I used the following code to try to show a message box: return QMessageBox::warning(0, Caption.c_str(), Message.c_str());
But when I build it in debug configuration it says "QWidget: Must construct a QApplication before a QPaintDevice" (and in release config it just dies silently).
I don't really know much about Qt yet, but does this mean I'm going to have to create a whole Qt Application object just to display a message box?
Or is there some other fix?
I know I can do that, but this is supposed to be a standalone component in a static library, and I don't want the user having to create the Qt app.
Can I give the application to the log as a member, or am I not allowed multiple QApplications at once? Also, don't I have to call app.quit() at the end.
Well, to have anything GUI related happen in QT you need a QApplication object.
From QT documentation wrote:
Since the QApplication object does so much initialization, it must be created before any other objects related to the user interface are created.
Can I give the application to the log as a member, or am I not allowed multiple QApplications at once?
From QT documentation wrote:
For any GUI application using Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any given time.
Also, don't I have to call app.quit() at the end.
---- Possibly not in our simple example ----
From QT documentaion wrote:
Generally, no user interaction can take place before calling QApplication::exec(). As a special case, modal widgets like QMessageBox can be used before calling exec(), because modal widgets call exec() to start a local event loop.
Thanks for your help, and sorry it's taken me a few days to reply.
For now, I only need Qt support for an error message box, but I suppose I might use it elsewhere later. Thus, shall I just have a global scope QApplication as part of the library? It would seem silly to require the user to create it.