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
Forum Updated to NodeBB v4.3 + New Features

QML private properties

Scheduled Pinned Locked Moved QML and Qt Quick
19 Posts 6 Posters 13.5k Views 1 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.
  • 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