1
votes

Can i pass in any QWidget, in my Case a Subclass of a QTreeWidget to a Qt Slot? I need to get text from the QTreeWidget in a member function of parent. Just passing in a QString as extra argument with connect(signalMapper, SIGNAL(mapped(QString)), parent, SLOT(changePicture(QString))); works fine, but now i want to pass in a subclassed QTreeWidget ifxTreeWidget *tree = new ifxTreeWidget(); to changePicture. I changed the Signature of changePicture to take an ifxTreeWidget as argument and the mapping like:

QSignalMapper * signalMapper = new QSignalMapper(parent);

signalMapper->setMapping(tree, tree)

and tried to connect it like:

connect(signalMapper, SIGNAL(mapped(QWidget)), parent, SLOT(changePicture(ifxTreeWidget)));

connect( tree, SIGNAL(clicked(QModelIndex)), signalMapper, SLOT(map()) );

but this leaves me with:

QObject::connect: No such signal QSignalMapper::mapped(QWidget) in...

Do i need to declare a Signal? How and where (if so)?

1

1 Answers

1
votes

your connect statement is wrong. Try this

connect(signalMapper, SIGNAL(mapped(QWidget*)), parent, SLOT(changePicture(QWidget*)));

and then in the parent class

void ParentClass::changePicture(QWidget* widget)
{
  ifxTreeWidget* tree = qobject_cast<ifxTreeWidget*>(widget);
  if (tree) {
    // do something with the tree now
  }
}