Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML private properties

QML private properties

Scheduled Pinned Locked Moved QML and Qt Quick
19 Posts 6 Posters 13.3k 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.
  • B Offline
    B Offline
    bunjee
    wrote on last edited by
    #1

    Greetings,

    In Qt 4.8 RC, I'm declaring a private property like this:
    @property bool __test: false

    on__testChanged: console.debug("Hi !")@
    I'm getting that:

    bq. PanelRelated.qml:23 Cannot assign to non-existent property "on__testChanged"

    Does anybody know why ?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      So

      bq. on__testChanged

      (as in example) or

      bq. on__textChanged

      (as in error message)

      May be it is just a typo in your code?

      --
      Vasiliy

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bunjee
        wrote on last edited by
        #3

        Hi Vass.

        My bad. Fixed. Still not working though.

        Have you tried on your side ? Does it work for you ?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          Hi,

          It works for me (though I tested in Qt 5) if I capitalize test, i.e. on__TestChanged. I'm not sure if this is documented behavior or not.

          Regards,
          Michael

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            Capitalising first letter is documented, but here - strictly speaking - first letter is '_'. Would be a good idea to add info about this behaviour of private properties to the documentation.

            (Z(:^

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              Well, depends on if you classify _ as a letter or not ;-) QChar::isLetter() says no.

              I guess this applies to signals as well, doesn't it? So <code>signal __someSignal</code> results in a <code>on__SomeSignal</code> signal handler.

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                :) Ok let's say I meant first character, not letter.

                By intuition, I would say that if first character is not a letter, then the first actual letter should not get capitalised. But it seems this was designed in an other way. That's why I think it good to be added to docs.

                Lukas - I've tried it with signals, and the answer is negative. Example:
                @
                signal __queueOrder (string orderName, real newX, real newY)
                on__QueueOrder: ActionLogic.queueOrder(orderName, newX, newY); // ERROR!
                on__queueOrder: ActionLogic.queueOrder(orderName, newX, newY); // CORRECT!
                @

                And now this looks like inconsistent behaviour. Would be nice if the principle was the same for properties and signals. Should we fill a bug report, or maybe was that fixed in Qt5? I'm too busy now to try this in Qt5, even though I have it compiled.

                (Z(:^

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #8

                  [quote author="sierdzio" date="1325581128"]By intuition, I would say that if first character is not a letter, then the first actual letter should not get capitalised. But it seems this was designed in an other way. That's why I think it good to be added to docs.[/quote]

                  If this is the intended behaviour it definitly should be added to the docs for clarification. I've added a docnote to "Introduction to the QML Language":http://developer.qt.nokia.com/doc/qt-4.8/qdeclarativeintroduction.html for now where the captialization is mentioned.

                  [quote author="sierdzio" date="1325581128"]Lukas - I've tried it with signals, and the answer is negative.[/quote]

                  That's rather strange and I would have guessed that there is just a single piece of code that is resposible for capitalization so the behaviour should be consistent - but obviously it is not.

                  [quote author="sierdzio" date="1325581128"]Would be nice if the principle was the same for properties and signals. Should we fill a bug report, or maybe was that fixed in Qt5? I'm too busy now to try this in Qt5, even though I have it compiled.[/quote]

                  -As it is quite a while to Qt 5 I'm going to file a bug report- -"QTBUG-23414":https://bugreports.qt.nokia.com/browse/QTBUG-23414- . However, this might not be an easy one to fix, as it will break existing code.

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #9

                    Please, verify first.

                    I've tried again now, and it seems I was partially wrong. Underscores in signals do not work at all! MOC throws an error at runtime. But Qt Creator allows to write the syntax I provided above (with underscores but no capitalisation).

                    (Z(:^

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lgeyer
                      wrote on last edited by
                      #10

                      [quote author="sierdzio" date="1325582995"]Please, verify first.
                      I've tried again now, and it seems I was partially wrong. Underscores in signals do not work at all! MOC throws an error at runtime. But Qt Creator allows to write the syntax I provided above (with underscores but no capitalisation).[/quote]

                      Even though Qt Creator allows it, it looks like there are no signal handlers generated for signals not starting with a letter.

                      @
                      Item {
                      signal publicSignal
                      signal _privateSignal

                      onPublicSignal: { console.debug('onPublicSignal') }
                      
                      on_PrivateSignal: { console.debug('on_PrivateSignal') }
                      on_privateSignal: { console.debug('on_privateSignal') }
                      

                      }

                      Cannot assign to non-existent property "on_PrivateSignal"
                      Cannot assign to non-existent property "on_privateSignal"
                      @

                      Which raises another question - intended behaviour or bug (as Qt and moc do support signals starting with underscores) ;-)

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        lgeyer
                        wrote on last edited by
                        #11

                        Well, as it turns out signals with underscores do work, but there are no handlers generated or there is a naming scheme used I haven't figured out yet.

                        @

                        Item {
                        signal publicSignal
                        signal __privateSignal

                        onPublicSignal: { console.debug('onPublicSignal') }
                        
                        Component.onCompleted: {
                            publicSignal();      // does work
                            __privateSignal();  // does work too
                        }
                        
                        on__PrivateSignal: { console.debug('on_privateSignal') }   // does not work, undefined property
                        on__privateSignal: { console.debug('on_privateSignal') }   // does not work, undefined property
                        

                        }
                        @

                        1 Reply Last reply
                        0
                        • sierdzioS Offline
                          sierdzioS Offline
                          sierdzio
                          Moderators
                          wrote on last edited by
                          #12

                          Best way now is to ask on development ML. I'll do that now.

                          (Z(:^

                          1 Reply Last reply
                          0
                          • sierdzioS Offline
                            sierdzioS Offline
                            sierdzio
                            Moderators
                            wrote on last edited by
                            #13

                            Done. I'll report any news that we get from there.

                            (Z(:^

                            1 Reply Last reply
                            0
                            • L Offline
                              L Offline
                              lgeyer
                              wrote on last edited by
                              #14

                              Fine. Thanks.

                              1 Reply Last reply
                              0
                              • B Offline
                                B Offline
                                bunjee
                                wrote on last edited by
                                #15

                                Looks like I started a debate here.

                                In the meantime I'm declaring private properties that way:
                                @property bool pTest@

                                Thanks guys.

                                1 Reply Last reply
                                0
                                • sierdzioS Offline
                                  sierdzioS Offline
                                  sierdzio
                                  Moderators
                                  wrote on last edited by
                                  #16

                                  Right, we've got some answers.

                                  The capitalisation for signals with double underscores works in Qt5, but will not be ported back to 4.x

                                  Capitalising the first actual letter is intentional and will stay this way.

                                  Craig also responded with some useful info on using underscores in C++ code (it's reserved by ISO standard)

                                  Conversation can be followed here: "link":http://lists.qt-project.org/pipermail/development/2012-January/001149.html.

                                  (Z(:^

                                  1 Reply Last reply
                                  0
                                  • L Offline
                                    L Offline
                                    lgeyer
                                    wrote on last edited by
                                    #17

                                    Thanks for reporting back. Quite interesting that symbol names with preceding underscores can be seen as "just don't do it", although Qt itself uses them extensively ;-)

                                    However, if I get things right this does not effect QML, signals with preceding underscores should work and will do so with Qt5.

                                    1 Reply Last reply
                                    0
                                    • sierdzioS Offline
                                      sierdzioS Offline
                                      sierdzio
                                      Moderators
                                      wrote on last edited by
                                      #18

                                      Yeah, I've raised the same point in my reply to Craig.

                                      AFAIK, QML "talks" directly with MOC, passing signal names as strings - so C++ standard should have nothing to say here. But I may be wrong. And definitely it's a good thing to remember that such a clause happens to exist in the ISO standard.

                                      (Z(:^

                                      1 Reply Last reply
                                      0
                                      • F Offline
                                        F Offline
                                        Flamaros
                                        wrote on last edited by
                                        #19

                                        Hi,

                                        I find this thread cause there is an issue with QtCreator that push me in mistake. QtCreator find this "on__OriginXChanged" invalid and "on__originXChanged", but the first one with the upper case is the property name working when the application runs.

                                        PS : I use Qt 5.2

                                        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