Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Error Message box without using QGuiApplication
abhishekm last edited by abhishekm
I am building a cross platform application using Qt Quick/qml. I would like to show an error message box without using QGuiApplication or QApplication. There can be situations where I do not have a QApplication instantiated or in any situation, it is not getting instantiated. Hence, in such cases, if any exception occurs, would like to show a message box to the user.
Using the qMessageHandler, I can capture the signal from OS. But how can this error be shown as a message/error window for all platform ?
Is there any way a message box can be shown without using QApplication for windows, macOS, android and ios ?
There can be situations where I do not have a QApplication initialized or in any situation, it is not getting initialized
What would be such a situation? I mean, QApplication is usually the first thing instantiated in a Qt application. "it is not getting initialized" - in such a situation you should not expect to be able to show any UI reliably as your application is in an undefined state.
What is your use case?
abhishekm last edited by
@jsulm As you mentioned, because the application is in an undefined state, would like to show a message to the user; lets say - user needs to reinstall the application due to some error/configuration; or the system is out of memory; My application also does a bunch of internal things before QApplication is instantiated. If I still want to show a message to the user, how would the same be achieved ? Does this help in the use case ?
Pablo J. Rogina last edited by
My application also does a bunch of internal things before QApplication is instantiated
Why not reverse the order? I mean, initialize QApplication as soon as possible, then do the bunch of internal things
JonB last edited by
My application also does a bunch of internal things before QApplication is instantiated. If I still want to show a message to the user, how would the same be achieved ? Does this help in the use case ?
I do not believe that is possible. You need at least a QGuiApplication
Since the QGuiApplication object does so much initialization, it must be created before any other objects related to the user interface are created.
To use Qt's cross-platform abstraction even for displaying a
QMessageBox, you need that, in fact you need a
QApplicationwhich inherits from
QGuiApplication. I can't think of anything Qt you can use to display a message box without that. Unless you want to write your own native calls.