I recently migrated my Qt project from Linux to Vista, and now I'm debugging signals blindly.
On Linux, if QObject::connect() fails in a debug build, I get a warning message on stderr. On Windows, there is no console output for GUI applications, only an OutputDebugString call.
I already installed DebugView, and it catches my own qDebug() output nicely, but still no warning on failed signals.
One possible solution would be to use QtCreator's autocomplete for signals, but I like Eclipse, and using both is a PITA. Any ideas on how to get signal/slot info at runtime?
Edit: I just realized connect() returns bool, which solves the immediate problem, ugly as it may be. However, this doesn't solve the cases where QMetaObject::connectSlotsByName() fails, and this one runs automatically with widgets.
Call the static function QErrorMessage::qtHandler().
As per the documentation, this 'installs a message handler using qInstallMsgHandler() and creates a QErrorMessage that displays qDebug(), qWarning() and qFatal() messages'.
Alternatively, install a message handler with qInstallMsgHandler().
Another alternative (described in a qt-interest post) is something like this:
#ifdef _DEBUG
#define connect( connectStmt ) Q_ASSERT( connect( connectStmt ) )
#endif
...and for what it's worth, here are some signals and slots debugging suggestions I compiled: http://samdutton.wordpress.com/2008/10/03/debugging-signals-and-slots-in-qt/
The solution I like for this is to set
QT_FATAL_WARNINGS=1
in the environment of the program when you debug. That makes the program crash, giving you a nice backtrace, especially if you run the code in a debugger. If you don't want the crash, see the answer above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With