QML 对象类型不是 QTCreator 中的类型错误 [英] QML Object Type is not a type error in QTCreator

查看:13
本文介绍了QML 对象类型不是 QTCreator 中的类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是 QT 新手,我无法通过另一个 qml 加载一个 qml基本上我已经创建了一个 qml MyTabView(MyTabView.qml)

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.3
 import QtQuick.Controls 1.2

TabView {
    width: 360
    height: 360

    Component.onCompleted: {
        addTab("Tab 1", tab1)

      addTab("Tab 2", tab2)
    }

    Component {
        id: tab1
        Rectangle {color: "red"}
    }

    Component {
        id: tab2
        Rectangle {color: "blue"}
    }
}

我正在尝试通过同一目录中的另一个 qml(main.qml) 显示它

and i am trying to show it through another qml(main.qml) which is in the same directory

import QtQuick 2.3
import QtQuick.Controls 1.2
import "."

ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Main")

MyTabView {}

}

但是当我尝试运行我的项目时,我得到了这个错误

but when i try to run my project i get this error

QQmlApplicationEngine 加载组件失败qrc:/qml/main.qml:11 TabView 不是类型

QQmlApplicationEngine failed to load component qrc:/qml/main.qml:11 TabView is not a type

请注意,我在 MyTabView.qml 中有 M Caps,并且 MyTabView.qml 和 main.qml 位于同一目录中.

Please note that i have M Caps in MyTabView.qml and that MyTabView.qml and main.qml are in the same directory.

有人能指出我在做什么错误吗?我要指出的一件事是,当我在 main.qml 中替换 MyTabView.qml 的所有代码而不是 MyTabView {} 时,程序不会给出任何错误并且正确运行.提前致谢

Can someone point me what mistake i am doing ? One thing i want to point is that when i replace all the code of MyTabView.qml instead of MyTabView {} inside main.qml,the program does not give any error and runs correctly. Thanks in advance

推荐答案

您是否已将文件添加到资源中?
将您的 MyTabView.qml 添加到您的项目中 main.qml 的同一目录中是不够的.
您必须将 QML 文件放在资源中(可能是 main.qrc/qml/)才能部署它.
Qt Creator 的编辑器不需要这个包含来找到你的类型,因此它不会显示错误.

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.

这篇关于QML 对象类型不是 QTCreator 中的类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆