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. Strange approach to properties
QtWS25 Last Chance

Strange approach to properties

Scheduled Pinned Locked Moved Solved General and Desktop
propertiesqwidgetserializationmetadataqmetaobject
12 Posts 3 Posters 4.7k 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.
  • W Offline
    W Offline
    Wilk
    wrote on 7 Jan 2016, 13:42 last edited by
    #1

    Hi all.

    I'm working on a small collection of functions that allow to serialize/deserialize Objects in/from XML. And I found out a fact that astonished me a lot: some properties of QWidget are actually not properties, and some of them are kinda useless, 'cause they can only be read.

    For example, windowFlags is mentioned as property in docs, however it is not, that can be seen in sources, where windowFlags is declared with QDOC_PROPERTY.

    Another example is fullScreen property of the same QWidget class. This property can only be read, but not set.

    Thus I can not understand, why all those properties was not implemented as full properties with set and get methods so that it could be used as any other property? I believe that there was some reason for that, however I can not understand it.

    Does anyone know that reason?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 7 Jan 2016, 13:51 last edited by
      #2

      Hi,

      Because not all properties makes sense to be read/write. You can have for example a property representing the state of a piece of hardware. The hardware being the controller of the state, it wouldn't make sense for a library user to be able to set that state.

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

      W 1 Reply Last reply 7 Jan 2016, 13:53
      0
      • S SGaist
        7 Jan 2016, 13:51

        Hi,

        Because not all properties makes sense to be read/write. You can have for example a property representing the state of a piece of hardware. The hardware being the controller of the state, it wouldn't make sense for a library user to be able to set that state.

        W Offline
        W Offline
        Wilk
        wrote on 7 Jan 2016, 13:53 last edited by
        #3

        @SGaist Well, you are right, not all properties make sense to read and write. But I think, that property like fullScreen is one of those, that one may want to write. Well, I want to write it)

        M 1 Reply Last reply 7 Jan 2016, 13:56
        0
        • W Wilk
          7 Jan 2016, 13:53

          @SGaist Well, you are right, not all properties make sense to read and write. But I think, that property like fullScreen is one of those, that one may want to write. Well, I want to write it)

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 7 Jan 2016, 13:56 last edited by
          #4

          @Wilk
          well that is what
          http://doc.qt.io/qt-5/qwindow.html#setWindowState
          is for :)

          W 1 Reply Last reply 7 Jan 2016, 14:02
          0
          • M mrjj
            7 Jan 2016, 13:56

            @Wilk
            well that is what
            http://doc.qt.io/qt-5/qwindow.html#setWindowState
            is for :)

            W Offline
            W Offline
            Wilk
            wrote on 7 Jan 2016, 14:02 last edited by
            #5

            @mrjj, I know about all other ways to make window fullscreen or set another window state. I'm talking about inability to make all those funny things with use of property system. Basically I'm veeery lazy, so I prefer to write a single piece of code that does everything instead of creating different code for handling different approaches to setting window state.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              Wilk
              wrote on 7 Jan 2016, 14:13 last edited by
              #6

              For example, if everything is property, I can do the following:

              1. Serialize object state with a single call:
              QDomNode serializedObjectProperties = serialize (
              	this,
              	QObjectSerialization::TAG_OBJECT_NAME);
              

              serializedObjectProperties will be XML DOM element with tag name that's the same as object name stored in objectName property.
              2. Save serialized object state in XML file like this:

               <SomeWidget minimumHeight="0" toolTipDuration="-1" modal="false" focus="false" windowOpacity="1" styleSheet="" objectName="SomeWidget" autoFillBackground="true" windowModified="false" maximized="false" toolTip="" inputMethodHints="0" minimumWidth="0" isActiveWindow="false" height="1024" y="51" width="1280" accessibleDescription="" windowTitle="" enabled="true" font="MS Shell Dlg 2,8.25,-1,5,50,0,0,0,0,0" windowModality="0" statusTip="" contextMenuPolicy="1" fullScreen="true" accessibleName="" maximumWidth="16777215" visible="true" x="-1280" updatesEnabled="true" maximumHeight="16777215" mouseTracking="true" layoutDirection="0" windowFilePath="" focusPolicy="0" whatsThis="" acceptDrops="false" windowIconText="" minimized="false">
                      <property name="childrenRect">
                        <QRect y="0" width="0" x="0" height="0"/>
                      </property>
                      <property name="geometry">
                        <QRect y="51" width="1280" x="-1280" height="1024"/>
                      </property>
                      <property name="normalGeometry">
                        <QRect y="358" width="640" x="-1050" height="480"/>
                      </property>
                      <property name="frameGeometry">
                        <QRect y="51" width="1280" x="-1280" height="1024"/>
                      </property>
                      <property name="rect">
                        <QRect y="0" width="1280" x="0" height="1024"/>
                      </property>
                    </SomeWidget>
              
              1. Restore full object state with a single call:
              deserialize (
              	window,
              	serializedObjectProperties);
              

              I find it usefull as soon as I don't need to wary about anything as long as object state if fully described with it's properties.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 7 Jan 2016, 14:15 last edited by mrjj 1 Jul 2016, 14:15
                #7

                Well, i understand.
                show() and hide() are not properties either so
                I guess they designed fullscreen to be a case of showíng and
                not a property. We are all lazy: )
                I just wish c++ had serialization system as default :)

                W 1 Reply Last reply 7 Jan 2016, 14:19
                0
                • M mrjj
                  7 Jan 2016, 14:15

                  Well, i understand.
                  show() and hide() are not properties either so
                  I guess they designed fullscreen to be a case of showíng and
                  not a property. We are all lazy: )
                  I just wish c++ had serialization system as default :)

                  W Offline
                  W Offline
                  Wilk
                  wrote on 7 Jan 2016, 14:19 last edited by
                  #8

                  @mrjj
                  With QObject properties serialization becomes realy easy. Well, some things in my implementation may be wrong or, you know, ugly, but for now it works quite fine. I think I'll put it on GitHub as soon as it will be ready enough.

                  M 1 Reply Last reply 7 Jan 2016, 14:20
                  1
                  • W Wilk
                    7 Jan 2016, 14:19

                    @mrjj
                    With QObject properties serialization becomes realy easy. Well, some things in my implementation may be wrong or, you know, ugly, but for now it works quite fine. I think I'll put it on GitHub as soon as it will be ready enough.

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 7 Jan 2016, 14:20 last edited by
                    #9

                    @Wilk
                    sounds cool. other will like to see such library.
                    Thank you

                    W 1 Reply Last reply 7 Jan 2016, 20:35
                    0
                    • M mrjj
                      7 Jan 2016, 14:20

                      @Wilk
                      sounds cool. other will like to see such library.
                      Thank you

                      W Offline
                      W Offline
                      Wilk
                      wrote on 7 Jan 2016, 20:35 last edited by
                      #10

                      @mrjj
                      You inspired me so I've commited my work on GitHub. The implementation is not good enough for production, I guess, and it's not packed as appropriate library, but it still may be usefull. As soon as I'll find time for it I'll try to make it a real library.

                      M 1 Reply Last reply 7 Jan 2016, 20:38
                      1
                      • W Wilk
                        7 Jan 2016, 20:35

                        @mrjj
                        You inspired me so I've commited my work on GitHub. The implementation is not good enough for production, I guess, and it's not packed as appropriate library, but it still may be usefull. As soon as I'll find time for it I'll try to make it a real library.

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 7 Jan 2016, 20:38 last edited by
                        #11

                        @Wilk
                        Checked a few files. seems good quality.
                        Thank you.

                        W 1 Reply Last reply 7 Jan 2016, 20:38
                        1
                        • M mrjj
                          7 Jan 2016, 20:38

                          @Wilk
                          Checked a few files. seems good quality.
                          Thank you.

                          W Offline
                          W Offline
                          Wilk
                          wrote on 7 Jan 2016, 20:38 last edited by
                          #12

                          @mrjj Thanks)

                          1 Reply Last reply
                          0

                          5/12

                          7 Jan 2016, 14:02

                          • Login

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