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 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
I was looking for a way to make my error handling working in console and GUI applications. If I'm running without a GUI, I will no longer try to offer the user a "nice" graphical error dialog.
Any better way to do this?
Are you writing a library or is it for your own application?
A library for a set of own applications
If you don't intend to ever link with QtGui and run a non-gui application then you don't have to worry about it. It's a bit strange combination anyway.
Maybe I got it wrong but I for example this is exactly my setup when compiling my QTest based test cases that need to be linked with QtGui but internally QTest instantiates a console application.
So you are instantiating a QCoreApplication yourself?
No, I'm using the QTEST_APPLESS_MAIN() macro.
So you don't have any application object - neither console nor non-console. In this case QCoreApplication::startingUp() would be enough.
Bookmarks