QtQuick 2.0中导入QML的问题

时间:2014-08-03 20:24:52

标签: qml qt5 qtquick2

have 3 files,主frontend.qml和按钮的额外qml文件,并希望在邮件QML中使用按钮QML,但收到错误:

Starting .../qmlscene .../qml/frontend.qml
file:///.../qml/frontend.qml:28 Cannot assign to non-existent property "btnSite"

.../qmlscene exited with code 255

好的......一步一步。

frontend.qmlproject:

import QmlProject 1.1

Project {
    mainFile: "frontend.qml"

    QmlFiles {
        directory: "."
    }
    JavaScriptFiles {
        directory: "."
    }
    ImageFiles {
        directory: "."
    }
}

bntSite.qml:

import QtQuick 2.0

Rectangle {
    id: container
    width: 200
    height: 45
    color: "#201616"

    Text {
        id: text1
        width: 24
        height: 16
        color: "#ead9d9"
        text: qsTr("Text")
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        horizontalAlignment: Text.AlignHCenter
        font.pixelSize: 14
    }
}

和最后一个文件(我想使用那个bntSite.qml)是frontend.qml:

import QtQuick 2.0

Rectangle {
    id: container
    width: 1080
    height: 700

    state: "selectSite"

    states: [
        State {
            name: "selectSite"
        }
    ]

    gradient: Gradient {
        GradientStop {
            position: 0
            color: "#38466b"
        }

        GradientStop {
            position: 1
            color: "#afbad7"
        }
    }

    btnSite { id:tab1 }

}

如果我尝试在frontend.qml中添加此字符串:

import "./btnSite.qml"

我仍然有错误,但另一个:

file:///.../qml/frontend.qml:2 "./btnSite.qml": no such directory

好吧,我的问题是如何在frontend.qml中使用btnSite.qml中的按钮?

0 个答案:

没有答案