Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Segmentation fault in Qt code when linking Qwt libraries

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.

like image 540
monkeypants Avatar asked Feb 10 '14 16:02

monkeypants


1 Answers

In current Fedora 23, you may install system packages: qwt and qwt-qt5 (plus -devel packages for these). You may accidentally link Qwt to a Qt 5-based project and indeed get the segmentation fault, because the "qwt" package is for Qt 4.

In order to avoid the segmentation fault, you must specify a library that is built with Qt 5, that is, -lqwt-qt5 in your build, not -lqwt.

E.g. in my .pro file:

unix|win32: LIBS += -lqwt-qt5

This resolves the issue.

like image 157
onkami Avatar answered Sep 17 '22 11:09

onkami