PDA

View Full Version : QWidget: Must construct a QApplication before a QPaintDevice



agupta108
21st July 2011, 22:20
Hello all,

I am using qwt 6.0.0 with Qt 4.6.2 and I am getting the error "QWidget: Must construct a QApplication before a QPaintDevice." I searched the forum and see that other users have had similar error and the replies suggested are 1. debug/release compilation modes 2. static/dynamic library. I have tried these options suggested in the forum but I am not able to get rid of this error. In my case either in debug or release mode, I get the same error. My code is very simple - plotting a sine plot using qwt:

#include <iostream>
#include <fstream>
#include <string>

#include <QApplication>
#include <QDialog>
#include <QPushButton>
#include <QString>
#include <QFileInfo>
#include <QMainWindow>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>

int main(int argc, char *argv[])
{

QApplication app(argc, argv);

QwtPlot plot(QwtText("CppQwtExample1"));
plot.setGeometry(0,0,640,400);
plot.setAxisScale(QwtPlot::xBottom, 0.0,2.0 * M_PI);
plot.setAxisScale(QwtPlot::yLeft,-1.0,1.0);

QwtPlotCurve sine101;

std::vector<double> xs;
std::vector<double> ys;
for (double x1 = 0; x1 < 2.0 * M_PI; x1+=(M_PI / 10.0))
{
xs.push_back(x1);
ys.push_back(std::sin(x1));
}
sine101.setSamples(&xs[0],&ys[0],xs.size());
sine101.attach(&plot);

plot.show();
return app.exec();
}

Any help will be appreciated.

Thanks.

Santosh Reddy
22nd July 2011, 01:13
I couldn't think of anything why it should give such error, even after creating QApplication. I tried creating the same project on my machine with Qt 4.7.0, Qwt 6.0.0, it just works. But I had to do one modification, I had to add #include <cmath> to the source posted my you. Further here is my project file, and screen shot for reference.


include(C:/qwt-6.0.0/examples/examples.pri)

QT += core gui

TARGET = untitled
TEMPLATE = app
SOURCES += main.cpp

rajeevsahu
25th July 2011, 08:08
Hey,

I am trying to build qwt app in Qt usinf Nokia Qt SDK, But it gives the following error:


:: error: No rule to make target `\NokiaQtSDK\Symbian\SDK\epoc32\release\armv5\LIB\ qwt.dso', needed by `\NokiaQtSDK\Symbian\SDK\epoc32\release\gcce\udeb\ HRMGraphApp.exe'. Stop.

Any ideas hiw to resolve this problem.

Thanks in advance...