qsignalmapper change object
-
Hello,
I have a couple of buttons connected to a signal mapper and I would like to change the object an update.
... signalMapper = new QSignalMapper(this); connect(signalMapper, SIGNAL(mapped(QObject*)), this, SLOT(on_delete_clicked(QObject*))); QPushButton *deleteButton = new QPushButton("x"); deleteButton->setObjectName("delButton1"); signalMapper->setMapping(deleteButton, obj); connect(deleteButton, SIGNAL(clicked()), signalMapper, SLOT(map())); layout->addWidget(deleteButton); ....
I tried to get the button, set the mapping (hopping that will overwrite it) and connecting the button to the signal mapper again, but no luck; I'm still getting the old object. "deleteButton" is found.
QPushButton *deleteButton = ui->mainbox_scrollArea->findChild<QPushButton *>("delButton1"); if (deleteButton) { signalMapper->setMapping(deleteButton, obj); connect(deleteButton, SIGNAL(clicked()), signalMapper, SLOT(map())); }
There is any way to do this?
Thanks -
Hi,
Can you explain what exactly you are trying to achieve ?
Because the deleteButton you get from that findChild call will be exactly the same you put there at the first place (at least from the code you gave).
-
I have a list of QHBoxLayout and each of them contains a delete button, edit button and a label.
For each button I map an object with information (title, description, ids, cat, etc) and I connect it to a signal mapper.
On edit button I open a new window, edit the information and send the new object to the MainWindow. Up to here everything works fine.
Then I want to update the object data from those buttons, so on the next edit or delete to show me the updated information and not the old information before the update. That's the reason I am getting the same button and trying to map the new object on it, hopping it will overwrite it. -
Aren't recreating some sort of QListWidget ?
-
Hi, perhaps your second call to
->setMapping()
is rejected (i.e. your overwrite is refused) because the docs say "There may be at most one object for each sender".
Try callingremoveMappings()
or maybe easier, consider creating a new QSignalMapper object.