Results 1 to 3 of 3

Thread: Issues while generating a view with QStandardModel,QStandardItem & QTreeview

  1. #1
    Join Date
    May 2010
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Issues while generating a view with QStandardModel,QStandardItem & QTreeview

    Qt Code:
    1. /*creating an QStandardItem & appending 2 new QStandardItems such that
    2.  
    3. nameItem
    4. |
    5. |-------cyName //having a text to set at runtime
    6. |-------cll //having a text to set at runtime
    7.  
    8. */
    9. QStandardItem* MainWindow::createNewCRListItem(const QStringList &sList)
    10. {
    11. nameItem=new QStandardItem();
    12. nameItem->setFlags(Qt::NoItemFlags);
    13. nameItem->setColumnCount(1);
    14.  
    15. QIcon lIcon(":/images/contact.png");
    16. nameItem->setIcon(lIcon);
    17. nameItem->data(Qt::DisplayRole);
    18. QStandardItem cyName;
    19.  
    20.  
    21. if(sList.size()!=3)
    22. Q_ASSERT("error in parsing string list ");
    23.  
    24. for (int j=0;j<sList.size();j++)
    25. {
    26. if (j==0)
    27. {
    28. const QString str= sList.at(j);
    29. nameItem->setText(str);
    30. qDebug()<< str;
    31. }
    32. if(j==1)
    33. {
    34. const QString str= sList.at(j);
    35. cyName.setText(str);
    36. qDebug()<< str;
    37. }
    38. if(j==2)
    39. {
    40. const QString str= sList.at(j);
    41. cll.setText(str);
    42. qDebug()<< str;
    43. }
    44. }
    45. nameItem->appendRow(&cyName);
    46. nameItem->appendRow(&cll);
    47. //emit nameItem->emitDataChanged();
    48. return nameItem;
    49. }
    50.  
    51. /* get a QList<QStringList> from parsing object
    52.   create a QStandardItem (above func)
    53.   set that QStandaradItem to a QStandardModel
    54.   later .. set the QStandardItem to QTreeView as shown below
    55. */
    56. void MainWindow::getlistFromParse( parseClass &pObj)
    57. {
    58.  
    59. list = pObj.getList(); //return the reference of list
    60. int modelSize= list.size();
    61. int itemRow;
    62. qDebug()<< "Row cont "<< modelSize;
    63. crItemModel.setRowCount(modelSize);
    64. qDebug()<<"check row: "<<crItemModel.rowCount();
    65. crItemModel.setColumnCount(1);
    66. qDebug()<<"check col : "<<crItemModel.columnCount();
    67.  
    68. QList<QStringList>::const_iterator i;
    69. for(i=list.constBegin(),itemRow=0;i!=list.constEnd();itemRow++,i++)
    70. {
    71. const QStringList& subList=*i;
    72. QStandardItem *item= MainWindow::createNewCRListItem(subList);
    73.  
    74. crItemModel.appendRow(item); //application closing unexpectedly
    75. //crItemModel.setItem(itemRow,1,item);
    76. }
    77. }
    To copy to clipboard, switch view to plain text mode 

    while the stack trace shows segmantation fault in crItemModel.appendRow(item);
    crItemModel is of type QStandardModel
    and
    Qt Code:
    1. tree = new QTreeView(parent);
    2. tree->setModel(&crItemModel);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Issues while generating a view with QStandardModel,QStandardItem & QTreeview

    Think about scope:
    Qt Code:
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2010
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Issues while generating a view with QStandardModel,QStandardItem & QTreeview

    I am so stupid on this.
    Thanks a lot.

Similar Threads

  1. Mirror nodes in QTreeView - reuse of QStandardItem fail
    By muenalan in forum Qt Programming
    Replies: 0
    Last Post: 13th January 2011, 13:13
  2. Replies: 1
    Last Post: 16th April 2010, 21:59
  3. Some QTreeView Issues
    By kazibi in forum Newbie
    Replies: 0
    Last Post: 27th December 2009, 14:51
  4. Question on checkable QStandardItem in QTreeView
    By ttvo in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2009, 00:30
  5. QTreeView and QStandardModel : add children
    By Valheru in forum Newbie
    Replies: 7
    Last Post: 19th September 2006, 17: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.