I have a utility class in my Qt GUI application. However, in my convenience class I wanted to call a QMessageBox::critical()
, warning()
, etc. The class isn't a QWidget
, and therefore I cannot pass this
as the parent. My class is subclassed from QObject
, however, so it can run things such as signals and slots. So to work around this--if it's possible to--should I maybe look at the property API instead of using the Static API?
Class declaration:
class NetworkManager : public QObject
And here's an example of a Static API call that fails:
QMessageBox::critical(this, tr("Network"), tr("Unable to connect to host.\n"),
QMessageBox::Ok | QMessageBox::Discard);
So, if I were to build a Property based API message box, would it be possible to call it in a QObject
somehow? I haven't really used the Property Based API, but I understand from the documentation that it seems to use an event loop (i.e. exec()
).
Just pass NULL
for the first parameter:
QMessageBox::critical(NULL, QObject::tr("Error"), QObject::tr("..."));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With