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. Calling QML function from PySide
Forum Updated to NodeBB v4.3 + New Features

Calling QML function from PySide

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 4 Posters 6.3k 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.
  • J Offline
    J Offline
    jech
    wrote on last edited by
    #1

    Hello,

    I'd like to get help on calling a function of a QML object from PySide. I know the example "here":http://qt.gitorious.org/pyside/pyside-examples/blobs/master/examples/declarative/signals/pytoqml1/main.py. But it only shows how to call a function of the root object, but how do I call function(s) of other QML objects?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      blam
      wrote on last edited by
      #2

      If you need to locate a child object, you should be able to use QObject::findChild(). The C++ example is here: http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#locating-child-objects

      Basically you'll need to set the 'objectName' for the child in order to locate it using QObject::findChild().

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kamalakshantv
        wrote on last edited by
        #3

        [quote author="blam" date="1293063077"]If you need to locate a child object, you should be able to use QObject::findChild(). The C++ example is here: http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#locating-child-objects

        Basically you'll need to set the 'objectName' for the child in order to locate it using QObject::findChild().[/quote]

        But this is usually not recommended right. Setting the objectName.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jech
          wrote on last edited by
          #4

          QtK: So what would be the recommended way of calling a function of a certain QML object?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kamalakshantv
            wrote on last edited by
            #5

            [quote author="jech" date="1293089959"]QtK: So what would be the recommended way of calling a function of a certain QML object?[/quote]

            "This":http://www.mail-archive.com/qt-qml@trolltech.com/msg01464.html thread should help you.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jech
              wrote on last edited by
              #6

              Thank you, this information helped me a lot. I think I can use a QObject with it's properties in most cases.

              But still I think I need to call a function in some cases. For example I need to set currentIndex of a ListView from Python. How would I do that?

              1 Reply Last reply
              0
              • F Offline
                F Offline
                FxIII
                wrote on last edited by
                #7

                This question raise a design issue; while is not a very good idea to pollute your root object with tons of functions, is still a good idea to put to root object all the function you need.
                You should try to think about root object as the interface to your qml gui: the deep you go through your QmlItems the wrost is going to be.
                You should expose a clear interface on your root object so changes behind the scenes can be kept hidden.
                In your case you should write a search function on the root object that parametrically finds what you want; that function should be semantc: say what you want and i will give it to you.
                Once again changing the entire qml and providing the same interface, gives you a new way to present and do stuffs, without change the backend.
                Doing so, you may see you are going to write too much function on your root object. In this case you can consider to write some interface Item on your Qml code directly behind your root object. So you can broke down interfaces by semantically unrelated groups and provide those interfaces as main gateways through your root object.
                I hope this can clear your picture.

                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