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