QWidget: Must construct a QApplication before a QPaintDevice怎么破?
月半不知愁 2017-09-27 05:05:22 使用Qwt的plot和plotcurve画出一条曲线,代码非常简单,属性曲线的用法,现在是报错:longj::InitDll CheckPidProc g_modulename plot.exe bAppOffice 0 return g_pidProcType 0QWidget: Must construct a QApplication before a QPaintDevice
inner:module name : ATTACH_PrintScreen is called!!!empty inner name and ver.Dynamic-----------------screen need SpecialCtrl mon 1
直接贴代码吧,求高手指导
//main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <QWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
--------------------------------------------
//mainwindow.cpp
#include "mainwindow.h"
#include <QWT/qwt_plot_curve.h>
#include <QWT/qwt_plot.h>
#include <QPen>
#include <math.h>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
//QWidget *widget =new QWidget;
//this->setCentralWidget(widget);
qwtplot = new QwtPlot(this);
qwtplot->setAxisTitle(QwtPlot::xBottom, "x –>");
qwtplot->setAxisScale(QwtPlot::xBottom,0.0,10.0);//横坐标从0到10, xBottom表示横坐标的方向从下往上
qwtplot->setAxisTitle(QwtPlot::yLeft,"y ->");
qwtplot->setAxisScale(QwtPlot::yLeft,-1.0,1.0);//纵坐标-1到1,yLeft表示纵坐标的方向从左到右
//curve->attach(qwtplot);
for (double x = 0; x < 2.0 * M_PI; x+=(M_PI / 10.0))
{
xs.append(x);
ys.append(qSin(x));
}
curve.setSamples(xs,ys);
curve.attach(this->qwtplot);
}
MainWindow::~MainWindow()
{
}
-------------------------------------------
//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWidget>
#include <QVector>
#include <QWT/qwt_plot_curve.h>
#include <QWT/qwt_plot.h>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QVector<double> xs;
QVector<double> ys;
QwtPlotCurve curve;
QwtPlot *qwtplot;
};
#endif // MAINWINDOW_H