PDA

View Full Version : QTreeWidget fails to emit itemClicked signal.



avh
5th June 2008, 21:38
I am attempting to control a QStackedWidget with a QTreeWidget.
Both are initialized in the constructor of my class.

To do so, I use the following code:



//optionLabels is a QTreeWidget*
//optionControls is a QStackedWidget*

void EditOptionsDialog::makeConnections() {
connect(optionLabels, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(changeCollectionPane(QTreeWidgetItem*, int)));
}

//This is defined as a slot in the header file
void EditOptionsDialog::changeCollectionPane(QTreeWidge tItem* selection, int col) {
QMessageBox::information(this, tr("Is this slot called?"), tr("Index of Clicked Widget: %1").arg(selection->data(col, Qt::UserRole).toInt()));
if(selection && col == 0) {
optionControls->setCurrentIndex(selection->data(col, Qt::UserRole).toInt());
}
}


When I click around on the tree, I don't get a message box, so the slot is not being called. Any ideas as to why?

jpn
6th June 2008, 10:25
Did you remember do declared changeCollectionPane as a slot? Does the declaration of EditOptionsDialog contain required Q_OBJECT macro? Check the debug output for a detailed reason why QObject::connect() fails.

avh
6th June 2008, 18:49
Thanks; I forgot that the Q_OBJECT macro still has to go in subclasses of standard Qt classes.