Is it possible to determine on run-time if a QCoreApplication or a QApplication is running?
Is it possible to determine on run-time if a QCoreApplication or a QApplication is running?
There is QCoreApplication::startingUp() if that's what you are after.
Unfortunately not! I would need to determine if a console (QCoreApplication) or GUI (QApplication) has been instantiated.
You mean you want to know whether you have a QCoreApplication instance or a QApplication instance? That's quite easy actually:
But the fact that you have a QApplication instance doesn't mean you have a GUI. QApplication can be used with a console app as well (see the third parameter to one of QApplicaiton constructors).Qt Code:
To copy to clipboard, switch view to plain text mode
doberkofler (16th September 2010)
Is there a way to determine if I'm running a console or a GUI app?
QApplication::type() looks very promising but failing that I suspect QApplication::topLevelWidgets() should be non-empty for a GUI app.
doberkofler (16th September 2010)
I must be missing the obvious... How can you have a GUI without any top level widgets? This list will contain top level widgets even if they are hidden from view.
I meant a GUI app, not a GUI so this is a perfectly good GUI app:
Qt Code:
#include <QtGui> int main(int argc, char **argv){ return app.exec(); }To copy to clipboard, switch view to plain text mode
But even if we talk about an app that has a GUI this is still possible - you can have an application that only has a system tray icon, I doubt that's considered a "top-level widget".
Besides, I think the OP wants to be able to check the availability of the GUI at an arbitrary moment so it might happen that he does it when no windows are present in the application (visible or not).
I make of with the following that seems to work fine for me:
Qt Code:
bool isGuiApp() { bool aIsGuiApp = false; if (aApplication) { } return aIsGuiApp; }To copy to clipboard, switch view to plain text mode
Bookmarks