【问题标题】:Segfault when adding QwtPlot to the code将 QwtPlot 添加到代码时出现段错误
【发布时间】:2013-05-09 18:12:39
【问题描述】:

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

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()
{
}

谢谢!

【问题讨论】:

  • 把这个 QwtText("Demo") 改成 "Demo"
  • 这就是我的第一个,给我一个error: no matching function for call to 'QwtPlot::QwtPlot(const char [5], MainWindow* const)'。这部分也来自here
  • 尝试在调试模式下运行并查找发生访问冲突的位置。我认为您在程序中的其他地方有女仆错误。
  • gdb 在start 之后直接失败。我新建了一个项目,只是将上面的代码复制到主窗口的构造函数中,在main(..) {之后直接qDebug() &lt;&lt; "main";:没有变化也没有输出。
  • 您没有提供足够的信息来解决您的问题。请提供此行之前的行。您使用的是哪个 IDE?

标签: c++ qt segmentation-fault qwt


【解决方案1】:

这是 Qt Creator 的问题(或 Qwt 与 Qt 5 不兼容),它将 qmake 识别为 Qt 4 的 qmake,但它适用于 Qt 5。修复 Options -> Build&Run -> Qt Versions 中的版本并使用 Qt 4 为项目修复了段错误。

【讨论】:

    猜你喜欢
    • 2017-01-22
    • 1970-01-01
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    • 2014-10-17
    相关资源
    最近更新 更多