Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: Having trouble clearing a QTreeWidget.

  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Having trouble clearing a QTreeWidget.

    Hello,

    I use Qt4.3.1 Open Source edition for Windows 32 bits (under Windows XP Pro SP2).

    My application has a small interface based upon a QTreeWidget (named "tree") that displays many QTreeWidgetItem *.
    When the user clic an item, the signal itemSelectionChanged() is emited. I've got a SLOT linked to this signal, so that I can analyse the item that has been clicked.
    So consider the following code as my SLOT block :




    With the following code : no problem.
    The QTreeWidget is correctly cleared.
    Qt Code:
    1. {
    2. tree->clear();
    3. }
    To copy to clipboard, switch view to plain text mode 
    Quote Originally Posted by Qt Assistant
    void QTreeWidget::clear () [slot]
    Clears the tree widget by removing all of its items and selections.
    Note: Since each item is removed from the tree widget before being deleted, the return value of QTreeWidgetItem::treeWidget() will be invalid when called from an item's destructor.



    With the following code : no problem.
    The QString contains the informations of the first column of the firts selected item on the QTreeWidget.
    Qt Code:
    1. {
    2. QString item_content = ((tree->selectedItems()).at(0))->text(0);
    3. }
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by Qt Assistant
    QList<QTreeWidgetItem *> QTreeWidget::selectedItems () const
    Returns a list of all selected non-hidden items.





    With the following code : problem.
    The application crashes, like it generally happens with memory errors...
    Qt Code:
    1. {
    2. QString item_content = ((tree->selectedItems()).at(0))->text(0);
    3. tree->clear();
    4. }
    To copy to clipboard, switch view to plain text mode 




    I don't really understand the problem, and I can't find any solution.
    The API concerning QTreeWidget and QTreeWidgetItem manages lots of pointers, like the list returned by selectedItems(). Certainly should I get the selected items instead of pointers to the selected ones... But I can't achieve to do that.

    May you help me, please ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    If the above slot is connected to a signal that emits a QTreeWidgetItem* parameter, you can't delete the object pointed by that parameter and that's what you do by calling clear() here. And make sure selectedItems() is not empty.

  3. #3
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Hi Wysota !

    I've tested the selectedItems() returned list to be sure that it's not empty, but I didn't mentionned that before. Moreover the signal itemSelectionChanged() emited by the QTreeWidget doesn't use any parameters...


  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    But the signal may be emited by another slot that takes the item as a parameter Either show us the backtrace or make a little test - instead of
    Qt Code:
    1. tree->clear()
    To copy to clipboard, switch view to plain text mode 
    call:
    Qt Code:
    1. QTimer::singleShot(0, tree, SLOT(clear()));
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Hi,

    It appears that the call of clear() throught the Qtimer makes the application crash too



    (I'm sorry for my bad English, I'm French and I do what I can to be understanded ^^)

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    In that case I need you to provide more code. Not only the method bodies, but also their prototypes, connect statements and class constructor.

  7. #7
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    The header file :

    Qt Code:
    1. #ifndef interface_impl_h
    2. #define interface_impl_h
    3.  
    4. #include "interface.h"
    5. #include "Listeur.h"
    6. #include "donnee.h"
    7.  
    8. #include <QObject>
    9. #include <QMainWindow>
    10. #include <QtGui>
    11. #include <QUrl>
    12. #include <QDesktopServices>
    13. #include <QFileInfoList>
    14. #include <QFileDialog>
    15. #include <QComboBox>
    16. #include <QList>
    17. #include <QFile>
    18. #include <QDir>
    19. #include <QString>
    20. #include <QPixmap>
    21.  
    22. class interface_impl : public QMainWindow, public Ui::MainWindow_interface
    23. {
    24. Q_OBJECT
    25.  
    26. public:
    27. interface_impl(Listeur *appelant = 0, QWidget *parent = 0);
    28. void resizer_tableaux();
    29. void Enregistrer_config();
    30.  
    31. protected:
    32. void showEvent(QShowEvent *event);
    33. void closeEvent(QCloseEvent *event);
    34.  
    35. private slots:
    36. void SLOT_ajouter_repertoire_scan();
    37. void SLOT_supprimer_repertoire_scan();
    38. void SLOT_rechercher_repertoire_scan();
    39.  
    40. void SLOT_ajouter_repertoire_noscan();
    41. void SLOT_supprimer_repertoire_noscan();
    42. void SLOT_rechercher_repertoire_noscan();
    43.  
    44. void SLOT_actualiser_liste_films();
    45. void SLOT_lancer_le_film(QTreeWidgetItem *, int);
    46.  
    47. void SLOT_selection_changed();
    48. void SLOT_ouvrir_selection();
    49. void SLOT_lancer_selection();
    50.  
    51. void SLOT_rechercher_synopsis_jaquettes_ALL();
    52. void SLOT_actualiser_synopsis_jaquettes_AC();
    53. void SLOT_actualiser_synopsis_jaquettes_QLCS();
    54. void SLOT_actualiser_sysnopsis_jaquettes_VC();
    55. void SLOT_actualiser_jaquettes_MC();
    56.  
    57. private:
    58. void Masquer_checkBoxes();
    59. void Nettoyer_texte_checkBoxes();
    60. void MAJ_checkBoxes_racines();
    61. void MAJ_listes_repertoires();
    62. void Charger_config();
    63. void MAJ_checkBoxes_racines_selon_config(QString, QString); // Texte, valeur activation
    64.  
    65. QString get_filename_selection();
    66. QString get_filepath_selection();
    67.  
    68. Listeur *Listeur_appelant;
    69. int NB_ligne_tableau_recherche_repertoire;
    70.  
    71. QList<QTreeWidgetItem *> liste_selection;
    72. };
    73.  
    74. #endif // interface_impl_h
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    The CPP file :

    Qt Code:
    1. #include <fstream>
    2. #include <iostream>
    3. using namespace std;
    4.  
    5. #include "interface_impl.h"
    6.  
    7. interface_impl::interface_impl(Listeur *appelant, QWidget *parent) : QMainWindow(parent)
    8. {
    9. cout << "interface_impl" << endl;
    10. setupUi(this);
    11.  
    12. Listeur_appelant = appelant;
    13.  
    14. Masquer_checkBoxes();
    15. MAJ_checkBoxes_racines();
    16.  
    17. connect(bouton_scan_plus_rep, SIGNAL(clicked()), this, SLOT(SLOT_ajouter_repertoire_scan()));
    18. connect(bouton_scan_moins_rep, SIGNAL(clicked()), this, SLOT(SLOT_supprimer_repertoire_scan()));
    19. connect(bouton_noscan_plus_rep, SIGNAL(clicked()), this, SLOT(SLOT_ajouter_repertoire_noscan()));
    20. connect(bouton_noscan_moins_rep, SIGNAL(clicked()), this, SLOT(SLOT_supprimer_repertoire_noscan()));
    21. connect(bouton_lister, SIGNAL(clicked()), this, SLOT(SLOT_actualiser_liste_films()));
    22.  
    23. connect(bouton_rechercher, SIGNAL(clicked()), this, SLOT(SLOT_rechercher_synopsis_jaquettes_ALL()));
    24. //connect(bouton_AC, SIGNAL(clicked()), this, SLOT(SLOT_actualiser_synopsis_jaquettes_AC()));
    25. //connect(bouton_QLCS, SIGNAL(clicked()), this, SLOT(SLOT_actualiser_synopsis_jaquettes_QLCS()));
    26. //connect(bouton_VC, SIGNAL(clicked()), this, SLOT(SLOT_actualiser_sysnopsis_jaquettes_VC()));
    27. //connect(bouton_MC, SIGNAL(clicked()), this, SLOT(SLOT_actualiser_jaquettes_MC()));
    28.  
    29. connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(SLOT_lancer_le_film(QTreeWidgetItem*, int)));
    30.  
    31. connect(tree, SIGNAL(itemSelectionChanged()), this, SLOT(SLOT_selection_changed()));
    32. connect(bouton_ouvrir, SIGNAL(clicked()), this, SLOT(SLOT_ouvrir_selection()));
    33. connect(bouton_lancer, SIGNAL(clicked()), this, SLOT(SLOT_lancer_selection()));
    34.  
    35. Charger_config();
    36. }
    37.  
    38. void interface_impl::SLOT_rechercher_synopsis_jaquettes_ALL()
    39. {
    40. Listeur_appelant->Rechercher_jaquettes_synopsis();
    41. }
    42.  
    43. void interface_impl::SLOT_actualiser_synopsis_jaquettes_AC()
    44. {
    45. Listeur_appelant->Utiliser_HTTP_AC();
    46. }
    47.  
    48. void interface_impl::SLOT_actualiser_synopsis_jaquettes_QLCS()
    49. {
    50. Listeur_appelant->Utiliser_HTTP_QLCS();
    51. }
    52.  
    53. void interface_impl::SLOT_actualiser_sysnopsis_jaquettes_VC()
    54. {
    55. Listeur_appelant->Utiliser_HTTP_VC();
    56. }
    57.  
    58. void interface_impl::SLOT_actualiser_jaquettes_MC()
    59. {
    60. Listeur_appelant->Utiliser_HTTP_MC();
    61. }
    62.  
    63. void interface_impl::SLOT_selection_changed()
    64. {
    65. cout << "\n\nSLOT_selection_changed" << endl;
    66.  
    67. liste_selection.clear();
    68. //liste_selection = tree->selectedItems();
    69.  
    70. // ----------------------
    71.  
    72. // QTreeWidgetItem *item;
    73. QString item_name;
    74. // QString item_path;
    75. // QDir mon_dossier_cible;
    76. // QFile mon_fichier_cible;
    77. // QUrl mon_url;
    78. // bool isDir;
    79. // bool isFile;
    80.  
    81. // item = liste_selection.at(0);
    82.  
    83. // item_name = item->text(0);
    84. // item_path = item->text(1);
    85.  
    86. item_name = ((tree->selectedItems()).at(0))->text(0);
    87.  
    88. tree->clear();
    89. //QTimer::singleShot(0, tree, SLOT(clear()));
    90.  
    91.  
    92. // mon_dossier_cible.setPath(item_path);
    93. // mon_fichier_cible.setFileName(item_path);
    94. // mon_url = QUrl::fromLocalFile(item_path);
    95. // isDir = mon_dossier_cible.exists();
    96. // isFile = mon_fichier_cible.exists();
    97. //
    98. // // L'objet sélectionné n'est pas un dossier
    99. // if (isDir == false)
    100. // {
    101. // // Par contre c'est bien un fichier, donc un film
    102. // if (isFile == true)
    103. // {
    104. // // On reconstruit le chemin d'accès au synopsis
    105. // QString acces_synopsys = "./Synopsis/";
    106. // acces_synopsys.append(item_name);
    107. // acces_synopsys.append(".html");
    108. //
    109. // // On crée l'URL qui sera utilisée par le QTextBroxser de synopsis
    110. // QUrl html_url;
    111. // html_url = QUrl::fromLocalFile(acces_synopsys);
    112. //
    113. // // On met à jour le QTextBrowser du synopsis
    114. // TB_Synopsis->setSource(html_url);
    115. //
    116. // // On reconstruit le nom complet de la jaquette (avec extension)
    117. // QString item_name_stored = "";
    118. // QDir dossier_synopsis("Jaquettes");
    119. // QFileInfoList synopsis_fileInfoList = dossier_synopsis.entryInfoList();
    120. // for(int i = 0; i < synopsis_fileInfoList.size(); ++i)
    121. // {
    122. // if(synopsis_fileInfoList.at(i).isFile()) // On peut avoir des DIR
    123. // {
    124. // if (synopsis_fileInfoList.at(i).baseName() == item_name) // Nom sans extension
    125. // {
    126. // item_name_stored = synopsis_fileInfoList.at(i).fileName(); // Nom avec extension
    127. // i = synopsis_fileInfoList.size(); // Fin de parcours
    128. // }
    129. // }
    130. // }
    131. //
    132. // if (item_name_stored == "") // La recherche n'a pas aboutit, ne devrait pas survenir
    133. // {
    134. // item_name_stored .append(item_name);
    135. // item_name_stored .append(".jpg");
    136. // }
    137. //
    138. // // On reconstruit le chemin d'accès à la jaquette
    139. // QString acces_jaquette = "./Jaquettes/";
    140. // acces_jaquette.append(item_name_stored);
    141. //
    142. // cout << "Accès jaquette : " << acces_jaquette.toStdString() << endl;
    143. //
    144. // // Affichage de l'image
    145. // int hauteur_jaquette = (tree->height()) / 2; // 50% de la hauteur de l'interface
    146. // QPixmap jaquette_pixmap;
    147. // jaquette_pixmap.load(acces_jaquette); // Chargement de l'image dans le QPixmap
    148. // jaquette_pixmap = jaquette_pixmap.scaledToHeight(hauteur_jaquette, Qt::SmoothTransformation); // Redimensionnement de l'image
    149. // label_jaquette->setPixmap(jaquette_pixmap); // Affichage du QPixmap (et donc de l'image) dans le QLabel de l'interface
    150. // }
    151. // }
    152. // else // L'objet sélectionné est un dossier
    153. // {
    154. // label_jaquette->clear();
    155. // TB_Synopsis->clear();
    156. // }
    157. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Qt Code:
    1. QString interface_impl::get_filename_selection()
    2. {
    3. QString item_name;
    4.  
    5. item = liste_selection.at(0);
    6. item_name = item->text(0);
    7.  
    8. return item_name;
    9. }
    10.  
    11. QString interface_impl::get_filepath_selection()
    12. {
    13. QString item_path;
    14.  
    15. item = liste_selection.at(0);
    16. item_path = item->text(1);
    17.  
    18. return item_path;
    19. }
    20.  
    21. void interface_impl::SLOT_ouvrir_selection()
    22. {
    23. cout << "SLOT_ouvrir_dossier" << endl;
    24.  
    25. QString item_path;
    26. QDir mon_dossier_cible;
    27. QFile mon_fichier_cible;
    28. QUrl mon_url;
    29. bool isDir;
    30. bool isFile;
    31. QStringList liste_dossiers_ouverts;
    32.  
    33. for (int i=0; i<liste_selection.size(); i++)
    34. {
    35. item = liste_selection.at(i);
    36. item_path = item->text(1);
    37. mon_dossier_cible.setPath(item_path);
    38. mon_fichier_cible.setFileName(item_path);
    39. mon_url = QUrl::fromLocalFile(item_path);
    40. isDir = mon_dossier_cible.exists();
    41. isFile = mon_fichier_cible.exists();
    42.  
    43. cout << "\t Cible : \t" << (item->text(0)).toStdString() << endl;
    44. cout << "\t Acces : \t" << item_path.toStdString() << endl;
    45. cout << "\t isDir : \t" << isDir << endl;
    46. cout << "\t isFile : \t" << isFile << endl;
    47. cout << "\n" << endl;
    48.  
    49. // L'objet sélectionné est un dossier
    50. if (isDir == true)
    51. {
    52. if (liste_dossiers_ouverts.contains(item_path) == false) // Si ce dossier n'a pas encore été ouvert
    53. {
    54. liste_dossiers_ouverts.append(item_path);
    55. mon_url = QUrl::fromLocalFile(item_path);
    56. QDesktopServices::openUrl(mon_url);
    57. }
    58. }
    59.  
    60. // L'objet sélectionné n'est pas un dossier
    61. else
    62. {
    63. // Par contre c'est bien un fichier, donc un film
    64. if (isFile == true)
    65. {
    66. QStringList liste_item_path = item_path.split("/");
    67.  
    68. // Parcours de la liste sauf le dernier élément
    69. // Pour reconstruire le chemin d'accès au dossier parant
    70. QString item_path_to_parent = "";
    71. for (int j=0; j<liste_item_path.size()-1; j++)
    72. {
    73. item_path_to_parent.append(liste_item_path.at(j));
    74. item_path_to_parent.append("/");
    75. }
    76.  
    77. if (liste_dossiers_ouverts.contains(item_path_to_parent) == false) // Si ce dossier n'a pas encore été ouvert
    78. {
    79. liste_dossiers_ouverts.append(item_path_to_parent);
    80. mon_url = QUrl::fromLocalFile(item_path_to_parent);
    81. QDesktopServices::openUrl(mon_url);
    82. }
    83. }
    84. }
    85. }
    86. }
    87.  
    88. void interface_impl::SLOT_lancer_selection()
    89. {
    90. cout << "SLOT_lancer_selection" << endl;
    91.  
    92. QString item_path;
    93. QDir mon_dossier_cible;
    94. QFile mon_fichier_cible;
    95. QUrl mon_url;
    96. bool isDir;
    97. bool isFile;
    98. QStringList liste_films_lances;
    99.  
    100. for (int i=0; i<liste_selection.size(); i++)
    101. {
    102. item = liste_selection.at(i);
    103. item_path = item->text(1);
    104. mon_dossier_cible.setPath(item_path);
    105. mon_fichier_cible.setFileName(item_path);
    106. mon_url = QUrl::fromLocalFile(item_path);
    107. isDir = mon_dossier_cible.exists();
    108. isFile = mon_fichier_cible.exists();
    109.  
    110. cout << "\t Cible : \t" << (item->text(0)).toStdString() << endl;
    111. cout << "\t Acces : \t" << item_path.toStdString() << endl;
    112. cout << "\t isDir : \t" << isDir << endl;
    113. cout << "\t isFile : \t" << isFile << endl;
    114. cout << "\n" << endl;
    115.  
    116. // L'objet sélectionné est un dossier
    117. if (isDir == true)
    118. {
    119. // if (liste_films_lances.contains(item_path) == false) // Si ce film n'a pas encore été lancé
    120. // {
    121. // liste_films_lances.append(item_path);
    122. // mon_url = QUrl::fromLocalFile(item_path);
    123. // QDesktopServices::openUrl(mon_url);
    124. // }
    125. }
    126.  
    127. // L'objet sélectionné n'est pas un dossier
    128. else
    129. {
    130. // Par contre c'est bien un fichier, donc un film
    131. if (isFile == true)
    132. {
    133. if (liste_films_lances.contains(item_path) == false) // Si ce film n'a pas encore été lancé
    134. {
    135. liste_films_lances.append(item_path);
    136. mon_url = QUrl::fromLocalFile(item_path);
    137. QDesktopServices::openUrl(mon_url);
    138. }
    139. }
    140. }
    141. }
    142. }
    143.  
    144. void interface_impl::SLOT_lancer_le_film(QTreeWidgetItem *item, int column)
    145. {
    146. cout << "\n\n" << endl;
    147. cout << "SLOT_lancer_le_film" << endl;
    148. cout << "Film : \t\t" << (item->text(0)).toStdString() << endl;
    149. cout << "Acces : \t" << (item->text(1)).toStdString() << endl;
    150.  
    151. QUrl mon_url;
    152. mon_url = QUrl::fromLocalFile(item->text(1));
    153. QDesktopServices::openUrl(mon_url);
    154. }
    155.  
    156. void interface_impl::showEvent(QShowEvent *event)
    157. {
    158. cout << "showEvent" << endl;
    159.  
    160. // // Préparation de l'affichage taille "normale" (fenêtré)
    161. // int hauteur_ecran = (QApplication::desktop()->availableGeometry(0)).height();
    162. // int largeur_ecran = (QApplication::desktop()->availableGeometry(0)).width();
    163. // setGeometry(50, 50, largeur_ecran - 100, hauteur_ecran - 100);
    164. //
    165. // // Passage en plein écran
    166. showMaximized();
    167.  
    168. // Redimensionnement des colonnes de stableaux d'ajout / suppression de dossiers à scanner / ne pas scanner
    169. // int largeur_tableau = (tableau_scan->width()) - (((tableau_scan->width()) * 3) / 100);
    170. // int largeur_col_0 = (largeur_tableau * 10) / 100;
    171. // int largeur_col_1 = (largeur_tableau * 20) / 100;
    172. // int largeur_col_2 = largeur_tableau - (largeur_col_0 + largeur_col_1);
    173.  
    174. // tableau_scan->setColumnWidth(0, largeur_col_0);
    175. // tableau_scan->setColumnWidth(1, largeur_col_1);
    176. // tableau_scan->setColumnWidth(2, largeur_col_2);
    177. //
    178. // tableau_noscan->setColumnWidth(0, largeur_col_0);
    179. // tableau_noscan->setColumnWidth(1, largeur_col_1);
    180. // tableau_noscan->setColumnWidth(2, largeur_col_2);
    181.  
    182. // Masquage de la colonne des chemins d'accès
    183. tree->hideColumn(1);
    184. }
    185.  
    186. void interface_impl::resizer_tableaux()
    187. {
    188. tableau_scan->resizeColumnToContents(0);
    189. tableau_scan->resizeColumnToContents(1);
    190. tableau_scan->setColumnWidth(1, tableau_scan->columnWidth(1) + 5);
    191. // tableau_scan->setColumnWidth(2, tableau_scan->width() - tableau_scan->columnWidth(0) - tableau_scan->columnWidth(1));
    192.  
    193. tableau_noscan->resizeColumnToContents(0);
    194. tableau_noscan->resizeColumnToContents(1);
    195. tableau_noscan->setColumnWidth(1, tableau_noscan->columnWidth(1) + 5);//
    196. // tableau_noscan->setColumnWidth(2, tableau_noscan->width() - tableau_noscan->columnWidth(0) - tableau_noscan->columnWidth(1));
    197.  
    198. // cout << tableau_scan->width() << endl;
    199. // cout << tableau_scan->columnWidth(0) << endl;
    200. // cout << tableau_scan->columnWidth(1) << endl;
    201. // cout << tableau_scan->columnWidth(2) << endl;
    202. // cout << tableau_scan->columnWidth(3) << endl;
    203. // cout << tableau_scan->width() - 10 - tableau_scan->columnWidth(0) - tableau_scan->columnWidth(1) << endl;
    204.  
    205. }
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Qt Code:
    1. void interface_impl::MAJ_listes_repertoires()
    2. {
    3. cout << "MAJ_listes_repertoires" << endl;
    4.  
    5. // Suppression du contenu des listes
    6. Listeur_appelant->vider_listes_repertoires();
    7.  
    8. // Variables temporaires
    9. QTableWidgetItem *QWI_element_courant;
    10. QString chemin_acces;
    11.  
    12. // Liste des répertoires à scanner
    13. for (int r = 0; r < tableau_scan->rowCount(); ++r)
    14. {
    15. // Récupération du chemin
    16. QWI_element_courant = tableau_scan->item(r, 0); // Checkbox
    17. if (QWI_element_courant->checkState() == Qt::Checked)
    18. {
    19. QWI_element_courant = tableau_scan->item(r, 2); // Chemin d'accès
    20. chemin_acces = "";
    21. chemin_acces = QWI_element_courant->text();
    22. if (chemin_acces != "")
    23. {
    24. // Ajout dans la liste
    25. Listeur_appelant->ajouter_repertoire_scan(chemin_acces);
    26. }
    27. }
    28. }
    29.  
    30. // Liste des répertoires à ne pas scanner
    31. for (int r = 0; r < tableau_noscan->rowCount(); ++r)
    32. {
    33. // Récupération du chemin
    34. QWI_element_courant = tableau_noscan->item(r, 0); // Checkbox
    35. if (QWI_element_courant->checkState() == Qt::Checked)
    36. {
    37. QWI_element_courant = tableau_noscan->item(r, 2); // Chemin d'accès
    38. chemin_acces = "";
    39. chemin_acces = QWI_element_courant->text();
    40. if (chemin_acces != "")
    41. {
    42. // Ajout dans la liste
    43. Listeur_appelant->ajouter_repertoire_noscan(chemin_acces);
    44. }
    45. }
    46. }
    47. }
    48.  
    49. void interface_impl::SLOT_ajouter_repertoire_scan()
    50. {
    51. cout << "SLOT_ajouter_repertoire_scan" << endl;
    52.  
    53. tableau_scan->setRowCount(tableau_scan->rowCount() + 1);
    54.  
    55. QTableWidgetItem *Item_2 = new QTableWidgetItem("");
    56.  
    57. QPushButton *bouton_rechercher = new QPushButton("Rechercher...");
    58. connect(bouton_rechercher, SIGNAL(clicked()), this, SLOT(SLOT_rechercher_repertoire_scan()));
    59.  
    60. Item_0->setCheckState(Qt::Unchecked);
    61. Item_0->setFlags(Item_0->flags() & (~(Qt::ItemIsEditable)));
    62. //Item_2->setFlags(Item_2->flags() & (Qt::ItemIsEditable));
    63.  
    64. tableau_scan->setItem(tableau_scan->rowCount()-1, 0, Item_0);
    65. tableau_scan->setCellWidget(tableau_scan->rowCount()-1, 1, bouton_rechercher);
    66. tableau_scan->setItem(tableau_scan->rowCount()-1, 2, Item_2);
    67. }
    68.  
    69. void interface_impl::SLOT_supprimer_repertoire_scan()
    70. {
    71. cout << "SLOT_supprimer_repertoire_scan" << endl;
    72.  
    73. // Recherche la ligne du tableau_scan sélectionnée
    74. QPushButton *QPB_element_courant;
    75. int row_number = -1;
    76. for (int r = 0; r < tableau_scan->rowCount(); ++r)
    77. {
    78. for (int c = 0; c < tableau_scan->columnCount(); ++c)
    79. {
    80. if (c == 0) // Item
    81. {
    82. if ((tableau_scan->item(r,c))->isSelected() == true)
    83. {
    84. row_number = r;
    85. }
    86. }
    87. else if (c == 1) // Boutons
    88. {
    89. QPB_element_courant = static_cast<QPushButton*>(tableau_scan->cellWidget(r, c));
    90. if (QPB_element_courant->hasFocus() == true)
    91. {
    92. row_number = r;
    93. }
    94. }
    95. else if (c == 2) // Item
    96. {
    97. if ((tableau_scan->item(r,c))->isSelected() == true)
    98. {
    99. row_number = r;
    100. }
    101. }
    102. }
    103. }
    104.  
    105. if (row_number == -1)
    106. {
    107. tableau_scan->removeRow(tableau_scan->rowCount()-1);
    108. }
    109. else
    110. {
    111. tableau_scan->removeRow(row_number);
    112. }
    113. }
    114.  
    115. void interface_impl::SLOT_rechercher_repertoire_scan()
    116. {
    117. cout << "SLOT_rechercher_repertoire_scan" << endl;
    118.  
    119. // Recherche la ligne du tableau_scan depuis laquelle le bouton a été cliqué
    120. QPushButton *QPB_element_courant;
    121. int row_number = -1;
    122. for (int r = 0; r < tableau_scan->rowCount(); ++r)
    123. {
    124. for (int c = 0; c < tableau_scan->columnCount(); ++c)
    125. {
    126. if (c == 0) // Item
    127. {
    128. if ((tableau_scan->item(r,c))->isSelected() == true)
    129. {
    130. row_number = r;
    131. }
    132. }
    133. else if (c == 1) // Boutons
    134. {
    135. QPB_element_courant = static_cast<QPushButton*>(tableau_scan->cellWidget(r, c));
    136. if (QPB_element_courant->hasFocus() == true)
    137. {
    138. row_number = r;
    139. }
    140. }
    141. else if (c == 2) // Item
    142. {
    143. if ((tableau_scan->item(r,c))->isSelected() == true)
    144. {
    145. row_number = r;
    146. }
    147. }
    148. }
    149. }
    150.  
    151. // Récupération du chemin affiché sur cette ligne du tableau_scan
    152. QTableWidgetItem *QWI_element_courant;
    153. QWI_element_courant = tableau_scan->item(row_number, 2);
    154. QString chemin_acces_affiche = QWI_element_courant->text();
    155.  
    156. // Fenêtre de recherche de répertoire
    157. QString titre = "Répertoire à scanner";
    158. QString chemin = "/home";
    159. if (chemin_acces_affiche != "")
    160. {
    161. chemin = chemin_acces_affiche;
    162. }
    163. QString chemin_acces_voulu = QFileDialog::getExistingDirectory(this, titre, chemin, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
    164.  
    165. // Mise à jour du chemin affiché dans cette ligne du tableau_scan
    166. if (chemin_acces_voulu != "")
    167. {
    168. QWI_element_courant->setText(chemin_acces_voulu);
    169. }
    170. }
    171. void interface_impl::SLOT_ajouter_repertoire_noscan()
    172. {
    173. cout << "SLOT_ajouter_repertoire_noscan" << endl;
    174.  
    175. tableau_noscan->setRowCount(tableau_noscan->rowCount() + 1);
    176.  
    177. QTableWidgetItem *Item_2 = new QTableWidgetItem("");
    178.  
    179. QPushButton *bouton_rechercher = new QPushButton("Rechercher...");
    180. connect(bouton_rechercher, SIGNAL(clicked()), this, SLOT(SLOT_rechercher_repertoire_noscan()));
    181.  
    182. Item_0->setCheckState(Qt::Unchecked);
    183. Item_0->setFlags(Item_0->flags() & (~(Qt::ItemIsEditable)));
    184. //Item_2->setFlags(Item_2->flags() & (Qt::ItemIsEditable));
    185.  
    186. tableau_noscan->setItem(tableau_noscan->rowCount()-1, 0, Item_0);
    187. tableau_noscan->setCellWidget(tableau_noscan->rowCount()-1, 1, bouton_rechercher);
    188. tableau_noscan->setItem(tableau_noscan->rowCount()-1, 2, Item_2);
    189. }
    190.  
    191. void interface_impl::SLOT_supprimer_repertoire_noscan()
    192. {
    193. cout << "SLOT_supprimer_repertoire_noscan" << endl;
    194.  
    195. // Recherche la ligne du tableau_scan sélectionnée
    196. QPushButton *QPB_element_courant;
    197. int row_number = -1;
    198. for (int r = 0; r < tableau_noscan->rowCount(); ++r)
    199. {
    200. for (int c = 0; c < tableau_noscan->columnCount(); ++c)
    201. {
    202. if (c == 0) // Item
    203. {
    204. if ((tableau_noscan->item(r,c))->isSelected() == true)
    205. {
    206. row_number = r;
    207. }
    208. }
    209. else if (c == 1) // Boutons
    210. {
    211. QPB_element_courant = static_cast<QPushButton*>(tableau_noscan->cellWidget(r, c));
    212. if (QPB_element_courant->hasFocus() == true)
    213. {
    214. row_number = r;
    215. }
    216. }
    217. else if (c == 2) // Item
    218. {
    219. if ((tableau_noscan->item(r,c))->isSelected() == true)
    220. {
    221. row_number = r;
    222. }
    223. }
    224. }
    225. }
    226.  
    227. if (row_number == -1)
    228. {
    229. tableau_noscan->removeRow(tableau_noscan->rowCount()-1);
    230. }
    231. else
    232. {
    233. tableau_noscan->removeRow(row_number);
    234. }
    235. }
    236.  
    237. void interface_impl::SLOT_rechercher_repertoire_noscan()
    238. {
    239. cout << "SLOT_rechercher_repertoire_noscan" << endl;
    240.  
    241. // Recherche la ligne du tableau_noscan depuis laquelle le bouton a été cliqué
    242. QPushButton *QPB_element_courant;
    243. int row_number = -1;
    244. for (int r = 0; r < tableau_noscan->rowCount(); ++r)
    245. {
    246. for (int c = 0; c < tableau_noscan->columnCount(); ++c)
    247. {
    248. if (c == 0) // Item
    249. {
    250. if ((tableau_noscan->item(r,c))->isSelected() == true)
    251. {
    252. row_number = r;
    253. }
    254. }
    255. else if (c == 1) // Boutons
    256. {
    257. QPB_element_courant = static_cast<QPushButton*>(tableau_noscan->cellWidget(r, c));
    258. if (QPB_element_courant->hasFocus() == true)
    259. {
    260. row_number = r;
    261. }
    262. }
    263. else if (c == 2) // Item
    264. {
    265. if ((tableau_noscan->item(r,c))->isSelected() == true)
    266. {
    267. row_number = r;
    268. }
    269. }
    270. }
    271. }
    272.  
    273. // Récupération du chemin affiché sur cette ligne du tableau_scan
    274. QTableWidgetItem *QWI_element_courant;
    275. QWI_element_courant = tableau_noscan->item(row_number, 2);
    276. QString chemin_acces_affiche = QWI_element_courant->text();
    277.  
    278. // Fenêtre de recherche de répertoire
    279. QString titre = "Répertoire à scanner";
    280. QString chemin = "/home";
    281. if (chemin_acces_affiche != "")
    282. {
    283. chemin = chemin_acces_affiche;
    284. }
    285. QString chemin_acces_voulu = QFileDialog::getExistingDirectory(this, titre, chemin, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
    286.  
    287. // Mise à jour du chemin affiché dans cette ligne du tableau_scan
    288. if (chemin_acces_voulu != "")
    289. {
    290. QWI_element_courant->setText(chemin_acces_voulu);
    291. }
    292. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Rah no... There is too much code, I'm at the end of the project.
    Moreover, I should shouw you the Listeur class too, cause it adds QTreeWidgetItem* to the QTreeWidget (This is the main class that create theinterface and serach for the data that will fill the QTreeWidget... :s)

    I'll try to do something more clearly later, because it won't be helpfull if I give you all that code as is... With so poor comments

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    I think you should have attached files instead of pasting them here

    I'll dig into what you provided and see what might be wrong. Currently I can't find the slot where you call clear() on the tree widget, could you point me to it?

    BTW. You really should have taken the model-view approach instead of using convenience classes...

    Edit: Could you provide the backtrace after the crash?
    Last edited by wysota; 9th October 2007 at 16:36.

  13. #13
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Yes, great idea

    Link to the project archived in ZIP format
    Link to the project archived in RAR format

    I should have taken a MVC approach, yes, but this project was just a small personnal project in order to list me what movies I have on my computer. I made the first build very simply, and I didn't took care about the conceptual approach... Shame on me !
    That's the reason why I didn't read all the informations relative to QTreeWidget in the Qt Assistant, and didn't saw the View and Model aspects avaibled for this widget .
    After that I developped more and more small functionnality, when I needed them. The project isn't really well concepted...

    My project is compounded of :
    - Listeur class, the main class that set the interface and lauch the various threads used by my application.
    - Interface_impl class, the interface implementation class that handle the user actions and wishes.
    - Thread_scanneur class, that search on my HDD in order to list the movies.
    - Thread_HTTP_XXX classes, that search on websites (1 class by website) in order to find, download and store the movies covers and resumes.

    So the 3 classes that manage QTreeWidgetItem* are :
    - Listeur
    - Interface_impl
    - Thread_scanneur

    The class that actually make the application to crash is Interface_impl.
    The signal concerned is : itemSelectionChanged().
    The slot concerned by this signal is : SLOT_selection_changed().

    The goal of this slot is to :
    - store all the items selected by the user
    - get the FIRST item selected in order to know the movie name that has been selected
    - display the cover and the resume of this movie on the interface
    Actually all this stuff is commented in the slot.

    There is no need to clear the QTreeWidget for doing that job...
    In reallity, the application used to crash when the user selected a movie, and then asked for an update of the movie list. This update was clearing the QTreeWidget in order to display the list of movies found on the HDD... And at this time, the application used to crash.

    So, in order to simplify the tests, I decided to clear() the QTreeWidget directly in the SLOT called when the selection changed.

    Thanks a lot for your help Wysota, as usually !



    EDIT : I've not really backtraces or debugger under the hand.
    I simply displays some comments on the cout at each step, in order to detect and target where the application crashes.

    EDIT : Attached the project source archived in ZIP format.
    Attached Files Attached Files
    Last edited by Nyphel; 9th October 2007 at 17:08.

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    Khyym... please use the attachment feature of the forum next time. We don't like external links here.

    I should have taken a MVC approach, yes, but this project was just a small personnal project in order to list me what movies I have on my computer. I made the first build very simply, and I didn't took care about the conceptual approach... Shame on me !
    That's the reason why I didn't read all the informations relative to QTreeWidget in the Qt Assistant, and didn't saw the View and Model aspects avaibled for this widget .
    That's usually the problem. You start with something simple and suddenly it happens to be a big project. You're wasting much effort operating on the filesystem and you could have just used QDirModel with an optional proxy model to filter out entries you didn't want. You should think about redesigning it...


    EDIT : I've not really backtraces or debugger under the hand.
    I simply displays some comments on the cout at each step, in order to detect and target where the application crashes.
    That's not good, because what's important is not only that where the application crashes but also which method invoked the method that crashed and with what parameters. Unless you provide us with something small and compilable, you have to provide the backtrace yourself. Currently there's just too much code to analyse. It could be that the crash is caused by one of the threads (from what I understand you are using threads). Don't you by any chance operate on the tree from within a worker thread? Anyway please provide the backtrace or cut down the project to something small that reproduces the problem.

  15. #15
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Oki, I've attached the source code in the previous post .

    So, how may I produce the fully backtrace for my code ?
    I'm under Windows XP Pro SP2, using Eclipse as text editor.
    I've recently added the Qt Plugin for Eclipse in order to managed my .pro file, to use the API code completion, to build and run my project...

    But I've no idea about what concerns the backtraces/debugger functionalities of Qt and/or the Eclipse integration.

    My Qt is compiled in release/shared configuration.
    Should I rebuild it in debug/shared configuration ?



    PS : I'm sure that the crash isn't caused by a Thread.
    The application crashes when no Thread is started, I can make it crash just after the launch if necessary. My thread are only started on user ask, by clicking buttons on the interface et traces are displayed on the cout when the run() method is called.
    Moreover, I've decided that no thread would modify the QTreeWidget. So only Listeur and Interface_impl classes can modify the QTreeWidget, I prefer that...

    But I understand why the backtrace is necessary
    Last edited by Nyphel; 9th October 2007 at 17:19.

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    Quote Originally Posted by Nyphel View Post
    Oki, I've attached the source code in the previous post .
    Yes, I know, but I assume that it's a bit too complex to understand it in 5 minutes.

    So, how may I produce the fully backtrace for my code ?
    I'm under Windows XP Pro SP2, using Eclipse as text editor.
    I've recently added the Qt Plugin for Eclipse in order to managed my .pro file, to use the API code completion, to build and run my project...
    If you're using MinGW as your compiler, you need to install gdb (GNU Debugger) and run your application under its control. When it crashes, type in "bt", press enter and paste in the result here. Just remember to compile your app in debug mode.

    Should I rebuild it in debug/shared configuration ?
    Not necessarily. You can compile your app in debug mode and link it against release Qt libs. But if you're not certain you can do it, it's better to compile Qt in debug mode as well.

  17. The following user says thank you to wysota for this useful post:

    Nyphel (10th October 2007)

  18. #17
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    I'm back

    In order to remove all doubt, I uninstalled Qt.
    I reinstalled Qt with the MinGW download.
    I reconfigured it with the following options : "-debug -release -shared".
    I re-built Qt without errors or warnings using "make sub-src".
    I built the Qt Debug Librairies without errors or warnings.

    I installed GDB (for MinGW).
    I reinstalled the Eclipse Qt Integration tool.

    I modified the .PRO file in order to add "Config += Debug".
    I launched my Qt Command Prompt.
    I built my application with "qmake" and "make".

    I' launched the GDB tool with "gdb release/Listeur" :
    Qt Code:
    1. Setting up a MinGW/Qt only environment...
    2. -- QTDIR set to D:\Applications\Qt\4.3.1
    3. -- PATH set to D:\Applications\Qt\4.3.1\bin
    4. -- Adding D:\Applications\MinGW\bin to PATH
    5. -- Adding C:\WINDOWS\System32 to PATH
    6. -- QMAKESPEC set to win32-g++
    7.  
    8. D:\Applications\Qt\4.3.1\Workspace\Listeur>gdb release/Listeur
    9. GNU gdb 6.3
    10. Copyright 2004 Free Software Foundation, Inc.
    11. GDB is free software, covered by the GNU General Public License, and you are
    12. welcome to change it and/or distribute copies of it under certain conditions.
    13. Type "show copying" to see the conditions.
    14. There is absolutely no warranty for GDB. Type "show warranty" for details.
    15. This GDB was configured as "i686-pc-mingw32"...(no debugging symbols found)
    To copy to clipboard, switch view to plain text mode 

    Next, I ran my application under control of GDB :
    Qt Code:
    1. (gdb) run
    2. Starting program: D:\Applications\Qt\4.3.1\Workspace\Listeur/release/Listeur.exe
    3.  
    4. ---Type <return> to continue, or q <return> to quit---
    To copy to clipboard, switch view to plain text mode 

    Of course, I pressed my RETURN key.
    The application has been launched.
    I selected an item of my QTreeWidget, and the application crashed :
    Qt Code:
    1. Program received signal SIGSEGV, Segmentation fault.
    2. 0x00446d3b in ?? ()
    To copy to clipboard, switch view to plain text mode 

    I typed in "bt", and here is what GDB returned me :
    Qt Code:
    1. (gdb) bt
    2. #0 0x00446d3b in ?? ()
    3. #1 0x0023979c in ?? ()
    4. #2 0x01543350 in ?? ()
    5. #3 0x10180418 in ZeqRK6QRectFS1_ ()
    6. from D:\Applications\Qt\4.3.1\bin\QtCore4.dll
    7. #4 0x10009f40 in ZN18QThreadStorageData6finishEPPv ()
    8. from D:\Applications\Qt\4.3.1\bin\QtCore4.dll
    9. #5 0x00455f40 in ?? ()
    10. #6 0x004a871b in ?? ()
    11. #7 0x002397cc in ?? ()
    12. #8 0x00446e42 in ?? ()
    13. #9 0x0023973c in ?? ()
    14. #10 0x00000001 in ?? ()
    15. #11 0x00000000 in ?? () from
    16. #12 0x00000027 in ?? ()
    17. #13 0x00239894 in ?? ()
    18. #14 0x002397e4 in ?? ()
    19. #15 0x00ba8372 in ZN11QMainWindow11qt_metacallEN11QMetaObject4CallEiPPv ()
    20. #16 0x0023a31c in ?? ()
    21. (gdb)
    To copy to clipboard, switch view to plain text mode 

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    Hmm... this doesn't look like debug mode And if the data is correct, it means your application has gone mad. Omit the "-release" switch when compiling Qt (or use -debug_and_release instead of -debug and -release). And make sure you add "CONFIG+=debug" to the project file (I'm not sure if it's case sensitive or not).

    Based on what we have here I'm sure your application uses threads (behind the scene, probably if you're not aware of it). Hard to say what exactly happens here without a proper backtrace.

  20. #19
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Oki, I've edited my .PRO file.

    A GDB run on "release/Listeur" returned me the same backtrace as the previous one, displayed above.

    Like my built of the application ("qmake", "make") outputs 2 executables ("release/Listeur.exe" and "debug/Listeur.exe"), I've made a GDB run on "debug/Listeur". It returned me the following backtrace :
    Qt Code:
    1. D:\Applications\Qt\4.3.1\Workspace\Listeur>gdb debug/Listeur
    2. GNU gdb 6.3
    3. Copyright 2004 Free Software Foundation, Inc.
    4. GDB is free software, covered by the GNU General Public License, and you are
    5. welcome to change it and/or distribute copies of it under certain conditions.
    6. Type "show copying" to see the conditions.
    7. There is absolutely no warranty for GDB. Type "show warranty" for details.
    8. This GDB was configured as "i686-pc-mingw32"...
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. (gdb) run
    2. Starting program: D:\Applications\Qt\4.3.1\Workspace\Listeur/debug/Listeur.exe
    To copy to clipboard, switch view to plain text mode 
    The application started correctly.

    Then, I made it crash, selected an item in my QTreeWidget :
    Qt Code:
    1. warning: ASSERT failure in QList<T>::at: "index out of range", file ../../includ
    2. e/QtCore/../../src/corelib/tools/qlist.h, line 386
    3.  
    4.  
    5. Program exited with code 01.
    To copy to clipboard, switch view to plain text mode 

    Now, I'm re-configuring and re-building Qt in debug mode only.
    See you tomorrow

  21. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    Wait, now we see you are accesing an item in a list that doesn't exist. It's probably your
    Qt Code:
    1. item_name = ((tree->selectedItems()).at(0))->text(0);
    To copy to clipboard, switch view to plain text mode 
    line. selectedItems() is probably empty. Try changing the above line to:
    Qt Code:
    1. QList<QTreeWidgetItem*> sel = tree->selectedItems();
    2. qDebug("ITEMS SELECTED: %d", sel.count());
    3.  
    4. if(!sel.isEmpty()){
    5. item_name = sel.at(0)->text(0);
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 23: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.