Results 1 to 8 of 8

Thread: Qwt Problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: Qwt Problem

    Sounds like you are manipulating the widget outside the main GUI thread, is this true?

    Thread Support in Qt:
    Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread.
    Last edited by jacek; 1st December 2006 at 20:27. Reason: changed [code] to [quote]
    J-P Nurmi

  2. #2
    Join Date
    May 2006
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qwt Problem

    Well, Im not sure. I am populating the TableWidget with data from a TreeWidget via a drag and drop. Is that manipulating the widget outside the main GUI thread? Again, I only have problems if I select items in the TableWidget.

  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: Qwt Problem

    Ok good, then the problem is not with threads. I was suspecting you tried to do the plotting in a "worker" thread..

    To be honest, I can't find any pitfall in your code, but does it make any difference if you revise the function to look something like this:
    Qt Code:
    1. void cPlot2d::setup2dPlot()
    2. {
    3. int totalRowCount = this->mTableWidget->rowCount();
    4. QList<QTableWidgetItem *> selected = this->mTableWidget->selectedItems();
    5.  
    6. QwtArray<double> x;
    7. QwtArray<double> y;
    8.  
    9. if(totalRowCount > 0)
    10. {
    11. //Have any items been selected
    12. if(selected.count() > 0)
    13. {
    14. foreach(item, selected)
    15. {
    16. bool ok = false;
    17. double value = item->text().toDouble(&ok);
    18. //For MVC, get the data out of the model
    19. //Data is stored contiguously in list, so got to figure out what column data is in
    20. //x=0 y=1
    21. if(item->column() == 0)
    22. {
    23. if(ok && !item->text().isEmpty())
    24. x.push_back(value);
    25. }
    26. else
    27. {
    28. if(ok && !item->text().isEmpty())
    29. y.push_back(value);
    30. }
    31. }
    32. }
    33. //No items selected, load up entire table
    34. else
    35. {
    36. for(int i=0; i<totalRowCount; ++i)
    37. {
    38. //For MVC, get the data out of the model
    39. QTableWidgetItem* item0 = mTableWidget->item(i,0);
    40. QTableWidgetItem* item1 = mTableWidget->item(i,1);
    41. x.push_back(item0->text().toDouble());
    42. y.push_back(item1->text().toDouble());
    43. }
    44. }
    45. // Set up Qwt Plot stuff
    46. QwtPlot * plot(new QwtPlot(this));
    47. plot->setTitle("2D Plot");
    48. // axis titles
    49. plot->setAxisTitle(QwtPlot::xBottom, "x");
    50. plot->setAxisTitle(QwtPlot::yLeft, "y");
    51.  
    52. // curve
    53. QwtPlotCurve * curve(new QwtPlotCurve("Curve 1"));
    54. curve->attach(plot);
    55. // data
    56. curve->setData(x, y);
    57. // pen
    58. curve->setPen(QPen(QColor(0, 0, 200)));
    59. // style
    60. curve->setStyle(QwtPlotCurve::Lines);
    61.  
    62. plot->replot();
    63.  
    64. cMainWindow::getInstance()->mWorkspace->addWindow(plot)->show();
    65.  
    66. }
    67. else
    68. {
    69. cout << " NO DATA TO PLOT!! " << endl;
    70. return;
    71. }
    72. } // cPlot2d::setup2dPlot
    To copy to clipboard, switch view to plain text mode 

    All I did was cleaning up the unnecessary usage of model indexes which you actually shouldn't need while working with convenience views. If it still crashes, could you please post the backtrace from the debugger? And could you tell the exact version of Qt you are using as well?
    J-P Nurmi

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  3. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. use interesting QWT Library with QT3.X
    By raphaelf in forum Qwt
    Replies: 2
    Last Post: 23rd January 2006, 11:24

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.