gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:55:26 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com