Précédent   Forum du club des développeurs et IT Pro > C et C++ > Bibliothèques > Qt
Qt Forum d'entraide technique sur la bibliothèque Qt. Avant de poster -> F.A.Q Qt
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 05/12/2012, 12h47   #1
Neckara
Rédacteur
 
Avatar de Neckara
 
Homme Denis
Étudiant
Inscription : décembre 2011
Messages : 2 612
Détails du profil
Informations personnelles :
Nom : Homme Denis
Localisation : France, Loire (Rhône Alpes)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : décembre 2011
Messages : 2 612
Points : 7 162
Points : 7 162
Envoyer un message via MSN à Neckara Envoyer un message via Skype™ à Neckara
Par défaut QListView et filtre : résultat incohérent

Bonjour,

Je bloque depuis plus d'une semaine sur un petit bug.
J'ai un QTreeView qui affiche des dossiers et lorsqu'on double-clique sur un dossier, la liste des fichiers contenu dans celui-ci s'affiche dans un QListView.
Malheureusement, il n'affiche pas uniquement les fichiers mais aussi les dossiers déjà parcourus contenu dans le dossier sélectionné.

Exemple : je vais dans /home, /cdrom puis je reviens dans / et /home et /cdrom s'affichent dans le QListView alors qu'ils ne devraient pas malgrès la présence d'un : modelFile.setFilter( QDir::Files); sur le modèle.

Voici mon code minimal :
Code main.cpp :
1
2
3
4
5
6
7
8
9
10
11
#include <QtGui/QApplication>
#include "mainwindow.h"
 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
 
    return a.exec();
}


Code mainwindows.h :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
#include <QFileSystemModel>
 
 
namespace Ui {
class MainWindow;
}
 
class MainWindow : public QMainWindow
{
    Q_OBJECT
 
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
 
private:
    Ui::MainWindow *ui;
    QFileSystemModel model;
    QFileSystemModel modelFile;
 
public slots :
    void changeDirectory(const QModelIndex & index);
};
 
#endif // MAINWINDOW_H

Code mainwindows.cpp :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
 
#include "mainwindow.h"
#include "ui_mainwindow.h"
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
	ui->setupUi(this);
 
	model.setRootPath(QDir::currentPath());
	model.setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);
	modelFile.setFilter( QDir::Files);
	modelFile.setRootPath(QDir::currentPath());
 
	ui->ArborescenceDossier->setModel(&model); //QTreeView
	ui->ArborescenceDossier->setColumnHidden(1, true);
	ui->ArborescenceDossier->setColumnHidden(2, true);
	ui->ArborescenceDossier->setColumnHidden(3, true);
 
	ui->listFichier->setModel(&modelFile); //QListView
	ui->ArborescenceDossier->disconnect(SIGNAL(doubleClicked(QModelIndex)));
	connect(ui->ArborescenceDossier, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(changeDirectory(QModelIndex)));
}
 
MainWindow::~MainWindow()
{
    	delete ui;
}
 
void MainWindow::changeDirectory(const QModelIndex & index)
{
	std::cerr << model.filePath(index).toStdString() << std::endl;
	modelFile.setRootPath( model.filePath(index)) ;
	ui->listFichier->setRootIndex( modelFile.index(model.filePath(index)) );
	std::cerr << modelFile.filter() << std::endl; //affiche 2
	std::cerr << (QDir::Files ) << std::endl; //affiche 2
}
Code mainwindows.ui :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>600</width>
    <height>407</height>
   </rect>
  </property>
  <property name="minimumSize">
   <size>
    <width>600</width>
    <height>400</height>
   </size>
  </property>
  <property name="windowTitle">
   <string>JukeBox</string>
  </property>
  <widget class="QWidget" name="centralWidget">
   <layout class="QHBoxLayout" name="horizontalLayout">
    <item>
     <layout class="QVBoxLayout" name="verticalLayout"/>
    </item>
    <item>
     <widget class="QTabWidget" name="Telecharger">
      <property name="sizePolicy">
       <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
        <horstretch>1</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
      <property name="currentIndex">
       <number>2</number>
      </property>
      <widget class="QWidget" name="tab_2">
       <attribute name="title">
        <string>Tab 2</string>
       </attribute>
       <widget class="QGroupBox" name="groupBox_3">
        <property name="geometry">
         <rect>
          <x>0</x>
          <y>0</y>
          <width>551</width>
          <height>500</height>
         </rect>
        </property>
        <property name="title">
         <string>Piste de lecture</string>
        </property>
        <widget class="QScrollArea" name="scrollArea">
         <property name="geometry">
          <rect>
           <x>0</x>
           <y>20</y>
           <width>171</width>
           <height>181</height>
          </rect>
         </property>
         <property name="widgetResizable">
          <bool>true</bool>
         </property>
         <widget class="QWidget" name="scrollAreaWidgetContents">
          <property name="geometry">
           <rect>
            <x>0</x>
            <y>0</y>
            <width>169</width>
            <height>179</height>
           </rect>
          </property>
          <widget class="QListView" name="listView">
           <property name="geometry">
            <rect>
             <x>20</x>
             <y>0</y>
             <width>151</width>
             <height>171</height>
            </rect>
           </property>
          </widget>
         </widget>
        </widget>
        <widget class="QLabel" name="label">
         <property name="geometry">
          <rect>
           <x>180</x>
           <y>10</y>
           <width>311</width>
           <height>181</height>
          </rect>
         </property>
         <property name="text">
          <string>Info titre</string>
         </property>
        </widget>
        <widget class="Phonon::SeekSlider" name="seekSlider">
         <property name="geometry">
          <rect>
           <x>0</x>
           <y>200</y>
           <width>501</width>
           <height>29</height>
          </rect>
         </property>
        </widget>
       </widget>
       <widget class="QGroupBox" name="groupBox">
        <property name="geometry">
         <rect>
          <x>0</x>
          <y>220</y>
          <width>551</width>
          <height>91</height>
         </rect>
        </property>
        <property name="title">
         <string>Parametres</string>
        </property>
        <widget class="QLabel" name="label_2">
         <property name="geometry">
          <rect>
           <x>180</x>
           <y>60</y>
           <width>66</width>
           <height>17</height>
          </rect>
         </property>
         <property name="text">
          <string>Son</string>
         </property>
        </widget>
        <widget class="QPushButton" name="pushButton_3">
         <property name="geometry">
          <rect>
           <x>260</x>
           <y>30</y>
           <width>121</width>
           <height>27</height>
          </rect>
         </property>
         <property name="text">
          <string>Vider la playlist</string>
         </property>
        </widget>
        <widget class="QPushButton" name="pushButton_5">
         <property name="geometry">
          <rect>
           <x>410</x>
           <y>20</y>
           <width>98</width>
           <height>27</height>
          </rect>
         </property>
         <property name="text">
          <string>SauverPlaylist</string>
         </property>
        </widget>
        <widget class="QPushButton" name="play">
         <property name="geometry">
          <rect>
           <x>10</x>
           <y>30</y>
           <width>98</width>
           <height>27</height>
          </rect>
         </property>
         <property name="text">
          <string>Start/Pause</string>
         </property>
        </widget>
        <widget class="Phonon::VolumeSlider" name="volumeSonore">
         <property name="geometry">
          <rect>
           <x>220</x>
           <y>60</y>
           <width>271</width>
           <height>29</height>
          </rect>
         </property>
        </widget>
       </widget>
      </widget>
      <widget class="QWidget" name="tab_3">
       <attribute name="title">
        <string>Page</string>
       </attribute>
       <widget class="QGroupBox" name="groupBox_2">
        <property name="geometry">
         <rect>
          <x>0</x>
          <y>0</y>
          <width>531</width>
          <height>301</height>
         </rect>
        </property>
        <property name="title">
         <string>Playlist</string>
        </property>
        <widget class="QListView" name="listView_2">
         <property name="geometry">
          <rect>
           <x>200</x>
           <y>20</y>
           <width>181</width>
           <height>241</height>
          </rect>
         </property>
        </widget>
        <widget class="QPushButton" name="pushButton">
         <property name="geometry">
          <rect>
           <x>100</x>
           <y>270</y>
           <width>98</width>
           <height>27</height>
          </rect>
         </property>
         <property name="text">
          <string>Charger</string>
         </property>
        </widget>
        <widget class="QPushButton" name="pushButton_4">
         <property name="geometry">
          <rect>
           <x>0</x>
           <y>270</y>
           <width>98</width>
           <height>27</height>
          </rect>
         </property>
         <property name="text">
          <string>Supprimer</string>
         </property>
        </widget>
        <widget class="QPushButton" name="pushButton_2">
         <property name="geometry">
          <rect>
           <x>200</x>
           <y>270</y>
           <width>98</width>
           <height>27</height>
          </rect>
         </property>
         <property name="text">
          <string>Inclure</string>
         </property>
        </widget>
        <widget class="QTreeView" name="treeView_2">
         <property name="geometry">
          <rect>
           <x>0</x>
           <y>20</y>
           <width>201</width>
           <height>241</height>
          </rect>
         </property>
        </widget>
        <widget class="QPushButton" name="pushButton_7">
         <property name="geometry">
          <rect>
           <x>310</x>
           <y>270</y>
           <width>98</width>
           <height>27</height>
          </rect>
         </property>
         <property name="text">
          <string>Sauvegarder</string>
         </property>
        </widget>
        <widget class="QPushButton" name="pushButton_8">
         <property name="geometry">
          <rect>
           <x>410</x>
           <y>270</y>
           <width>98</width>
           <height>27</height>
          </rect>
         </property>
         <property name="text">
          <string>Nouveau</string>
         </property>
        </widget>
        <widget class="QListView" name="listView_3">
         <property name="geometry">
          <rect>
           <x>380</x>
           <y>20</y>
           <width>141</width>
           <height>241</height>
          </rect>
         </property>
        </widget>
       </widget>
      </widget>
      <widget class="QWidget" name="tab_4">
       <attribute name="title">
        <string>Page</string>
       </attribute>
       <widget class="QGroupBox" name="groupBox_4">
        <property name="geometry">
         <rect>
          <x>0</x>
          <y>10</y>
          <width>551</width>
          <height>301</height>
         </rect>
        </property>
        <property name="title">
         <string>Arborescence fichier</string>
        </property>
        <widget class="QTreeView" name="ArborescenceDossier">
         <property name="geometry">
          <rect>
           <x>0</x>
           <y>20</y>
           <width>231</width>
           <height>281</height>
          </rect>
         </property>
        </widget>
        <widget class="QListView" name="listView_5">
         <property name="geometry">
          <rect>
           <x>410</x>
           <y>20</y>
           <width>131</width>
           <height>281</height>
          </rect>
         </property>
        </widget>
        <widget class="QListView" name="listFichier">
         <property name="geometry">
          <rect>
           <x>235</x>
           <y>20</y>
           <width>181</width>
           <height>281</height>
          </rect>
         </property>
        </widget>
       </widget>
      </widget>
      <widget class="QWidget" name="tab_5">
       <attribute name="title">
        <string>Page</string>
       </attribute>
       <widget class="QGroupBox" name="groupBox_5">
        <property name="geometry">
         <rect>
          <x>10</x>
          <y>20</y>
          <width>541</width>
          <height>51</height>
         </rect>
        </property>
        <property name="title">
         <string>Télécharger une musique Youtube</string>
        </property>
        <widget class="QTextEdit" name="textEdit">
         <property name="geometry">
          <rect>
           <x>10</x>
           <y>20</y>
           <width>301</width>
           <height>21</height>
          </rect>
         </property>
         <property name="html">
          <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name="qrichtext" content="1" /&gt;&lt;style type="text/css"&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"&gt;
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"&gt;url&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
         </property>
        </widget>
        <widget class="QTextEdit" name="textEdit_2">
         <property name="geometry">
          <rect>
           <x>310</x>
           <y>20</y>
           <width>111</width>
           <height>21</height>
          </rect>
         </property>
         <property name="html">
          <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name="qrichtext" content="1" /&gt;&lt;style type="text/css"&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"&gt;
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"&gt;nom&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
         </property>
        </widget>
        <widget class="QPushButton" name="pushButton_6">
         <property name="geometry">
          <rect>
           <x>430</x>
           <y>10</y>
           <width>98</width>
           <height>27</height>
          </rect>
         </property>
         <property name="text">
          <string>Charger</string>
         </property>
        </widget>
        <widget class="QWidget" name="gridLayoutWidget">
         <property name="geometry">
          <rect>
           <x>30</x>
           <y>-90</y>
           <width>561</width>
           <height>361</height>
          </rect>
         </property>
         <layout class="QGridLayout" name="gridLayout_3"/>
        </widget>
       </widget>
      </widget>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menuBar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>600</width>
     <height>25</height>
    </rect>
   </property>
   <widget class="QMenu" name="menuFichier">
    <property name="title">
     <string>Fichier</string>
    </property>
    <addaction name="actionD_finir_dossier_de_playlist"/>
    <addaction name="actionD_finir_dossier_de_sons_Youtube"/>
    <addaction name="separator"/>
    <addaction name="actionExporter_liste_de_playlist"/>
    <addaction name="actionExporter_sons"/>
    <addaction name="actionExporter_playlist_et_son"/>
    <addaction name="separator"/>
    <addaction name="actionImporter_liste_de_playlist"/>
    <addaction name="actionOo"/>
    <addaction name="actionCharger_playlist_et_son"/>
    <addaction name="separator"/>
    <addaction name="actionSupprimer_sons_sans_playlist"/>
    <addaction name="separator"/>
    <addaction name="actionQuitter"/>
   </widget>
   <widget class="QMenu" name="menuAide">
    <property name="title">
     <string>Aide</string>
    </property>
    <addaction name="actionA_propos"/>
    <addaction name="actionDocumentation"/>
   </widget>
   <addaction name="menuFichier"/>
   <addaction name="menuAide"/>
  </widget>
  <widget class="QStatusBar" name="statusBar"/>
  <action name="actionQuitter">
   <property name="text">
    <string>Quitter</string>
   </property>
  </action>
  <action name="actionD_finir_dossier_de_playlist">
   <property name="text">
    <string>Définir dossier de playlist</string>
   </property>
  </action>
  <action name="actionD_finir_dossier_de_sons_Youtube">
   <property name="text">
    <string>Définir dossier de sons</string>
   </property>
  </action>
  <action name="actionExporter_liste_de_playlist">
   <property name="text">
    <string>Exporter liste de playlist</string>
   </property>
  </action>
  <action name="actionExporter_sons">
   <property name="text">
    <string>Exporter sons</string>
   </property>
  </action>
  <action name="actionImporter_liste_de_playlist">
   <property name="text">
    <string>Importer liste de playlist</string>
   </property>
  </action>
  <action name="actionOo">
   <property name="text">
    <string>Importer sons</string>
   </property>
  </action>
  <action name="actionExporter_playlist_et_son">
   <property name="text">
    <string>Exporter playlist et son</string>
   </property>
  </action>
  <action name="actionCharger_playlist_et_son">
   <property name="text">
    <string>Importer playlist et son</string>
   </property>
  </action>
  <action name="actionSupprimer_sons_sans_playlist">
   <property name="text">
    <string>Supprimer sons sans playlist</string>
   </property>
  </action>
  <action name="actionA_propos">
   <property name="text">
    <string>A propos</string>
   </property>
  </action>
  <action name="actionDocumentation">
   <property name="text">
    <string>Documentation</string>
   </property>
  </action>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <customwidgets>
  <customwidget>
   <class>Phonon::SeekSlider</class>
   <extends>QWidget</extends>
   <header location="global">phonon/seekslider.h</header>
  </customwidget>
  <customwidget>
   <class>Phonon::VolumeSlider</class>
   <extends>QWidget</extends>
   <header location="global">phonon/volumeslider.h</header>
  </customwidget>
 </customwidgets>
 <resources/>
 <connections/>
</ui>

NB : J'utilise Qt Creator 2.4.1 Basé sur Qt 4.8.0 (64 bit) sous Ubuntu LTS 12.04.
__________________
Recherche devs C++ motivés et sérieux pour Last Dungeon.

Chaîne Youtube : Vidéos

Ma page DVP : http://neckara.developpez.com/
Neckara est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/12/2012, 15h48   #2
LittleWhite
Responsable 2D/3D/Jeux


 
Avatar de LittleWhite
 
Homme Alexandre Laurent
Ingénieur développement logiciels
Inscription : mai 2008
Messages : 10 467
Détails du profil
Informations personnelles :
Nom : Homme Alexandre Laurent
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : mai 2008
Messages : 10 467
Points : 40 427
Points : 40 427
Bonjour,

Ne suffit-il pas de vider la liste (le modèle) avant de continuer à la remplir ?
__________________
Vous souhaitez participer à la rubrique 2D / 3D / Jeux ? Contactez-moi
La rubrique a aussi un blog !

Ma page sur DVP
Mon Portfolio

Qui connaît l'erreur, connaît la solution.
LittleWhite est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/12/2012, 17h55   #3
Neckara
Rédacteur
 
Avatar de Neckara
 
Homme Denis
Étudiant
Inscription : décembre 2011
Messages : 2 612
Détails du profil
Informations personnelles :
Nom : Homme Denis
Localisation : France, Loire (Rhône Alpes)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : décembre 2011
Messages : 2 612
Points : 7 162
Points : 7 162
Envoyer un message via MSN à Neckara Envoyer un message via Skype™ à Neckara
Bonjour,

Merci pour ton aide mais malheureusement ta solution ne marche pas.
J'ai mis :
Code :
modelFile.removeRows(0 , modelFile.rowCount() );
dans changeDirectory mais sans grand succès.
__________________
Recherche devs C++ motivés et sérieux pour Last Dungeon.

Chaîne Youtube : Vidéos

Ma page DVP : http://neckara.developpez.com/
Neckara est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/12/2012, 01h14   #4
koala01
Modérateur
 
Avatar de koala01
 
Philippe Dunski
Inscription : octobre 2004
Messages : 8 626
Détails du profil
Informations personnelles :
Nom : Philippe Dunski
Âge : 41

Informations forums :
Inscription : octobre 2004
Messages : 8 626
Points : 13 346
Points : 13 346
Envoyer un message via MSN à koala01 Envoyer un message via Skype™ à koala01
Salut,

Et si, au lieu d'avoir un modèle comme membre, tu en faisais une variable locale, qui serait donc détruite à chaque fois que tu sors de la fonction

Au moins, tu serais sur de partir sur un model dans lequel il ne reste aucune "crasse"

Si cela ne suffit pas, tu pourrais toujours tenter de forcer l'appel à update() en passant le modèleindex adéquat
__________________
A méditer: La solution la plus simple est toujours la moins compliquée
Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
Compiler Gcc sous windows avec MinGW
je ne répondrai à aucune question technique par E-mail, message visiteur ou message privé
Vous avez obtenu votre réponse pensez au bouton en bas de page
koala01 est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 07/12/2012, 06h37   #5
Neckara
Rédacteur
 
Avatar de Neckara
 
Homme Denis
Étudiant
Inscription : décembre 2011
Messages : 2 612
Détails du profil
Informations personnelles :
Nom : Homme Denis
Localisation : France, Loire (Rhône Alpes)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : décembre 2011
Messages : 2 612
Points : 7 162
Points : 7 162
Envoyer un message via MSN à Neckara Envoyer un message via Skype™ à Neckara
Citation:
Envoyé par koala01 Voir le message
Salut,

Et si, au lieu d'avoir un modèle comme membre, tu en faisais une variable locale, qui serait donc détruite à chaque fois que tu sors de la fonction

Au moins, tu serais sur de partir sur un model dans lequel il ne reste aucune "crasse"
J'ai mis :
Code :
1
2
3
4
5
    QFileSystemModel modelFile;
 
     modelFile.setRootPath( model.filePath(index)) ;
     modelFile.setFilter(QDir::Files);
     ui->listFichier->setModel(&modelFile);
Mais plus rien n'apparaît.

Citation:
Envoyé par koala01 Voir le message
Si cela ne suffit pas, tu pourrais toujours tenter de forcer l'appel à update() en passant le modèleindex adéquat
Code :
1
2
3
4
5
     modelFile.setRootPath( model.filePath(index)) ;
     modelFile.setFilter(QDir::Files);
     ui->listFichier->setModel(&modelFile);
     ui->listFichier->setRootIndex( modelFile.index(model.filePath(index)) );
     ui->listFichier->update( modelFile.index(model.filePath(index)) );
Ne fait rien de nouveau.

Merci pour tes idées.
__________________
Recherche devs C++ motivés et sérieux pour Last Dungeon.

Chaîne Youtube : Vidéos

Ma page DVP : http://neckara.developpez.com/
Neckara est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/12/2012, 13h18   #6
Neckara
Rédacteur
 
Avatar de Neckara
 
Homme Denis
Étudiant
Inscription : décembre 2011
Messages : 2 612
Détails du profil
Informations personnelles :
Nom : Homme Denis
Localisation : France, Loire (Rhône Alpes)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : décembre 2011
Messages : 2 612
Points : 7 162
Points : 7 162
Envoyer un message via MSN à Neckara Envoyer un message via Skype™ à Neckara
Citation:
Envoyé par koala01 Voir le message
Salut,

Et si, au lieu d'avoir un modèle comme membre, tu en faisais une variable locale, qui serait donc détruite à chaque fois que tu sors de la fonction

Au moins, tu serais sur de partir sur un model dans lequel il ne reste aucune "crasse"
Tu étais vraiment pas loin de la solution :
Au lieu d'utiliser une variable locale, détruite à la fin de la fonction vidant alors le QListView, j'utilise une variable allouée avec new que je détruit et reconstruit à chaque appel de la fonction

Code :
1
2
3
4
5
6
7
8
9
    delete modelFile;
    modelFile = new QFileSystemModel;
 
 
     modelFile->setFilter( QDir::Files);
     modelFile->setRootPath( model.filePath(index) );
 
     ui->listFichier->setModel(modelFile);
     ui->listFichier->setRootIndex( modelFile->index(model.filePath(index)) );
Merci pour votre aide, même si je n'ai toujours pas compris ce qu'il se passait
__________________
Recherche devs C++ motivés et sérieux pour Last Dungeon.

Chaîne Youtube : Vidéos

Ma page DVP : http://neckara.developpez.com/
Neckara est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/12/2012, 15h07   #7
saad.hessane
Membre éprouvé
 
Avatar de saad.hessane
 
Homme Saâd Hessane
Ingénieur développement logiciels
Inscription : avril 2008
Messages : 302
Détails du profil
Informations personnelles :
Nom : Homme Saâd Hessane
Localisation : France, Paris (Île de France)

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : avril 2008
Messages : 302
Points : 436
Points : 436
Je ne sais pas si ton problème est résolue. Effectivement le model est recréé, mais il il y a quelque chose qui cloche.
Le fait que le modèle affiche des dossiers bien que les filtres soit activer me perturbe.
Mais après lecture de la doc et une petite relecture du code de la classe QFileSystemModel, j'ai peut être un début de réponse.
QFileSystemModel utilise QFileSystemWatcher pour surveiller les modifications dans le système de fichier. Quand tu fais setRootPath(path), ce path est ajouté à l'objet QFileSystemWatcher.
Quand tu remontes l'arborescence, l'objet QFileSystemWatcher surveille les fichiers du dossier actuel, mais aussi les fichiers du dossier d'avant. Mais vu que tu affiches le model dans une qlistview, il n'affiche que le premier niveau : les fichiers du dossier courant, et les dossiers contenant des fichiers qui ont été ajouter au QFileSystemWatcher.
Tu peux t'en rendre compte en remplaçant la QListView par une QTreeView.
C'est pas facile à expliquer, j’essaierai d'aller plus loin dans les tests ce soir pour confirmer mon hypothèse.
saad.hessane est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 07/12/2012, 15h36   #8
Neckara
Rédacteur
 
Avatar de Neckara
 
Homme Denis
Étudiant
Inscription : décembre 2011
Messages : 2 612
Détails du profil
Informations personnelles :
Nom : Homme Denis
Localisation : France, Loire (Rhône Alpes)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : décembre 2011
Messages : 2 612
Points : 7 162
Points : 7 162
Envoyer un message via MSN à Neckara Envoyer un message via Skype™ à Neckara
Si je comprend bien :

Je suis dans / :
Il surveille alors les fichiers contenus dans / ainsi que / au cas où d'autres fichiers seraient ajoutés.
Fichiers surveillés :
Code :
1
2
3
4
0         1
/
         fichier1
         fichier2

Je vais dans /home :
Il surveille en plus des fichiers précedants les fichiers contenus dans /home ainsi que /home au cas où d'autres fichiers seraient ajoutés.
Fichiers surveillés :
Code :
1
2
3
4
5
6
7
0         1         2
/
         fichier1
         fichier2
         /home
                       fichier3
                       fichier4
Donc si je reviens dans /, il affichera tous les fichiers surveillés dans / soit fichier1, fichier2 et /home.

C'est donc un bug de Qt ?
Il faudrait donc chercher un moyen de vider le QFileSystemWatcher avant de changer le dossier où on va.
__________________
Recherche devs C++ motivés et sérieux pour Last Dungeon.

Chaîne Youtube : Vidéos

Ma page DVP : http://neckara.developpez.com/
Neckara est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/12/2012, 16h05   #9
saad.hessane
Membre éprouvé
 
Avatar de saad.hessane
 
Homme Saâd Hessane
Ingénieur développement logiciels
Inscription : avril 2008
Messages : 302
Détails du profil
Informations personnelles :
Nom : Homme Saâd Hessane
Localisation : France, Paris (Île de France)

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : avril 2008
Messages : 302
Points : 436
Points : 436
Citation:
Envoyé par Neckara Voir le message
Si je comprend bien :

Je suis dans / :
Il surveille alors les fichiers contenus dans / ainsi que / au cas où d'autres fichiers seraient ajoutés.
Fichiers surveillés :
Code :
1
2
3
4
0         1
/
         fichier1
         fichier2

Je vais dans /home :
Il surveille en plus des fichiers précedants les fichiers contenus dans /home ainsi que /home au cas où d'autres fichiers seraient ajoutés.
Fichiers surveillés :
Code :
1
2
3
4
5
6
7
0         1         2
/
         fichier1
         fichier2
         /home
                       fichier3
                       fichier4
Donc si je reviens dans /, il affichera tous les fichiers surveillés dans / soit fichier1, fichier2 et /home.
C'est effectivement ce que je pense. La doc :
Citation:
Envoyé par Doc Qt
QModelIndex QFileSystemModel::setRootPath ( const QString & newPath )
Sets the directory that is being watched by the model to newPath by installing a file system watcher on it. Any changes to files and directories within this directory will be reflected in the model.
Le problème n’apparaît naturellement pas si le filtre QDir:: Dirs est activé.
Citation:
Envoyé par Neckara Voir le message
C'est donc un bug de Qt ?
Pour l'instant ça n'est qu'une hypothèse, je parle de problème et ne veux pas m'avancer à dire que c'est un bug. Le problème apparaît sur Windows 64bits avec Qt 4.8, et Debian avec Qt 4.4 dans mon cas.
Citation:
Envoyé par Neckara Voir le message
Il faudrait donc chercher un moyen de vider le QFileSystemWatcher avant de changer le dossier où on va.
QFileSystemModel utilise QFileSystemWatcher à la fois comme un cache de données et pour garder le modèle cohérent avec le système de fichiers. Tu n'y as malheureusement (ou heureusement) pas accès.
saad.hessane est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/12/2012, 16h26   #10
saad.hessane
Membre éprouvé
 
Avatar de saad.hessane
 
Homme Saâd Hessane
Ingénieur développement logiciels
Inscription : avril 2008
Messages : 302
Détails du profil
Informations personnelles :
Nom : Homme Saâd Hessane
Localisation : France, Paris (Île de France)

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : avril 2008
Messages : 302
Points : 436
Points : 436
Pas besoin de confirmation. C'est un problème connue. Plusieurs tickets sont créés pour rapporter le problème. L'un d'eux :
https://bugreports.qt-project.org/browse/QTBUG-8632
[EDIT]https://bugreports.qt-project.org/browse/QTBUG-9811
Une solution serait de faire :
Code C++ :
1
2
3
4
5
6
void MainWindow::changeDirectory(const QModelIndex & index)
{
	modelFile.setRootPath( model.filePath(index)) ;
	ui->listFichier->setRootIndex( modelFile.index(model.filePath(index)) );
	modelFile.setNameFilters(QStringList());
}
Source de la solution et explication : http://qt-project.org/forums/viewthread/7265
saad.hessane est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 00h23.


 
 
 
 
Partenaires

Hébergement Web