Segmentation fault in Qt code when linking Qwt libraries
Asked Answered
S

1

6

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.

Spleenful answered 10/2, 2014 at 16:12 Comment(6)
Is Qwt 6.1 linked to Qt version 4 or Qt version 5 on Fedora? Because this works for me on Arch.Rudiment
ldd tells me the repo version is linked to libQtCore.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.Spleenful
Everything that you link into your project must be compiled using the same C++ compiler and must use the same major Qt version.Decagon
Is there any suggestion to solve this problem? I have the same issue :(Mincemeat
You should compile all packages (whatever you are doing + qwt) with the same Qt version, AND link to that version. If you compiled with qmake-qt5 and ldd says the library is linked to libQtCore.so.4 something is wrong.Gunrunning
@cauchy is right. Compiling Qwt takes a couple of minutes even on my 8 year old notebook. Also careful not to link Qwt debug version to a Qt release 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
F
1

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.

Fitts answered 17/9, 2016 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.