Hi all ! No problem during the building. At the end of "run" the message of Application Output is: Button is not a type (in main.qml).. This looks like a nonsense. I give you below the two codes of "Button.qml" and "main.qml". The main.cpp is constructed by QtCreator. This project comes from a book.There are many days I try to finish this project, without success.I hope somebody will help me.
//button.qml
import QtQuick 2.0
Rectangle {
id: button
width: 64
height: 64
property alias operation: buttonText.text
signal clicked
color: "green"
Rectangle {
id: shade
anchors.fill: button;
color: "black"; opacity: 0
}
Text {
id: buttonText
anchors.centerIn: parent;
color: "white"
font.pointSize: 16
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
button.clicked();
}
}
states: State {
name: "pressed"; when: mouseArea.pressed == true
PropertyChanges { target: shade; opacity: .4 }
}
}
//button.qml
import QtQuick 2.0
Rectangle {
id: button
width: 64
height: 64
property alias operation: buttonText.text
signal clicked
color: "green"
Rectangle {
id: shade
anchors.fill: button;
color: "black"; opacity: 0
}
Text {
id: buttonText
anchors.centerIn: parent;
color: "white"
font.pointSize: 16
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
button.clicked();
}
}
states: State {
name: "pressed"; when: mouseArea.pressed == true
PropertyChanges { target: shade; opacity: .4 }
}
}
To copy to clipboard, switch view to plain text mode
Next
//main.qml
import QtQuick 2.3
import QtQuick.Window 2.2
Rectangle {
width: 360
height: 200
color: "grey"
TextInput {
id: argument1
anchors.left: parent.left
width: 160
anchors.top: parent.top
anchors.topMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
text: "2"
font.pointSize: 18
}
TextInput {
id: argument2
anchors.right: parent.right
width: 160
anchors.top: parent.top
anchors.topMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
text: "2"
font.pointSize: 18
}
Text {
id: result
anchors.left: parent.left
anchors.right: parent.right
anchors.top: argument2.bottom
anchors.topMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
text: "4"
font.pointSize: 24
}
Row {
id: buttonRow
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottomMargin: 20
spacing: 20
Button { //Button is not a type
id: plusButton
operation: "+"
onClicked: result.text = parseFloat(argument1.text) + parseFloat(argument2.text)
}
Button {
id: minusButton
operation: "-"
onClicked: result.text = parseFloat(argument1.text) - parseFloat(argument2.text)
}
Button {
id: timesButton
operation: "*"
onClicked: result.text = parseFloat(argument1.text) * parseFloat(argument2.text)
}
Button {
id: divideButton
operation: "/"
onClicked: result.text = parseFloat(argument1.text) / parseFloat(argument2.text)
}
}
}
//main.qml
import QtQuick 2.3
import QtQuick.Window 2.2
Rectangle {
width: 360
height: 200
color: "grey"
TextInput {
id: argument1
anchors.left: parent.left
width: 160
anchors.top: parent.top
anchors.topMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
text: "2"
font.pointSize: 18
}
TextInput {
id: argument2
anchors.right: parent.right
width: 160
anchors.top: parent.top
anchors.topMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
text: "2"
font.pointSize: 18
}
Text {
id: result
anchors.left: parent.left
anchors.right: parent.right
anchors.top: argument2.bottom
anchors.topMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
text: "4"
font.pointSize: 24
}
Row {
id: buttonRow
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottomMargin: 20
spacing: 20
Button { //Button is not a type
id: plusButton
operation: "+"
onClicked: result.text = parseFloat(argument1.text) + parseFloat(argument2.text)
}
Button {
id: minusButton
operation: "-"
onClicked: result.text = parseFloat(argument1.text) - parseFloat(argument2.text)
}
Button {
id: timesButton
operation: "*"
onClicked: result.text = parseFloat(argument1.text) * parseFloat(argument2.text)
}
Button {
id: divideButton
operation: "/"
onClicked: result.text = parseFloat(argument1.text) / parseFloat(argument2.text)
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks