Results 1 to 6 of 6

Thread: Please Help-->Not able to draw curves in QwtPlot Widget !

  1. #1
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Please Help-->Not able to draw curves in QwtPlot Widget !

    Hello! Friends,
    I am using Qwt plugin with Qt4.3.4 in WinXP to design a GUI. Now i have created a Widget in Qt, added QwtPlot Widget to it named sampleqwtPlot and coded the following files: -

    ########sampleplot.h##########
    Qt Code:
    1. #ifndef SAMPLEPLOT_H
    2. #define SAMPLEPLOT_H
    3.  
    4. #include<QtGui>
    5. #include <qwt_plot.h>
    6. #include <qwt_plot_curve.h>
    7.  
    8. #include "ui_sampleplot.h"
    9.  
    10. const int PLOT_SIZE = 101;
    11.  
    12. class samplePlot : public QWidget, private Ui::sampleForm
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. samplePlot(QWidget* parent = 0);
    18.  
    19. private:
    20. // Arrays holding the values.
    21. double xval[PLOT_SIZE];
    22. double yval[PLOT_SIZE];
    23. // Insert new curve
    24. QwtPlotCurve *curve;
    25. };
    26.  
    27. #endif
    To copy to clipboard, switch view to plain text mode 

    ########sampleplot.cpp########
    Qt Code:
    1. #include <QtGui>
    2. #include "sampleplot.h"
    3.  
    4. samplePlot::samplePlot( QWidget *parent )
    5. : QWidget( parent )
    6. {
    7. setupUi(this); // this sets up GUI
    8. connect( startPushButton, SIGNAL( clicked() ), this, SLOT( draw_curve() ) );
    9.  
    10. // Axis
    11. sampleqwtPlot->setAxisTitle(QwtPlot::xBottom, "Time/seconds");
    12. sampleqwtPlot->setAxisScale(QwtPlot::xBottom, 0, 100);
    13.  
    14. sampleqwtPlot->setAxisTitle(QwtPlot::yLeft, "Values");
    15. sampleqwtPlot->setAxisScale(QwtPlot::yLeft, 0, 50);
    16.  
    17. // Set curve styles
    18. curve->setPen(QPen(Qt::red));
    19.  
    20. //
    21. // Calculate values
    22. //
    23. for(int i=0;i<PLOT_SIZE;i++)
    24. {
    25. xval[i] = i;
    26. yval[i] = 0.5*i;
    27. }
    28. //
    29. //Assign values to the curve.
    30. //
    31. curve->setData( xval, yval, PLOT_SIZE );
    32. //
    33. //Attach the curve.
    34. //
    35. curve->attach( sampleqwtPlot );
    36. //
    37. // finally, refresh the plot
    38. //
    39. sampleqwtPlot->replot();
    40. }
    To copy to clipboard, switch view to plain text mode 

    I am able to get the sampleplot.exe file but its not working, like whenever i try to run it, displays error "encountered a problem".

    I think i am making a small silly mistake somewhere.

    Can anyone please help me out.--> I will be obliged

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Please Help-->Not able to draw curves in QwtPlot Widget !

    Could you post the exact error message? Maybe your OS can't find Qwt DLLs?

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Please Help-->Not able to draw curves in QwtPlot Widget !

    You have
    Qt Code:
    1. QwtPlotCurve *curve;
    To copy to clipboard, switch view to plain text mode 
    and I see it being used but never allocated. In other words, it's a dangling pointer.
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    Krish (13th March 2008)

  5. #4
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Please Help-->Not able to draw curves in QwtPlot Widget !

    Hello! Jacek & Jpn,
    Thanks for taking out time and helping me out. I had made a same mistake as said by Jpn. But now i did few things and its working!!

    But now i added a pushbutton to clear the drawn plot but its not clearing the curves n all, i dont know why? Even though i have properly connected it to sampleqwtPlot->clear() slot, its not working. I mean replot() slot is working but clear() slot is not!!!!

    Also i tried to connect the same button to Form->close() slot, and its working but samplePlot->clear() slot isn't????

    Thanks again.

    Best Regards.
    Last edited by Krish; 13th March 2008 at 08:41.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Please Help-->Not able to draw curves in QwtPlot Widget !

    Quote Originally Posted by Krish View Post
    Also i tried to connect the same button to Form->close() slot, and its working but samplePlot->clear() slot isn't????
    How did you declare samplePlot::clear() and how do you establish the connection?

  7. #6
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Please Help-->Not able to draw curves in QwtPlot Widget !

    Hello! Jacek Sir,
    Thanks for taking out time and replying but i have somehow solved the problem.

    Thanks again

    Best Regards

Similar Threads

  1. QwtPlot - promote to custom widget
    By MrGarbage in forum Qwt
    Replies: 7
    Last Post: 10th February 2011, 10:12

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.