1

I have 3 files, main frontend.qml and additional qml file for button and want to use button QML in mail QML but got error:

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

.../qmlscene exited with code 255

Okay... so step-by step.

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
    }
}

and last file (in which I want to use that bntSite.qml) is 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 }

}

if I try to add in frontend.qml this string :

import "./btnSite.qml"

I still got error, but another:

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

Well, my question is how to use button from btnSite.qml in frontend.qml?

xiaose
  • 616
  • 1
  • 7
  • 19

0 Answers0