Results 1 to 8 of 8

Thread: Qwt Problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question Qwt Problem

    I'm having a problem with my app crashing. I have a QTableWidget that has 2 columns that I am populating with a drag and drop event. If I plot everything in the table I have no problem. If I select a few rows and only try to plot them, I crash. Here is my slot that is connected to a "Plot" button. Can anyone tell what I am doing wrong?

    Qt Code:
    1. void cPlot2d::setup2dPlot()
    2. {
    3. QAbstractItemModel * model = this->mTableWidget->model();
    4. QItemSelectionModel * selectionModel = this->mTableWidget->selectionModel();
    5. QModelIndex index = model->index(0,0);
    6.  
    7. int totalRowCount = model->rowCount();
    8. bool select(false);
    9.  
    10. //If user selects any items this model contains it
    11. QItemSelection selection = selectionModel->selection();
    12. QModelIndexList list = selection.indexes();
    13.  
    14. //Number of items selected
    15. int selectCount = list.count();
    16. int numRowsSelected(0);
    17. for(int i=0;i<selectCount;++i)
    18. {
    19. if(list[i].column()==0)
    20. ++numRowsSelected;
    21. }
    22.  
    23. QwtArray<double> x;
    24. QwtArray<double> y;
    25. QwtArray<double> xSelect;
    26. QwtArray<double> ySelect;
    27.  
    28. if(totalRowCount > 0)
    29. {
    30. //Has any items been selected
    31. if(selectCount>0)
    32. {
    33. select = true;
    34. for(int i=0; i<selectCount; ++i)
    35. {
    36. //For MVC, get the data out of the model
    37. //Data is stored contiguously in list, so got to figure out what column data is in
    38. //x=0 y=1
    39. if(list.at(i).column() == 0)
    40. {
    41. xSelect.push_back(list.at(i).data().toDouble());
    42. }
    43. else
    44. {
    45. ySelect.push_back(list.at(i).data().toDouble());
    46. }
    47. }
    48. }
    49. //No items selected, load up entire table
    50. else
    51. {
    52.  
    53. for(int i=0; i<totalRowCount; ++i)
    54. {
    55. //For MVC, get the data out of the model
    56. x.push_back(model->data(index.sibling(i,0)).toDouble());
    57. y.push_back(model->data(index.sibling(i,1)).toDouble());
    58. }
    59. }
    60. // Set up Qwt Plot stuff
    61. QwtPlot * plot(new QwtPlot(this));
    62. plot->setTitle("2D Plot");
    63. // axis titles
    64. plot->setAxisTitle(QwtPlot::xBottom, "x");
    65. plot->setAxisTitle(QwtPlot::yLeft, "y");
    66.  
    67. // curve
    68. QwtPlotCurve * curve(new QwtPlotCurve("Curve 1"));
    69. curve->attach(plot);
    70. // data
    71. if(select)
    72. {
    73. //User selected data to plot
    74. curve->setData(xSelect, ySelect);
    75. }
    76. else
    77. {
    78. //Plot entire table
    79. curve->setData(x, y);
    80. }
    81. // pen
    82. curve->setPen(QPen(QColor(0, 0, 200)));
    83. // style
    84. curve->setStyle(QwtPlotCurve::Lines);
    85.  
    86. plot->replot();
    87.  
    88. cMainWindow::getInstance()->mWorkspace->addWindow(plot)->show();
    89.  
    90. }
    91. else
    92. {
    93. cout << " NO DATA TO PLOT!! " << endl;
    94. return;
    95. }
    96.  
    97. } // cPlot2d::setup2dPlot
    To copy to clipboard, switch view to plain text mode 
    Last edited by allensr; 21st November 2006 at 21:04.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.