Component template
-
Hello,
I want to define a custom component and to instanciate it in my main QML file. I use QML Controls2.
I read the Qt tutorial and the forum but there is something I don't get. It seems to be a basic problem but it eludes me.Here is the content of buttonal1.qml
import QtQuick 2.0 Rectangle { width: 300 height: 200 color:"#0f0f0f" property alias nameTextTop: nameText // This alias is defined at top level and bound to Text element Text { id: nameText color: "blue" text: "Some text fragment" } }
and here is the content of main.qml:
import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World") buttonal1 { width: 200 } }
However, I get an error in my main file (buttonal1 is not recognized "invalid property name").
Both main.qml and buttonal1.qml are under Resources/qml.qrc/
Thank you so much,
Alex
-
Hi,
I went through the exact same problem ... changed the component beginning letter to upper case. Now I get this run time error "qrc:/main.qml:21 MButton is not a type". Please tell me what is wrong?
Anthony
MButton.qml
import QtQuick 2.0
Rectangle
{
width: 100; height: 30; color: "yellow"
}main.qml
import QtQuick 2.7
import QtQuick.Controls 2.0ApplicationWindow
{
visible: true
width: 640
height: 480
title: qsTr("Calculator")Column { width: parent.width Rectangle { width: 100 height: 100 color: "red" } MButton { } }
}
qml.qrc
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>content/MButton.qml</file>
</qresource>
</RCC> -
Hi,
I went through the exact same problem ... changed the component beginning letter to upper case. Now I get this run time error "qrc:/main.qml:21 MButton is not a type". Please tell me what is wrong?
Anthony
MButton.qml
import QtQuick 2.0
Rectangle
{
width: 100; height: 30; color: "yellow"
}main.qml
import QtQuick 2.7
import QtQuick.Controls 2.0ApplicationWindow
{
visible: true
width: 640
height: 480
title: qsTr("Calculator")Column { width: parent.width Rectangle { width: 100 height: 100 color: "red" } MButton { } }
}
qml.qrc
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>content/MButton.qml</file>
</qresource>
</RCC>