Thanks.
Let me be more specific:
*** questions below ***
I call:
qInstallMsgHandler(myMsgHandler);
to install my own message handler, which follows:
void myMsgHandler(QtMsgType type , const char *msg)
{
QString text;
if (strstr(msg, "Object::connect:") != NULL)
{
return;
}
switch (type)
{
case QtDebugMsg:
text = QString ("Debug: %1\n").arg(msg);
break;
case QtWarningMsg:
text = QString ("Warning: %1\n").arg(msg);
break;
case QtCriticalMsg:
text = QString ("Critical: %1\n").arg(msg);
break;
case QtFatalMsg:
text = QString ("Fatal: %1\n").arg(msg);
break;
}
// Display a message to the user
if (this thread is gui thread) *** How do I get the thread to see if this is a GUI thread? ***
{
QMessageBox::information(NULL, QString("Error"), text); // this only works if this handler was called from a GUI thread
}
else
{
*** how to display error to user from a non-gui thread? ***
}
#ifndef NDEBUG // when in debug mode, do this
#ifdef WINDOWS
OutputDebugStringA(text.toAscii().data()); // this works if we are in debug
#else // non-windows
fprintf(stderr(text.toAscii()));
#endif
}
#endif
if (type == QtFatalMsg)
{
abort();
}
return;
}
Qt Code:
// only windows has a "default" msg handler, 0 is returned on other platforms! QtMsgHandler msgHandler = qInstallMsgHandler(myMsgHandler); void myMsgHandler(QtMsgType type , const char *msg) { ... { // gui thread } if (msgHandler) { // call the default windows handler msgHandler(type, msg); } else { fprintf(stderr, qPrintable(text)); } ... }To copy to clipboard, switch view to plain text mode
J-P Nurmi
Or you can emit a signal from that thread if you don't want to implement a custom event.You can send an event with error message (for example to a QApplication subclass) and show that message box in the event handler.
Emitting a signal might be a good way to go.
Thanks.
- Bruce
One other quick question - how can I tell if the current thread is the GUI thread?
bruccutler (19th May 2007)
Oops -- Seeing I could not see. Now I've seen.
Bookmarks