QPushButton *myButton = new QPushButton("Click me", parent); myButton->setObjectName("myButton"); QString buttonName = myButton->objectName();
QPushButton *myButton = new QPushButton("Click me", parent); myButton->setObjectName("myButton"); connect(myButton, &QPushButton::clicked, this, [this]() { if (myButton->objectName() == "myButton") { qDebug() << "Button clicked!"; } });In this example, we create a new QPushButton with the label "Click me", and set its objectName to "myButton". We then connect the button's clicked signal to a lambda function that checks if the button's objectName is "myButton". If it is, it prints "Button clicked!" to the debug console. Package library: Qt Widgets Library.