Solved 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
-
Ok, I found the answer. My template file "buttonal1.qml" was beginning with a lower case letter and it is why it didn't work....It must start with an upper case letter.
-
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> -
@att_
Hi,
Did you ever find out what was wrong? I'm starting using Qt right now, and running into the same line if problems, Qt not wanting to use some objects I have refactored to move them in a different file...Thanks.