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. Access qml object that was defined in python and dynamically (?) used in a repeater

Access qml object that was defined in python and dynamically (?) used in a repeater

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
repeaterpython accessdynamically
1 Posts 1 Posters 619 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.
  • SietseAchteropS Offline
    SietseAchteropS Offline
    SietseAchterop
    wrote on last edited by SietseAchterop
    #1

    Hello List,

    EDIT: made the question a bit clearer I hope.
    I have a python class that is registered and instantiated in qml.

    qmlRegisterType(FigureCanvasQTAggToolbar, "Backend", 1, 0, "FigureToolbar")
    

    In qml I give the instantiation of FigureToolbar the object name "pieces".
    I want to access that object using a python class FormPieces and connect the two as follows:

      mainPieces = FormPieces()  
      engine.load( 'main.qml'))  
      win = engine.rootObjects()[0]  
      mainPieces.figure = win.findChild(QObject, "pieces").getFigure()
    

    I now can use the FigureToolbar from mainPieces. This works fine.

    But now I have a number of these FigureToolbars in a Repeater, the number can vary.
    The Repeater is as follows:

    	Repeater {
    	    model: draw_mpl.nmbrRowers
    	    delegate: RowerProfile {
    		rindex : index
    	    }
    	}
    

    In Python I do the apropriate number of times::

    rowerPlots[i] = RowerForm(i)
    

    In RowerProfile item, in the Figuretoolbar, I do the following in the hope the object is available when completed.:

            objectName = 'viewrower' + theindex;
            Component.onCompleted: draw_mpl.rowerprofile(objectname)
    

    Then in python in rowerprofile(n) I do:

       rowerPlots[i].figure = win.findChild(QObject, n).getFigure()
    

    Rowerprofile is called the correct number of times, the different objectNames are coming across , but I get the following error:

    AttributeError: 'NoneType' object has no attribute 'findChild'
    

    I don't understand this, the object is completed, it has it's correct objectname, but it can't be found?

    What I also did try was to make getFigure a slot of the FigureToolbar and then:

     Component.onCompleted: draw_mpl.rowerprofile(getFigure())
    

    But then I get undefined in python. Also putting the result in a list did not work.

    So, how can I, in Python or C++, get access to a method in an object in qml inside a repeater object when it is dynamically created?

    Thanks in advance, Sietse

    PS. The complete code is at https://github.com/SietseAchterop/RtcNoordApp

    1 Reply Last reply
    1

    • Login

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