Results 1 to 6 of 6

Thread: [Solved] Adding a qwtPlot to a layout

  1. #1
    Join Date
    Mar 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default [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)
    Qt Code:
    1. QwtPlot* plot = new QwtPlot();
    2. plot->setTitle( "Plot Demo" );
    3. plot->setCanvasBackground( Qt::white );
    4. plot->setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    5. plot->insertLegend( new QwtLegend() );
    6. [...]
    7. plot->show();
    To copy to clipboard, switch view to plain text mode 

    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.
    Qt Code:
    1. QwtPlot* plot = new QwtPlot();
    2. [...]
    3. ui->horizontalLayout->addWidget(plot);
    To copy to clipboard, switch view to plain text mode 

    Is this even Possible? i cant even find anything about this.
    Last edited by cl90; 4th March 2015 at 12:10.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Adding a qwtPlot to a layout

    I will take a guess, clean build the application (just your application not Qwt).
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  4. #4
    Join Date
    Mar 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default 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)

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. w.show();
    5.  
    6. return a.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. qwtplot::qwtplot(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::qwtplot)
    4. {
    5.  
    6. QwtPlot* plot = new QwtPlot();
    7.  
    8. plot->setTitle( "Plot Demo" );
    9. plot->setCanvasBackground( Qt::white );
    10. plot->setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    11. plot->insertLegend( new QwtLegend() );
    12.  
    13. ui->hlayout->addWidget(plot); // the app crashes here.
    14.  
    15. [...]
    16.  
    17. plot->show();
    18.  
    19.  
    20.  
    21. ui->setupUi(this);
    22. }
    To copy to clipboard, switch view to plain text mode 

    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.

  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Adding a qwtPlot to a layout

    Call ui->setupUI(this) before using anything in ui, better call it as first statement in constructor.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  6. #6
    Join Date
    Mar 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adding a qwtPlot to a layout

    ...
    that was it -.-

    Thanks. hard to believe that i didn't tryed that.

Similar Threads

  1. Replies: 1
    Last Post: 23rd January 2014, 01:27
  2. Replies: 0
    Last Post: 7th July 2012, 11:32
  3. Adding line in layout.
    By Niamita in forum Qt Programming
    Replies: 5
    Last Post: 17th October 2011, 14:56
  4. Replies: 0
    Last Post: 12th December 2010, 05:09
  5. A question about adding to layout
    By Cruz in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2009, 12:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.