A simple application with a ui form, generated in eclipse. The form is opened and shown upon compiling. The form has a QWidget called widget.
If I add the basic code to draw a qwtplot on the form it crashes. The mesage is: "QWidget: Must construct a QApplication before a QPaintDevice". I thought qapplication was constructed first in the main code, so I don't get it! I have tried linking the qwtplot to "this" and "parent" but the same result. I have also tried to move the plot form the constructor of trygraph to a button press function but with the same result
In all examples of QwtPLot I can find the plot is made in the main function before "return a.exec();"
Appreciate any help or pointers to examples.
trygraph
::trygraph(QWidget *parent
){
ui.setupUi(this);
double x[100], y1[100];
for (int i = 0; i < 100; i++)
{
x[i] = i;
y1[i] = 10-0.1*i*i;
}
// add curves
// copy the data into the curves
curve1->setData(x,y1,100);
curve1->attach(myPlot);
myPlot->replot();
}
[the main function:]
int main(int argc, char *argv[])
{
trygraph w;
w.show();
return a.exec();
}
trygraph::trygraph(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
double x[100], y1[100];
QwtPlot *myPlot = new QwtPlot(QwtText("a Curves"), ui.widget);
for (int i = 0; i < 100; i++)
{
x[i] = i;
y1[i] = 10-0.1*i*i;
}
// add curves
QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
// copy the data into the curves
curve1->setData(x,y1,100);
curve1->attach(myPlot);
myPlot->replot();
}
[the main function:]
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
trygraph w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks