我尝试使用 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/