PDA

View Full Version : QwtPlot on ui form



qt_gotcha
4th June 2010, 06:45
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)
: 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();
}

qt_gotcha
4th June 2010, 08:10
sorry didn't see the Qwt forum, asked it there

Astronomy
30th June 2010, 14:12
hmm..

i dont see the problem rigth now, maybe you debug it with F5 and post the line of error?
greetz A.