Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to properly display error messages without parent window
Qt 6.11 is out! See what's new in the release blog

How to properly display error messages without parent window

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 777 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lp2020
    wrote on last edited by
    #1

    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

    1. I don't have a window yet
    2. 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 the catch 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);
      }
    
    jsulmJ 1 Reply Last reply
    0
    • L lp2020

      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

      1. I don't have a window yet
      2. 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 the catch 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);
        }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • L Offline
        L Offline
        lp2020
        wrote on last edited by
        #3

        Thank you.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved