c++ - 将 QwtPlot 添加到代码时出现段错误

标签 c++ qt segmentation-fault qwt

我尝试使用 QwtPlot,但是当我将这一行添加到我的 MainWindow.cpp

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

应用程序编译和链接没有错误,但是当我尝试运行它时我得到了

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

没有任何回溯。我的 .pro 文件:

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

我正在使用 Qwt 6.0.2、Qt Creator 2.7.0 并安装了 Qt 4.8.4 和 5.0.2。

当我创建“Qt Gui 应用程序”(没有 .ui 文件)并且只有这段代码时,也会出现错误:

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

主要.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();
}

主窗口.hpp

#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP

#include <QMainWindow>

class MainWindow : public QMainWindow
{
    Q_OBJECT

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

#endif // MAINWINDOW_HPP

主窗口.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()
{
}

谢谢!

最佳答案

这是 Qt Creator 的一个问题(或者 Qwt 与 Qt 5 不兼容),它将 qmake 识别为 Qt 4 的 qmake 但它是用于 Qt 5 的。修复选项 -> 构建&运行 -> Qt 版本中的版本并使用 Qt 4 为项目修复了段错误。

关于c++ - 将 QwtPlot 添加到代码时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16468312/

相关文章:

c++ - 隐式将返回的左值视为右值

c++ vector 不在嵌套for循环中更新

c++ - 将捕获 lambda 包装为模板函数中的函数指针

c - 当我尝试使用函数中通过引用传递的预分配矩阵读取值时出现段错误

插入到二叉树中的 C 段错误

c++ - 打印原子枚举值时 gdb 崩溃

C++ 链接自定义 .so 库,然后使用 JNI

windows - 在 QT 程序中全局强制 QFileDialog::DontUseNativeDialog

c++ - "Could not determine which "制作 "command to run. Check the "制作 "step in the build configuration."Qt 创建者

c++ - Qt5 : Get value of item clicked in a listview