PDA

View Full Version : QTreeView expand signals



Vidar Bøe
22nd May 2008, 07:23
Working with QTreeView I've run into a problem related to the expanded signal. It seems that the very first time I select a file in the directory structure, expanded emits three signals, that is, one related to the selected file itself, and two aditional which seems to be the equivalent of the unix . and ..

This only happens the first time I select a file. If a directory is selected only one signal is emitted......
Can expand be configured to emit one signal only?


Thanks,
Vidar

jpn
22nd May 2008, 15:03
Which exact version of Qt are you using? I can't reproduce the problem with Qt 4.4.0.

Vidar Bøe
26th May 2008, 09:47
Hi,

I'm using version 4.3.1. Included are some sourcecode for convenience:
The undelined connect is the one who trigger the signal.

QObject::connect(treeView, SIGNAL(expanded(QModelIndex)), this, SLOT(resizeColumn_tw()));
QObject::connect(treeView, SIGNAL(expanded(QModelIndex)), this, SLOT(getDirName_fs(QModelIndex)));
QObject::connect(treeView, SIGNAL(collapsed(QModelIndex)), this, SLOT(resizeColumn_tw()));
QObject::connect(treeView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(resizeColumn_tw()));
QObject::connect(treeView, SIGNAL(clicked(QModelIndex)), this, SLOT(openMd5File(QModelIndex)));

QObject::connect(treeView_2, SIGNAL(expanded(QModelIndex)), this, SLOT(resizeColumn_tw2()));
QObject::connect(treeView_2, SIGNAL(expanded(QModelIndex)), this, SLOT(finnOppdrag(QModelIndex)));
QObject::connect(treeView_2, SIGNAL(collapsed(QModelIndex)), this, SLOT(resizeColumn_tw2()));
QObject::connect(treeView_2, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(resizeColumn_tw2()));
QObject::connect(treeView_2, SIGNAL(clicked(QModelIndex)), this, SLOT(finnOppdrag(QModelIndex)));

QObject::connect(pushButton_2, SIGNAL(clicked()), this, SLOT(showAllFiles_tw()));
QObject::connect(pushButton_2, SIGNAL(clicked()), this, SLOT(resizeColumn_tw()));
QObject::connect(pushButton, SIGNAL(clicked()), this, SLOT(findFileNames()));
QObject::connect(pushButton_lagre, SIGNAL(clicked()), this, SLOT(writeSettings()));
QObject::connect(pushButton_avbryt, SIGNAL(clicked()), this, SLOT(restoreSettings()));

QObject::connect(pushButton_hent, SIGNAL(clicked()), this, SLOT(getArchive()));
QObject::connect(calendarWidget, SIGNAL(selectionChanged()), this, SLOT(setDate()));
QObject::connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableViewButton()));
QObject::connect(radioButton, SIGNAL(toggled(bool)), this, SLOT(enableHentButton()));
QObject::connect(radioButton_2, SIGNAL(toggled(bool)), this, SLOT(enableHentButton()));
QObject::connect(pushButton_avbrytHent, SIGNAL(clicked()), this, SLOT(avbrytHent()));
QObject::connect(pushButton_sok, SIGNAL(clicked()), this, SLOT(sokMd5()));
QObject::connect(pushButton_hent_2, SIGNAL(clicked()), this, SLOT(archive()));


Calling showAllFiles_tw function to restore the tree-view, actually make the problem reappear for the first file selected:

/// Retrieve the original directory: /archive
void Tarkiv::showAllFiles_tw()
{
model->setReadOnly(true);
treeView->setModel(model);
treeView->setRootIndex(model->index(lineEdit_katalog->text()));
treeView->hideColumn(2);
current_model = model;
}