I have added a set of pushbuttons inside a QScrollarea dynamically , but I want to get the text of that particular button either by click or touch.
button = new QPushButton("someText");
button->setParent(ui->scrollArea);
button->setCheckable(true);
button->show();
I used button->text(); and button->currentText();. But it gives the text of the last added pushbutton, but not the clicked button.
G.M. said:
One way to get any
QPushButton's text when clicked, is to connect itsclicked()slot to a lambda that stores button text, in aQStringfor example:qDebugis just there to confirm that the button's text has been stored inbuttonText, for debugging purposes.