Results 1 to 4 of 4

Thread: QTreeWidget Crashing while setText,setFont,setIcon

  1. #1
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QTreeWidget Crashing while setText,setFont,setIcon

    Hi
    My application is creating Tree of thousand or lack of folder ad files..
    I m using setText,setFont,setIcon for QTreeWidget for every folder..
    But in the mid of application it crashes while creating tree...

    I m using code like this:

    Qt Code:
    1. void* StellarPhoenixMAC::InsertFoldersInTree(void* myEntry,QString bFileName)
    2. {
    3. MyEntry = (DOSDIR*)myEntry;
    4.  
    5.  
    6. QIcon Folder(":/images/img_Folder.png");
    7. QSize size(18,18);//Set the size of the Item in treeWidget
    8. QSize folderSize(16,16);
    9. QFont lucidaFont("Lucida Grande", 12);
    10.  
    11. unsigned int nListCnt = 0;
    12. QTreeWidgetItem *treeViewItem = NULL;
    13.  
    14. iProgressCounter++;
    15.  
    16.  
    17. //Check if root already there or not
    18. //if(!bDriveTree && bProcessStarted)
    19.  
    20. if(!m_dwDirLength)
    21. {
    22. m_dwDirLength++;
    23. DOSDIR *firstDirLink=NULL;
    24. firstDirLink = (DOSDIR*)calloc(1,sizeof(DOSDIR)); //For CreateDirTreeRootItem added here
    25.  
    26. if(firstDirLink)
    27. {
    28. firstDirLink->dwFileId = ROOTREFRENCE;
    29. firstDirLink->bAttribute=0x10;
    30. firstDirLink->bCheckStatus=UNCHECK;
    31. //Root's ParentID is set to -1 so as to keep it unique
    32. firstDirLink->dwParentId=0;
    33. }
    34.  
    35. list.append(new TREEITEM((void*)firstDirLink,QString::fromAscii((const char *)m_pDriveForSavingFiles->VolumeLable,-1)));
    36. emit MacFileSysRootTree(QString::fromAscii((const char *)m_pDriveForSavingFiles->VolumeLable,-1),qFileId.setNum(ROOTREFRENCE),QString::number(0));
    37.  
    38. m_MacFileSys->MacFileSysThreadSleep();
    39.  
    40. if(list.count() > 0)
    41. {
    42. treeitem=list.first();
    43. treeitem->ListViewItem=MacFileSysRootItem;
    44. }
    45.  
    46. free(firstDirLink);
    47. }///end of if(!m_dwDirLength)
    48. m_dwDirLength++;
    49. m_dwTotalDirs++;
    50.  
    51. if(!bFileName.isEmpty())
    52. list.append(new TREEITEM((void*)MyEntry,bFileName)); //Item added to list
    53. else
    54. list.append(new TREEITEM((void*)MyEntry,QString::number(MyEntry->dwFileId))); //Item added to list
    55.  
    56. nListCnt = list.count();
    57. //if(list.count() > 0)
    58. // treeitem=list.last();
    59. if(nListCnt)
    60. treeitem = list.at(nListCnt-1);
    61.  
    62. treeViewItem = new QTreeWidgetItem;
    63.  
    64. //if(!TotalFilesAndFoldersInList.isEmpty())
    65. // m_pTotalSizeReadLabel->setText(TotalFilesAndFoldersInList);
    66.  
    67. QString ID = QString::number(MyEntry->dwFileId);
    68. QString parentId = QString::number(MyEntry->dwParentId);
    69.  
    70. if(!bFileName.isEmpty())
    71. treeViewItem->setText(0,bFileName);
    72. else
    73. {
    74. if(!ID.isEmpty())
    75. treeViewItem->setText(0,ID);
    76. else
    77. treeViewItem->setText(0,"NONAME");
    78. }
    79.  
    80. if(!ID.isEmpty())
    81. treeViewItem->setText(1,ID);
    82.  
    83. if(!parentId.isEmpty())
    84. treeViewItem->setText(2,parentId);
    85. //emit SetFolderTree((void*)treeViewItem,bFileName,QString::number(MyEntry->dwFileId),QString::number(MyEntry->dwParentId));
    86.  
    87. if(MacFileSysRootItem !=NULL && treeViewItem != NULL)
    88. MacFileSysRootItem->insertChild(0,treeViewItem);
    89.  
    90. treeViewItem->setCheckState (0, Qt::Unchecked );
    91. treeViewItem->setIcon (0, Folder );
    92.  
    93.  
    94. if(treeitem != NULL && treeViewItem != NULL)
    95. treeitem->ListViewItem= treeViewItem;
    96.  
    97. return( (void*)treeViewItem);
    98. }
    99.  
    100. void StellarPhoenixMAC::SetFolderTree (void* treeViewItem,QString bFileName, QString ID,QString parentId)
    101. {
    102. QIcon Folder(":/images/img_Folder.png");
    103. QSize size(18,18);//Set the size of the Item in treeWidget
    104. QSize folderSize(16,16);
    105. QFont lucidaFont("Lucida Grande", 12);
    106.  
    107. if(!TotalFilesAndFoldersInList.isEmpty())
    108. m_pTotalSizeReadLabel->setText(TotalFilesAndFoldersInList);
    109.  
    110. if(!bFileName.isEmpty())
    111. ((QTreeWidgetItem*)treeViewItem)->setData(0,Qt::DisplayRole,bFileName);
    112. else
    113. {
    114. if(!ID.isEmpty())
    115. ((QTreeWidgetItem*)treeViewItem)->setData(0,Qt::DisplayRole,ID);
    116. else
    117. ((QTreeWidgetItem*)treeViewItem)->setData(0,Qt::DisplayRole,"NONAME");
    118. }
    119.  
    120. if(!ID.isEmpty())
    121. ((QTreeWidgetItem*)treeViewItem)->setData(1,Qt::DisplayRole,ID);
    122.  
    123. if(!parentId.isEmpty())
    124. ((QTreeWidgetItem*)treeViewItem)->setData(2,Qt::DisplayRole,parentId);
    125.  
    126. //((QTreeWidgetItem*)treeViewItem)->setFont(0,lucidaFont);
    127.  
    128. //((QTreeWidgetItem*)treeViewItem)->setCheckState (0, Qt::Unchecked );
    129. //((QTreeWidgetItem*)treeViewItem)->setIcon (0, Folder );
    130. //((QTreeWidgetItem*)treeViewItem)->setSizeHint (0,size );
    131.  
    132.  
    133. ((QTreeWidgetItem*)treeViewItem)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
    134. }
    To copy to clipboard, switch view to plain text mode 


    if anybody know why it is crashing plz help me...

  2. #2
    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: QTreeWidget Crashing while setText,setFont,setIcon

    Start with removing void pointers and C-style casts. This will let compiler do sanity checks.
    J-P Nurmi

  3. #3
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QTreeWidget Crashing while setText,setFont,setIcon

    But without (void*)treeItem which typecasting i will use....Is there any other alternative..

    According to my application requirment function return QtreeWidgetItem to other class...
    How i will use qt casting here...kindly tell me

  4. #4
    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: QTreeWidget Crashing while setText,setFont,setIcon

    This forum is not about C++ programming basics. Please refer your favourite C++ book about type casting.
    J-P Nurmi

Similar Threads

  1. QTreeWidget click
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 24th October 2007, 16:47
  2. Having trouble clearing a QTreeWidget.
    By Nyphel in forum Qt Programming
    Replies: 28
    Last Post: 10th October 2007, 15:33
  3. how to add icons to QTreeWidget?
    By wei243 in forum Qt Programming
    Replies: 4
    Last Post: 21st September 2007, 08:34
  4. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  5. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32

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.