Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] C# "Tag" equivalent for QT button
QtWS25 Last Chance

[SOLVED] C# "Tag" equivalent for QT button

Scheduled Pinned Locked Moved Unsolved General and Desktop
pushbutton
4 Posts 3 Posters 552 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vincenzo.pappano
    wrote on 29 Aug 2021, 14:29 last edited by vincenzo.pappano
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 29 Aug 2021, 14:34 last edited by
      #2

      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

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      V 1 Reply Last reply 29 Aug 2021, 14:58
      4
      • C Christian Ehrlicher
        29 Aug 2021, 14:34

        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

        V Offline
        V Offline
        vincenzo.pappano
        wrote on 29 Aug 2021, 14:58 last edited by
        #3

        @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();
        
        1 Reply Last reply
        3
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 29 Aug 2021, 18:00 last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          4/4

          29 Aug 2021, 18:00

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved