Results 1 to 5 of 5

Thread: Newbie: putting a QwtPlot on a ui form

  1. #1
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Newbie: putting a QwtPlot on a ui form

    A simple application with a ui form, generated in eclipse. I am working with Qt for about 6 months now, but still learning. The form is opened and shown after 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 from the constructor of class 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.

    Qt Code:
    1. trygraph::trygraph(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. ui.setupUi(this);
    5.  
    6. double x[100], y1[100];
    7. QwtPlot *myPlot = new QwtPlot(QwtText("a Curves"), ui.widget);
    8.  
    9. for (int i = 0; i < 100; i++)
    10. {
    11. x[i] = i;
    12. y1[i] = 10-0.1*i*i;
    13. }
    14.  
    15. // add curves
    16. QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
    17.  
    18. // copy the data into the curves
    19. curve1->setData(x,y1,100);
    20.  
    21. curve1->attach(myPlot);
    22.  
    23. myPlot->replot();
    24. }
    25.  
    26. [the main function:]
    27.  
    28. int main(int argc, char *argv[])
    29. {
    30. QApplication a(argc, argv);
    31. trygraph w;
    32. w.show();
    33. return a.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2009
    Posts
    28
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Newbie: putting a QwtPlot on a ui form

    Hello,

    Be sure you're using the debug dll when you're in debug mode and the release one when you're in release mode. Review the compilation of the libraries.

    Regards

  3. #3
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Newbie: putting a QwtPlot on a ui form

    thanks, you mean my code should work?
    I have compiled in debug mode but I'll check

  4. #4
    Join Date
    Oct 2009
    Posts
    28
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Newbie: putting a QwtPlot on a ui form

    Yes, I think your code will work.
    Try to give a look at your compilation of the dll.

    Regards.

  5. #5
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Newbie: putting a QwtPlot on a ui form

    that was it!
    thanks a lot ;-)

Similar Threads

  1. Replies: 7
    Last Post: 8th October 2010, 13:07
  2. QwtPlot on ui form
    By qt_gotcha in forum Newbie
    Replies: 2
    Last Post: 30th June 2010, 14:12
  3. Replies: 6
    Last Post: 14th May 2009, 12:02
  4. Putting Tab Space
    By zgulser in forum Qt Tools
    Replies: 1
    Last Post: 16th January 2009, 15:36
  5. putting widgets
    By mickey in forum Qt Programming
    Replies: 1
    Last Post: 20th June 2006, 08:49

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
  •  
Qt is a trademark of The Qt Company.