Include another QML file from a QML file

前端 未结 6 1610
天涯浪人
天涯浪人 2020-12-29 21:53

There\'s another question on Stackoverflow about this matter but I don\'t find the accepted solution possible. So I ask again because the old question is out of attention.

6条回答
  •  旧时难觅i
    2020-12-29 22:12

    Finally I have dug it out from internet. Let's say the to-be-included file is 'mycomponent.qml' in this directory structure (Qt Quick):

    projectdir/
      qml/
        projectname/
          main.qml
          mycomponent.qml
    

    The content of 'mycomponent.qml' (for example):

    Text {
      text:"Hello, Scooby Doo!";
    }
    

    We have to load it this way (in 'main.qml'):

    Rectangle {
      ...
      Loader {
        source:"mycomponent.qml";
      }
      ...
    }
    

提交回复
热议问题