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. Javascript and UI Form

Javascript and UI Form

Scheduled Pinned Locked Moved Solved QML and Qt Quick
11 Posts 3 Posters 3.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.
  • 6thC6 Offline
    6thC6 Offline
    6thC
    wrote on last edited by
    #2

    http://doc.qt.io/Qt-5/qtquickcontrols-uiforms-qml-settings-qml.html from the example project at http://doc.qt.io/Qt-5/qtquickcontrols-uiforms-example.html
    might help get your head sorted.

    You can still do onCompleted work - just not declared inside the UI file. Do that where you use the file not inside it.

    You also can declare your own qml signals (but I don't think that's what you want). The reason you can't is because if you are using an UI file - that's the whole idea. No scripting or functions. Bindings are fine.

    So see in that example file? Settings has an SettingsForm instance and used onCompleted to invoke readData method.

    1 Reply Last reply
    1
    • D Offline
      D Offline
      Diarby
      wrote on last edited by
      #3

      Hi,
      Thanks for your reply. I read the SettingsForm example but I didn't found what I'm looking for.
      The Component.onCompleted is referencing the whole object (SettingsForm) but I want to reference individual objects declared inside the form. Each one can do its completion irrespective of other.

      ODБOïO 6thC6 2 Replies Last reply
      0
      • D Diarby

        Hi,
        Thanks for your reply. I read the SettingsForm example but I didn't found what I'm looking for.
        The Component.onCompleted is referencing the whole object (SettingsForm) but I want to reference individual objects declared inside the form. Each one can do its completion irrespective of other.

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by ODБOï
        #4

        @Diarby hi,
        you can create your own qml Type and add it to .ui.qml. With this you can reference childs by their x,y position..

        //MyItem.qml

        import QtQuick 2.0
        
        Item {
            Component.onCompleted: console.log(parent.childAt(0,0).color="red");
        }
        

        Hope it can help you
        LA

        D 1 Reply Last reply
        0
        • D Diarby

          Hi,
          Thanks for your reply. I read the SettingsForm example but I didn't found what I'm looking for.
          The Component.onCompleted is referencing the whole object (SettingsForm) but I want to reference individual objects declared inside the form. Each one can do its completion irrespective of other.

          6thC6 Offline
          6thC6 Offline
          6thC
          wrote on last edited by
          #5

          @Diarby Hmmm. I'm away from my machine currently... can you alias the object you want in the ui file
          and then attach to it's completed?

          If I can remember, I'll try and have a look myself Monday (it's Sat. here).

          D 1 Reply Last reply
          0
          • 6thC6 6thC

            @Diarby Hmmm. I'm away from my machine currently... can you alias the object you want in the ui file
            and then attach to it's completed?

            If I can remember, I'll try and have a look myself Monday (it's Sat. here).

            D Offline
            D Offline
            Diarby
            wrote on last edited by
            #6

            @6thC Hi. I exported the object from ui.qml file with an alias property. The problem is I can write only suggested handlers.
            The concept of separation between ui and code logics is the best and I agree to it. However, in the onCompleted handler we have to write codes so it will be right to have this handler in the suggested handlers. I think its absence is a weakness.

            1 Reply Last reply
            0
            • ODБOïO ODБOï

              @Diarby hi,
              you can create your own qml Type and add it to .ui.qml. With this you can reference childs by their x,y position..

              //MyItem.qml

              import QtQuick 2.0
              
              Item {
                  Component.onCompleted: console.log(parent.childAt(0,0).color="red");
              }
              

              Hope it can help you
              LA

              D Offline
              D Offline
              Diarby
              wrote on last edited by
              #7

              @LeLev Hi. Thanks for your suggestion but I think this way is a reinvention of the wheel. If the ui.qml contains more objects with different code logics, we have to implement a file for each one increasing the risk of do more mistakes.
              The Qt provides many QML types ready for use with an opportunity to implement user logic in the onCompleted handler.

              1 Reply Last reply
              0
              • 6thC6 Offline
                6thC6 Offline
                6thC
                wrote on last edited by 6thC
                #8

                @Diarby
                I see what you mean.

                I cannot access an aliased objects onCompleted from the qml file. That was unexpected (to me).

                All the other handlers are available in the autocomplete ... even onDestroyed.
                However, If I actually use onDestroyed, at runtime I get:

                qrc:/main.qml:12 Type CustomComponent unavailable
                qrc:/CustomComponent.qml:13 Cannot assign to non-existent property "onDestroyed"
                

                the aliased object fills the parent and I can access onWidthChanged as expected...

                I think it'd be useful to have exposed too and indeed I expected it already was.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Diarby
                  wrote on last edited by
                  #9

                  Hello everyone,
                  I let this opened until a solution is found. Maybe someone else can fix this.

                  1 Reply Last reply
                  0
                  • 6thC6 Offline
                    6thC6 Offline
                    6thC
                    wrote on last edited by
                    #10

                    Maybe someone on http://lists.qt-project.org/mailman/listinfo/development could help?
                    Or you could report a bug http://wiki.qt.io/Reporting_Bugs - it may not be. It maybe that there is a way to do this.

                    If I was you and needing this now as you are - I would probably try moving those objects in the UI file into separate QML + UI files and doing the onComplete stuff there? Either way the forum probably won't help get anything progressed, it's great for helping to use it but it's not really the best place for getting effective changes.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Diarby
                      wrote on last edited by
                      #11

                      Thanks for links supplied. I would submit later, after my learning of QML.
                      For now, I did separations to accomplish this work, which is a test of QML Programming as I'm new to Qt.

                      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