[Interest] Weird issue: Debugger won't start when qInstallMsgHandler is used
Mike Nolan
me at mknln.com
Thu Sep 4 20:57:33 CEST 2014
I have a weird issue that I finally tracked down.
I am using Qt Creator (2.8.1). When I was 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 and debugging would start.
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);
}
(Theres a few things to explain here: Im calling emitMessageHandled,
rather than emitting the signal directly, because were 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 wont continue. Since the QML file isnt 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 hasnt loaded yet) but Id like to understand this better.
-- Version info --
Qt Creator: 2.8.1
Qt: 4.8.4
More information about the Interest
mailing list