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



  • 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.


  • Lifetime Qt Champion

    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



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


  • Lifetime Qt Champion

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.