Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Weird issue: Debugger won't start when qInstallMsgHandler is used

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

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 2 Posters 1.4k Views 1 Watching
  • 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 Offline
    E Offline
    elevenfound
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • E Offline
        E Offline
        elevenfound
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0

          • Login

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