如何解决QML“文本不是类型”错误?

时间:2020-07-30 09:09:13

标签: qt qml

我正在关注wireframe Qml example in QtCreator

我想在视图中添加标题,所以我在main.qml中添加了Text组件。

/****************************************************************************/

import QtQuick 2.1 as QQ2
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Input 2.0
import Qt3D.Extras 2.0

Entity {
    id: root

    // Render from the mainCamera
    components: [
        RenderSettings {
            activeFrameGraph: ForwardRenderer {
                id: renderer
                camera: mainCamera
            }
        },
        // Event Source will be set by the Qt3DQuickWindow
        InputSettings { }
    ]

    BasicCamera {
        id: mainCamera
        position: Qt.vector3d( 0.0, 0.0, 15.0 )
    }

    FirstPersonCameraController { camera: mainCamera }

    WireframeMaterial {
        id: wireframeMaterial
        effect: WireframeEffect {}
        ambient: Qt.rgba( 0.2, 0.0, 0.0, 1.0 )
        diffuse: Qt.rgba( 0.8, 0.0, 0.0, 1.0 )

        QQ2.SequentialAnimation {
            loops: QQ2.Animation.Infinite
            running: true

            QQ2.NumberAnimation {
                target: wireframeMaterial;
                property: "lineWidth";
                duration: 1000;
                from: 0.8
                to: 1.8
            }

            QQ2.NumberAnimation {
                target: wireframeMaterial;
                property: "lineWidth";
                duration: 1000;
                from: 1.8
                to: 0.8
            }

            QQ2.PauseAnimation { duration: 1500 }
        }
    }

    TrefoilKnot {
        id: trefoilKnot
        material: wireframeMaterial
    }

    Text {
        id: name
        text: qsTr("TrefoilKnot")
    }


}

但是当我运行应用程序时,Qt给我

qrc:/main.qml:114:5:文本不是一种类型

错误

文本只是基本的Qt Quick QML类型,我不知道为什么会这样。

我该如何解决?

1 个答案:

答案 0 :(得分:2)

import QtQuick 2.1 as QQ2
...

您已将QtQuick作为QQ2导入,因此需要将Text称为QQ2.Text,即

QQ2.Text {
    id: name
    text: qsTr("TrefoilKnot")
}