Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 278
Cory Klein Avatar asked Jun 27 '13 20:06

Cory Klein


2 Answers

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.

like image 95
peppe Avatar answered Oct 20 '22 22:10

peppe


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.

like image 39
CmdrMoozy Avatar answered Oct 20 '22 21:10

CmdrMoozy