QApplication segmentation fault

2019-05-08 02:59发布

问题:

I get a crash when try to create a QApplication object. This is my code:

#include <QLabel>
#include <QApplication>

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);
    return app.exec();
}

I am using Qt version 4.8.4 and the MinGW compiler. My application crashes when running QCoreApplicationPrivate::processCommandLineArguments method. Can anybody tell how to solve this problem?

回答1:

Apparently, this error is caused by binary incompatibility of Qt binaries and your compiler.

From here:

There are binary installers targetting MinGW for both Qt 4 and Qt 5. The Qt 4 ones are built with aMinGW.org toolchain using gcc 4.4. The Qt 5 ones are based on a MinGW-builds toolchain [sourceforge.net] using gcc 4.7.2. The Qt 5 installer also ships the toolchain itself.

If you are using gcc 4.7 (I think this is the default version with the latest MinGW), you can't compile (well, you can, but it will not work) with Qt 4 precompiled binaries.

So, either downgrade your gcc to 4.4 version, or upgrade Qt to latest (Qt 5) version.