【发布时间】: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() << "main";:没有变化也没有输出。 -
您没有提供足够的信息来解决您的问题。请提供此行之前的行。您使用的是哪个 IDE?
标签: c++ qt segmentation-fault qwt