[SOLVED] QML component inheritance - problem
-
Hi. I have two files:
@
// MainWindow.qmlimport QtQuick 2.1
import Qt3D 2.0Rectangle {
//some code
Viewport {
// some 3D code
}
}// Robot.qml
import QtQuick 2.1
import Qt3D 2.0MainWindow {
Item3D {
// some 3D robot drawing code
}}
@
And my problem is that this isn't working. I know why, because Item3D is on the first level in MainWindow class. Item3D is child of Rectangle in MainWindow class, but Item3D must be child of Viewport in MainWindow class. How to tell the QML to put item3D in Viewport in main Window, not in the top level Rectangle ?
-
@onek24: You are right I didn't notice the "some code" mention. However it is still possible to move the rectangle and the outside code to Robot.qml
@sibislaw2: Is something like below possible in your use case?
@
// MainWindow.qmlimport QtQuick 2.1 Rectangle { //some code MyViewport { } } // MyViewport.qml import QtQuick 2.1 import Qt3D 2.0 Viewport { // some 3D code Robot{ } } // Robot.qml import QtQuick 2.1 import Qt3D 2.0 Item3D { // some 3D robot drawing code }@
-
I resolved problem by using loader class.
@
Rectangle {
// code
Viewport {
// codeLoader { id: robotLoader objectName: "robotLoader" property string robotQmlFile: "" source: robotLoader.robotQmlFile }}
}@
By this code i can load dynamically my class into desired Viewport.