Reputation: 1429
When I try using Exceptions with Qt the application crashes instant on any throw statement, ignoring any catch(...)
-clauses. This is the minimal code that causes the crash:
#include <QString>
int main ( ) {
try {
throw 1;
} catch (...) {
QString a;
}
}
Without the QString
it works fine, even if the library is included.
The Exception Code I get is
40000015
and the offset:
0000bb3f
I'm using QtCreator 2.7.2 with Qt 5.1.0 and mingw 4.8 (the version shipped with QtCreator). I used windows 8 for my builds.
After some research in the web I tried to add the CONFIG+=exceptions
flag to the *.pro-file and still got the crash.
When I read that Qt can be build without exceptions (whatever that means) I checked the default values as I'm using the pre-compiled version shipped with the QtCreator; this one should be built including exceptions.
I checked the temp code after the pre-compiler and the pre-compiler didn't change anything for the main function.
When I tried debugging the code I noticed that it didn't execute any line after the throw statement, it really crashes exactly there.
I'm still a beginner with Qt; is this a problem for this built of Qt? should I just get a newer one? Or did I miss some configs I could change in order to get it working?
EDIT: After Frank Osterfeld asked me to I tried with several other classes. Here are my findings:
std::string
QPoint
QChar
QDate
QMessageLogger
QString
QByteArray
QDir
QException
QFile
QRegularExpression
QSet<int>
QTimer
Upvotes: 4
Views: 1284
Reputation: 643
Qt application crashes instant on any throw statement - I found this happens when application compiled with flag -static
.
QMAKE_LFLAGS *= -static
Environment: Qt 5.5.1, mingw 32bit runtime, Windows 8.
Upvotes: 1
Reputation: 11046
I'm using Qt 5.2.1.
I ran into a situation where this kind of throw would cause the application to crash (but not always!):
try{ throw; } catch(...){ }
I replaced that with
try{ throw 1; } catch(...){ }
And it fixed the problem. Not sure why or when exactly this change was needed, but this might help someone out...
Upvotes: 0
Reputation: 1429
I finally solved this by reinstalling the whole Computer. I had to do this anyway and it fixed the problem when I downloaded the new Version of QtCreator (3.0.0).
Probably it would have been enough to reinstall Qt though.
Upvotes: 0