[SOLVED] C# "Tag" equivalent for QT button
Unsolved
General and Desktop
-
In C# I can populate a Tag field for a push button -- for instance the button text has a description and the button tag stores a modbus address. How can I achieve a similar result in QT? What is the recommended practice?
-
You can add custom properties to your object: https://doc.qt.io/qt-5/properties.html#reading-and-writing-properties-with-the-meta-object-system
-
@Christian-Ehrlicher: Perfect!
Set value
QObject *object = ui->btnErrorCode; object->setProperty("ModbusAddress", 3054);
Retrieve value in button handler
QObject *object = sender(); QVariant vAddress = object->property("ModbusAddress"); uint16_t address = vAddress.toUInt();
-
Hi and welcome to devnet,
You can mark your thread as solved either using the "Topic Tools" button or the three dotted menu beside the answer your deem correct :-)
The title prefix was needed in a previous version of the forum.
1/4