Results 1 to 2 of 2

Thread: Bug with QwtPlotPicker

  1. #1
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Bug with QwtPlotPicker

    Hi,

    I found a bug in QwtPlotPicker (either in the code or in the documentation, depending on how it is supposed to work):

    When I create a plot picker I pass the canvas of a plot as its parent (according to documentation). However, when I delete the plot and hence its canvas, the plot picker is not deleted and does not stop working which leads to an access violation when the picker internally accesses the plot in the method QwtPlotPicker::invTransform.

    If the plot picker is deleted in the plot's destructor manually, all works fine. Here is an example:

    Qt Code:
    1. class MyPlot : public QwtPlot
    2. {
    3. public:
    4. MyPlot(QWidget* parent) : QwtPlot(parent)
    5. {
    6. m_picker = new QwtPlotPicker(canvas());
    7. m_picker->setStateMachine(new QwtPickerTrackerMachine());
    8. m_picker->setTrackerMode(QwtPicker::AlwaysOn);
    9. }
    10.  
    11. ~MyPlot()
    12. {
    13. //delete m_picker;
    14. }
    15.  
    16. private:
    17. QwtPlotPicker* m_picker;
    18. };
    19.  
    20. class TempPlot : public QDialog
    21. {
    22. Q_OBJECT
    23.  
    24. public:
    25. TempPlot(QWidget *parent = Q_NULLPTR)
    26. : QDialog(parent)
    27. {
    28. ui.setupUi(this);
    29. m_plot = new MyPlot(this);
    30. setLayout(new QVBoxLayout());
    31. layout()->addWidget(m_plot);
    32. }
    33.  
    34. protected:
    35. void keyPressEvent(QKeyEvent* event) override
    36. {
    37. if (event->key() == Qt::Key_D)
    38. {
    39. if (m_plot != nullptr)
    40. {
    41. delete m_plot;
    42. m_plot = nullptr;
    43. }
    44. }
    45. QDialog::keyPressEvent(event);
    46. }
    47.  
    48. private:
    49. Ui::TempPlotClass ui;
    50. MyPlot* m_plot;
    51. };
    To copy to clipboard, switch view to plain text mode 

    Press the "d" key while moving the mouse over the plot. If the line in ~MyPlot is commented out, the application will crash.

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

    Default Re: Bug with QwtPlotPicker

    Yes, you are running into a situation, where the plot is already gone, but the canvas is still alive.
    I added a check in QwtPlotPicker before accessing the parent of the canvas.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    Crowley (6th September 2017)

Similar Threads

  1. QwtPlotPicker on stockchart
    By wooosh in forum Qwt
    Replies: 2
    Last Post: 17th February 2014, 09:04
  2. QwtPlotPicker with QwtPlotDirectPainter
    By friendbaby in forum Qwt
    Replies: 1
    Last Post: 12th December 2012, 14:43
  3. QwtPlotPicker
    By carhun in forum Qwt
    Replies: 1
    Last Post: 20th August 2012, 13:12
  4. QwtPlotMarker QwtPlotPicker
    By bss in forum Qwt
    Replies: 1
    Last Post: 15th June 2011, 12:55
  5. QwtPlotPicker questions
    By ttvo in forum Qwt
    Replies: 7
    Last Post: 28th February 2009, 09:44

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.