QML Object Type is not a type error in QTCreator

后端 未结 4 1258
无人及你
无人及你 2021-02-20 10:01

Hi Everyone i am new to QT and i am having trouble loading one qml through another qml Basically i have created a qml MyTabView(MyTabView.qml)

 import QtQuick 2.         


        
相关标签:
4条回答
  • 2021-02-20 10:34

    This error can also be caused by a component's having an error. For instance, I had this sequence of errors:

    QQmlApplicationEngine failed to load component
    qrc:/main.qml:6 Type MainView unavailable
    qrc:/MainView.qml:27 Type ApplicationLocked unavailable
    qrc:/ApplicationLocked.qml:4 MetaStateChart is not a type
    

    It's not very clear, bu the error in MainView is caused by a problem in ApplicationLocked. When I fixed that error, everything else worked.

    So contrary to the conventional wisdom of starting with the first compiler error, it may be necessary to start with the last one!

    0 讨论(0)
  • 2021-02-20 10:36

    I had a similar problem.

    qrc:AGview.qml:8:15: AGraph is not a type

    I solved it: my original code (in my main.cpp):

    view.setSource(QUrl("qrc:AGview.qml"));
    

    the working one:

    view.setSource(QUrl("qrc:/AGview.qml"));
    

    I think without the slash it don't search in the actual folder.

    0 讨论(0)
  • 2021-02-20 10:38

    Have you added the file to your Resources ?
    Adding your MyTabView.qml to your project in the same directory of main.qml is not sufficient.
    You have to put your QML file in the Resources (probably main.qrc/qml/) in order to have it deployed.
    The editor of Qt Creator does not need this inclusion in order to find your type, therefore it displays no error.

    0 讨论(0)
  • 2021-02-20 10:48

    You should rename your "TabView.qml" to something like "MyTabView.qml".

    Because of that import

    import "."
    

    you have conflict of TabView from "QtQuick.Controls 1.2" and local folder "."

    0 讨论(0)
提交回复
热议问题