Results 1 to 10 of 10

Thread: is it a C++ error or Qt/Qwt related?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    31
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanked 5 Times in 4 Posts

    Default Re: is it a C++ error or Qt/Qwt related?

    After

    Qt Code:
    1. redCurve.setRawData(xval,redCurveData,size);
    2. greenCurve.setRawData(xval,greenCurveData,size);
    To copy to clipboard, switch view to plain text mode 

    you don't need the previous samples anymore (it seems) so you can call freeData() after that, of course delaying assign of new pointers until after the free of old data:

    Qt Code:
    1. void Dialog::getData()
    2. {
    3. int size = 1+rand()%10 + 10;
    4.  
    5. double* redCurveDataPtr = new double[size];
    6. double* greenCurveData = new double[size];
    7. double* xval = new double[size];
    8.  
    9. for(int i = 0; i < size; i++)
    10. {
    11. redCurveData[i] = 0+rand()%10;
    12. greenCurveData[i] = 0+rand()%10;
    13. xval[i] = i + 1;
    14. }
    15.  
    16. redCurve.setRawData(xval,redCurveData,size);
    17. greenCurve.setRawData(xval,greenCurveData,size);
    18.  
    19. // old data is no more needed now
    20. freeData();
    21.  
    22. // now we can add newly created samples pointers
    23. samplesPtr << redCurveDataPtr << greenCurveData << xval;
    24.  
    25. plot->setAxisScale(QwtPlot::xBottom, 1, size);
    26. plot->setAxisScale(QwtPlot::yLeft, 0, 10);
    27.  
    28. drawCurves();
    29. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Posts
    31
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanked 5 Times in 4 Posts

    Default Re: is it a C++ error or Qt/Qwt related?

    A couple of bugs

    Because pointer vector is reused freeData() should be:

    Qt Code:
    1. void Dialog::freeData()
    2. {
    3. for(int i = 0; i < samplesPtr.size(); i++)
    4. delete[] samplesPtr.at(i);
    5.  
    6. samplesPtr.clear();
    7. }
    To copy to clipboard, switch view to plain text mode 

    And also remember to add a freeData() call in the d'tor to be sure the last samples data set is properly released when closing the dialog.

  3. #3
    Join Date
    Aug 2007
    Posts
    244
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    42
    Thanked 8 Times in 8 Posts

    Default Re: is it a C++ error or Qt/Qwt related?

    Inserting freeData() where you say gives me strange graphs. Removing it works again right.

    Regards
    Giuseppe CalÃ

Similar Threads

  1. Related to header file
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2007, 13:03
  2. Question related to Q3DataTable
    By mitesh_modi in forum Qt Programming
    Replies: 0
    Last Post: 29th November 2006, 08:49
  3. Replies: 4
    Last Post: 3rd April 2006, 08:22
  4. Qt related questions and thoughts about getting job
    By AlexKiriukha in forum General Discussion
    Replies: 4
    Last Post: 26th January 2006, 12:25

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.