[Solved] Adding a qwtPlot to a layout
Hi!
What i'm trying to do should be pretty easy. But somehow it doesn't work.
All i'm trying to do is to add a qwtPlot to an qt application, without launching the plot in its own application.
Every time i try, i end up with 2 application windows (one for the application and one for the plot) or with no application (because it crashes).
I tired this for quiet some time without any progress, so maybe you can help me out.
If i run this somewhere in my code i end up with 2 application windows. (not what i want)
Code:
plot->setTitle( "Plot Demo" );
plot->setCanvasBackground( Qt::white );
plot
->setAxisScale
( QwtPlot::yLeft,
0.0,
10.0 );
[...]
plot->show();
What i want is to add a plot to a specified layout inside my application.
every time i try to add a qwtPlot as a widget, my application crashes.
Code:
[...]
ui->horizontalLayout->addWidget(plot);
Is this even Possible? i cant even find anything about this.
Re: Adding a qwtPlot to a layout
Everything fine with your code snippet - putting QwtPlot inside a layout is probably what almost all applications do.
The bug is somewehere else in your code ( unrelated to Qwt ) - the debugger is your friend.
Uwe
Re: Adding a qwtPlot to a layout
I will take a guess, clean build the application (just your application not Qwt).
Re: Adding a qwtPlot to a layout
Thanks for the quick replys.
I thought it must be something else, because qwt would be some kind of useless.
here is the whole code of a new app. which should work (but doesn't)
Code:
int main(int argc, char *argv[])
{
w.show();
return a.exec();
}
Code:
{
plot->setTitle( "Plot Demo" );
plot->setCanvasBackground( Qt::white );
plot
->setAxisScale
( QwtPlot::yLeft,
0.0,
10.0 );
ui->hlayout->addWidget(plot); // the app crashes here.
[...]
plot->show();
ui->setupUi(this);
}
Could this mean that my qwt is not compiled right? or do i something wrong with linking?
I use Qt 5.2.1 with MSVC addin 5.2.1 with qwt 6.1.2.
I can run plots and they work as expected.
Re: Adding a qwtPlot to a layout
Call ui->setupUI(this) before using anything in ui, better call it as first statement in constructor.
Re: Adding a qwtPlot to a layout
...
that was it -.-
Thanks. hard to believe that i didn't tryed that.