Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Weird issue: Debugger won't start when qInstallMsgHandler is used

    Tools
    2
    4
    979
    Loading More Posts
    • 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.
    • E
      elevenfound last edited by

      I have a weird issue that I finally tracked down.

      I am using Qt Creator. When I'm in debug mode, and hit the Start Debugging button, the application would never actually load. Finally, I traced it down to qInstallMsgHandler -- if I commented out that line then the application would again load.

      The code looked like this:

      @
      static void msgHandler(QtMsgType type, const char msg) {
      Q_UNUSED(type);
      Q_UNUSED(msgHandler);
      ((MyApp
      )qApp)->emitMessageHandled(type, msg);
      }

      MyApp::MyApp(int & argc, char **argv) : QApplication(argc, argv) {
      qInstallMsgHandler(msgHandler);
      }
      @

      (There's a few things to explain here: I'm calling emitMessageHandled, rather than emitting the signal directly, because we're in a static function. That signal is caught by a QML file that is loaded later on, which then has a logging object that can write to a file, add to a queue in memory, etc.)

      What I found -- the weird part -- is that I could work around the issue by adding something like this:
      @
      static void msgHandler(QtMsgType type, const char *msg) {
      Q_UNUSED(type);
      Q_UNUSED(msgHandler);

      // Workaround
      if (strstr(msg, "QDeclarativeDebugServer") > 0) {
      printf("%s\n", msg);
      fflush(stdout);
      }
      // End workaround

      ((MyApp*)qApp)->emitMessageHandled(type, msg);
      }
      @

      Basically, it seems as though the QDeclarativeDebugServer must have its message outputted or it won't continue. Since the QML file isn't loaded at the time it wants to print (and it handles the output), I force the output here, enabling it to continue.

      I cannot understand why this is, however. Is this a bug in QDeclarativeDebugServer or am I maybe breaking a rule about using qInstallMsgHandler? I have a slightly better workaround (always printing if the QML file hasn't loaded yet) but I'd like to understand this better.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        I would rather bring this to the interest mailing list. You'll find there Qt's developers/maintainers. This forum is more user oriented

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • E
          elevenfound last edited by

          Thanks, I didn't realize. I'll post it there and check back in if I learn anything.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            No problem with that, you might be lucky here also :)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post