Question

I try to use QwtPlot, but when i add this line to my MainWindow.cpp

QwtPlot *plot = new QwtPlot(QwtText("Demo"), this);

the application compile and link without errors, but when I try to run it I get

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff514227c in ?? () from /usr/lib/libQtGui.so.4

without any backtrace. My .pro file:

INCLUDEPATH += /usr/include/qwt
CONFIG += qwt
LIBS += -lqwt

I'm using Qwt 6.0.2, Qt Creator 2.7.0 and have Qt 4.8.4 and 5.0.2 installed.

The error also occours when I create a "Qt Gui Application" (without .ui file) and just this code:

qwt-test.pro

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = qwt-test
TEMPLATE = app

INCLUDEPATH += /usr/include/qwt
CONFIG += qwt
LIBS += -lqwt

SOURCES += main.cpp\
        MainWindow.cpp

HEADERS  += MainWindow.hpp

main.cpp

#include "MainWindow.hpp"
#include <QApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    qDebug() << "main";
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

MainWindow.hpp

#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP

#include <QMainWindow>

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();
};

#endif // MAINWINDOW_HPP

MainWindow.cpp

// MainWindow.cpp
#include "MainWindow.hpp"

#include <qwt_plot.h>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    QwtPlot *plot = new QwtPlot(QwtText("Demo"), this);
}

MainWindow::~MainWindow()
{
}

Thanks!

Was it helpful?

Solution

It was a problem with Qt Creator (or Qwt being incompatible with Qt 5), it recognized qmake as qmake for Qt 4 but it was for Qt 5. Fixing the versions in Options -> Build&Run -> Qt Versions and using Qt 4 for the project fixed the segfault.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top