Cory Klein
Cory Klein

Reputation: 55690

Can you cause Qt to assert, segfault, or otherwise crash when a QObject::connect() fails?

I'm using Qt 4.8.x so I don't have access to the new connect interface from Qt5, but I want to be alerted better when a signal/slot connection fails because I misspelled a signal or slot name.

Currently, all Qt does is spit out an error message when the connection is attempted. However, my program has a lot of output on stdout so it is easy to miss these errors sometimes. Is it possible to force my application to crash via assert, segfault, or other method, when a connect statement fails?

Upvotes: 12

Views: 2733

Answers (2)

peppe
peppe

Reputation: 22744

Yes: set the QT_FATAL_WARNINGS environment variable to a non-zero value.

You can do this during development in Qt Creator by going to the Projects pane, click Run, then under "Run Environment" click Details, then click Add.

Edit to add: you can of course also implement some wrappers for QObject::connect, that will check its return value and assert() if it returns false.

Upvotes: 12

CmdrMoozy
CmdrMoozy

Reputation: 3931

I think at least one of the solutions in this question: Qt GUI app: warning if QObject::connect() failed? does what you need.

In particular, by using QErrorMessage::qtHandler you should be able to intercept those warnings and do whatever you want with them.

Upvotes: 4

Related Questions