QWT示例该程序已经意外完成
qwt example The program has unexpectedly finished
我的代码没有什么问题,当我执行程序(qwt的示例)时,我会收到此错误(程序意外完成),为什么我会收到此错误消息,以及如何如何修复它?
谢谢
这是我的代码:
main.cpp
#include "mainwindow.h"
#include <QtGui>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
w.resize(400, 450);
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
MainWindow:: MainWindow(QWidget *parent) :
QMainWindow(parent)
{
CreateGui();
}
MainWindow::~MainWindow()
{
}
void MainWindow::CreateGui()
{
QwtPlot *myPlot = new QwtPlot(centralWidget());
QwtPlotCurve *courbe = new QwtPlotCurve("Courbe 1");
QLineEdit *test = new QLineEdit;
QVector<double> x(5);
QVector<double> y(5);
// On entre des valeurs
for(int i=0;i<5;i++)
{
x.append((double)i);
y.append((double)(5-i));
}
courbe->setSamples(x.data(),y.data(),x.size());
myPlot->replot();
courbe->attach(myPlot);
QGridLayout *layout = new QGridLayout;
layout->addWidget(myPlot, 0, 1);
layout->addWidget(test,1,0);
centralWidget()->setLayout(layout);
}
and mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QObject>
#include <QMainWindow>
#include<QLineEdit>
#include<QGridLayout>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
class MainWindow: public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent=0);
~MainWindow();
private:
private slots:
void CreateGui();
};
#endif // MAINWINDOW_H
在mainwindow.h
中creategui不是一个插槽,也许可以是,bot暂时还没有与任何连接(信号,插槽)
相关<罢工>mainwindow(qwidget *parent = 0);没有那个明确的话,我不知道您想明确说什么。:S (明确是可以的,多亏了@frank)罢工>
在mainwindow.cpp
中而不是centralwidget()您将添加此关键字,并尝试在MainWindow窗口小部件上渲染,从Qwidget继承。
类似的东西:
在mainwindow.cpp上:
void MainWindow::CreateGui()
{
QwtPlot *myPlot = new QwtPlot(this);
QwtPlotCurve *courbe = new QwtPlotCurve("Courbe 1");
QLineEdit *test = new QLineEdit;
QVector<double> x(5);
QVector<double> y(5);
// On entre des valeurs
for(int i=0;i<5;i++)
{
x.append((double)i);
y.append((double)(5-i));
}
courbe->setSamples(x.data(),y.data(),x.size());
myPlot->replot();
courbe->attach(myPlot);
QGridLayout *layout = new QGridLayout;
layout->addWidget(myPlot, 0, 1);
layout->addWidget(test,1,0);
this->setLayout(layout);
}
或将CentralWidget设置为某物,因为没有setCentralwidget(qwidget*)在任何地方都调用,kerfrank名称。
DOC说,如果CentralWidget()在未设置之前将返回零。并向您显示指向SetCentralWidget(Qwidget*)方法的链接。
我添加了@frank在构造函数上说的线。
this->setCentralWidget(new QWidget);
之后也有效。我以前从未使用过这些方法,但显然最后是使用它的首选方法。
问候!
相关文章:
- 更改.cpp程序的输入文件中数据的位置会意外更改输出
- 多线程程序中出现意外的内存泄漏
- C++ 程序意外退出
- 在gcc中意外调用了Const重载.编译器错误或兼容性修复程序
- 如果我删除指针,我的C++程序会意外删除系统文件吗?
- Qt 应用程序具有意外的 QDir::currentPath
- 排序程序的意外错误代码
- 以下程序的意外输出
- QT应用程序意外的语言事件
- 简单程序中的意外推力错误
- 程序意外终止C
- 设置终止和意外处理程序
- 双精度数字程序意外值
- QWT示例该程序已经意外完成
- 使用双精度的程序的意外行为
- 查找素数的程序意外停止
- 程序意外地完成了-QT创建者
- cpp 程序中的意外输出
- 当我在递归函数中调用 return 时,我的程序意外完成
- Arduino上的意外程序停止