Question

i have a qtreewidget with checkable item, i can check and uncheck element, i want to check if item is checked or not, i use connect but my slot is not called, i add break point in my slot but i never reach it, i connect like this :

 connect(_events, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(eventChecked(QWidgetItem*,int)));
    connect(_player, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(playerChecked(QWidgetItem*,int)));

i used both itemClicked and itemChanged but my slots never called, my slot is :

    playerChecked(QTreeWidgetItem *item, int i)
    {
        if(item->checkState(i) == Qt::Checked) {
            std::cout << "reached here" << std::endl;
        } else {
            operators->printAllowedPlayers();
        }
}
Was it helpful?

Solution

i use connect but my slot is not called, i add break point in my slot but i never reach it

There are a couple of things that can be done in such cases to pin the issue down:

  • Check the console output to see if there are any complaints.

  • See if the connect statement is called.

  • Check the return value of the connect statement whether the connection was made successfully.

In this special case, the issue is matching parameters because you have this for the connect statement:

SLOT(playerChecked(QWidgetItem*,int))

whereas you have this slot declaration:

playerChecked(QTreeWidgetItem *item, int i)

You can see the mix of QWidgetItem and QTreeWidgetItem. This probably applies to the eventChecked slot, too. You need to make them matching, probably by passing QTreeWidgetItem* to the slot, especially since that is what the signal also contains that the slot is connected to. This would be the solution, respectively:

 connect(_events, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(eventChecked(QTreeWidgetItem*,int)));
 connect(_player, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(playerChecked(QTreeWidgetItem*,int)));

Personally, I would even drop the this parameter as it is implicit. That makes the lines somewhat shorter without making it less comprehensive.

Furthermore, your slot definition does not seem to contain the return value. You would need to add the void in there. You should get a compilation error due to that.

OTHER TIPS

i made mistake because in connect statement i used Qwidgetitem not qtreewidgetitem

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top