Results 1 to 3 of 3

Thread: QTreeWidget fails to emit itemClicked signal.

  1. #1
    Join Date
    May 2008
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeWidget fails to emit itemClicked signal.

    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:

    Qt Code:
    1. //optionLabels is a QTreeWidget*
    2. //optionControls is a QStackedWidget*
    3.  
    4. void EditOptionsDialog::makeConnections() {
    5. connect(optionLabels, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(changeCollectionPane(QTreeWidgetItem*, int)));
    6. }
    7.  
    8. //This is defined as a slot in the header file
    9. void EditOptionsDialog::changeCollectionPane(QTreeWidgetItem* selection, int col) {
    10. QMessageBox::information(this, tr("Is this slot called?"), tr("Index of Clicked Widget: %1").arg(selection->data(col, Qt::UserRole).toInt()));
    11. if(selection && col == 0) {
    12. optionControls->setCurrentIndex(selection->data(col, Qt::UserRole).toInt());
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    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?

  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 fails to emit itemClicked signal.

    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.
    J-P Nurmi

  3. #3
    Join Date
    May 2008
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget fails to emit itemClicked signal.

    Thanks; I forgot that the Q_OBJECT macro still has to go in subclasses of standard Qt classes.

Similar Threads

  1. how to know which button emit the signal?
    By coder1985 in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2008, 15:26

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.