I am trying to make a Qt 5 application with a few Qwt widgets, but I see a segmentation fault in Qt's code as soon as I try linking the Qwt libraries. I am using a very simple Qt program that only pops a blank window:
#include <QApplication>
#include <QWidget>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(250, 150);
window.setWindowTitle("Simple example");
window.show();
return app.exec();
}
This works fine when I compile normally. The problems start as soon as I add LIBS += -lqwt
to my .pro file. It will still compile, but segmentation faults when I try to run it, even without anything calling Qwt code.
Backtrace:
Program received signal SIGSEGV, Segmentation fault.
QList (this=0x3ea60da418 <QPrinterInfoPrivate::shared_null+24>) at ../../src/corelib/tools/qlist.h:121
121 inline QList() : d(&QListData::shared_null) { d->ref.ref(); }
(gdb) bt
#0 QList (this=0x3ea60da418 <QPrinterInfoPrivate::shared_null+24>) at ../../src/corelib/tools/qlist.h:121
#1 QPrinterInfoPrivate (name=..., this=0x3ea60da400 <QPrinterInfoPrivate::shared_null>) at painting/qprinterinfo_p.h:71
#2 __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at painting/qprinterinfo.cpp:35
#3 _GLOBAL__sub_I_qprinterinfo.cpp(void) () at painting/qprinterinfo.cpp:163
#4 0x0000003e9c20f2ea in call_init (l=<optimized out>, argc=argc@entry=1, argv=argv@entry=0x7fffffffddb8, env=env@entry=0x7fffffffddc8) at dl-init.c:82
#5 0x0000003e9c20f3d3 in call_init (env=<optimized out>, argv=<optimized out>, argc=<optimized out>, l=<optimized out>) at dl-init.c:34
#6 _dl_init (main_map=0x3e9c421168, argc=1, argv=0x7fffffffddb8, env=0x7fffffffddc8) at dl-init.c:130
#7 0x0000003e9c20122a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
As you can see, the segfault occurs in Qt's code without ever getting to the code in main.cpp
. What is causing this, and how do I fix it?
I am using Qt 5.2.0 and Qwt 6.1.0 on Fedora 20, both from the repositories.
ldd
tells me the repo version is linked tolibQtCore.so.4 => /lib64/libQtCore.so.4
and a few more Qt .so's, but the version I compiled from source (using qmake-qt5) is too, and that doesn't seem to have the same problem. – Spleenfuldebug
version to a Qtrelease
application and vice versa. I have Qt 5.7 and using the latest Qwt and haven't got a single problem with it. The fact that Qwt shows that its linked against Qt 4.x can only mean that 1)you have the wrong package installed or 2)there is no Qwt linked against Qt 5.2 in the repositories. Safest way is to build Qwt on your own with the version you are using for your project. – Allard