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. Looking for suggestions or hints on best way to...

Looking for suggestions or hints on best way to...

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 630 Views 3 Watching
  • 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I'm implementing classes which are derived from Qt controls and I need to implement a way of saving an original state of say for example QCheckBox or QComboBox etc.

    The checkbox is easy enough I could just save a boolean value and compare if later, but I'm looking for something more generic.

    I would like to have a function that saves the a copy of the control state and then later I can compare the current state with the original for change. I realise that using memcpy isn't going to be a workable solution for comparing classes, can I rely on the '=' operator to compare a copy against the current version?

    If anyone can suggest a portable and generic way that I can use for Qt controls, very much appreciated.

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can do some meta system programming and store the value of the property that is marked as USER.

      See the property system documentation for more information.

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

      SPlattenS 1 Reply Last reply
      3
      • SGaistS SGaist

        Hi,

        You can do some meta system programming and store the value of the property that is marked as USER.

        See the property system documentation for more information.

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        @SGaist , I'm looking at this now, I would imagine that implementing this method would require a specific implementation for each control, I was hoping to add something that would require minimal differences between different controls. I started with a base class that has a couple of pure virtual functions such as:

        virtual bool blnChanged() = 0; // Returns true if control has changed from original
        virtual void saveOriginal() = 0; // Saves the current state as the original
        

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That's why I am suggesting using meta system programming. Inspect the objects QMetaObject to get the right property and store that one.

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

          SPlattenS 2 Replies Last reply
          3
          • SGaistS SGaist

            That's why I am suggesting using meta system programming. Inspect the objects QMetaObject to get the right property and store that one.

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #5

            @SGaist , I'll read up.

            Kind Regards,
            Sy

            1 Reply Last reply
            0
            • SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #6

              Doesn't look like a simple solution, I need to take a break and come back fresh another day. Need to think about this.

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • SGaistS SGaist

                That's why I am suggesting using meta system programming. Inspect the objects QMetaObject to get the right property and store that one.

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by SPlatten
                #7

                @SGaist , can properties be added at run-time?

                I want to store the original data for each GUI object, I was thinking of doing this in properties the comparing the original data with the current data and returning true if there is a difference.

                Just found this:
                https://doc.qt.io/qt-5/properties.html#dynamic-properties

                Looking into it.

                Kind Regards,
                Sy

                1 Reply Last reply
                0
                • JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by JoeCFD
                  #8

                  Try to use QStateMachine.

                  1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    SimonSchroeder
                    wrote on last edited by
                    #9

                    @SGaist said in Looking for suggestions or hints on best way to...:

                    That's why I am suggesting using meta system programming. Inspect the objects QMetaObject to get the right property and store that one.

                    Having a quick look shows that QMetaObject even has a userProperty() member functions. The link @SGaist already provided says the following about the USER property:

                    The USER attribute indicates whether the property is designated as the user-facing or user-editable property for the class. Normally, there is only one USER property per class (default false). e.g., QAbstractButton::checked is the user editable property for (checkable) buttons.

                    So, I would suggest trying something like this:

                    const char *propertyName = widget->metaObject()->userProperty()->name();
                    QVariant value = widget->property(name);
                    ...
                    widget->setProperty(name, value);
                    

                    You need to figure out, though, what happens if there is no USER property. Maybe propertyName would be an empty string or nullptr?

                    1 Reply Last reply
                    1
                    • SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #10

                      I've made some progress in this area, not all widgets have USER property, but its pretty simple to figure out.

                      Kind Regards,
                      Sy

                      1 Reply Last reply
                      0

                      • Login

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