How to properly display error messages without parent window
-
I'm implementing exception handling currently for my tool. My problem is that I may have errors that I wish to display in a context where I don't have a parent window to provide for
QErrorMessage
or similar because- I don't have a window yet
- I'm in a context where I don't know of any windows. I would have to drag a reference through multiple function headers or add a member reference to classes in places where I don't need it for anything else.
What is the proper way to display an error in a PopUp Window similar to
QErrorMessage
in a context where I don't have a window to reference to?
Using the no-parameter ctor doesn't show anything, even though thecatch
block is reached:try { param = findParamByName(json["param"].toString().toStdString(), allParams); } catch(ParamNotFoundException &e) { QString errorMessage("Parameter " + e.what + " not found"); //simplified QErrorMessage q; q.showMessage(errorMessage); }
-
@lp2020 said in How to properly display error messages without parent window:
Using the no-parameter ctor doesn't show anything, even though the catch block is reached
Actually it does show the message, but (https://doc.qt.io/qt-5/qerrormessage.html#showMessage)
"Shows the given message, message, and returns immediately".
Since q lives inside catch block it is destroyed just after calling showMessage.
Declare q in a way it does not go out of scope (allocate on the heap or make it class member).