Qml class doesn't work
-
In Qt Creator I am trying to use a custom qml class I can add objects but I get this error:
Invalid property name 'x' (M16)whenever I set a property.
And nothing is displayed when I launch the app.main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQmlContext> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; qmlRegisterType(QUrl("qrc:/MyTimer.qml"), "MyTimers", 1, 0, "MyTimer"); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }main.qml import QtQuick import QtQuick.Window import QtMultimedia import QtQuick.Controls import QtQuick.Layouts import MyTimers Window { width: 640 height: 480 visible: true title: qsTr("Timers") color: "#000000" MyTimer { id: timer1 countdownValue: 30 } }MyTimer.qml
import QtQuick import QtQuick.Controls Item { id: root property int countdownValue: 30 Rectangle { anchors.fill: parent color: "red" width: 600 height: width } }Since it wasn't working I changed the class to have only a rectangle (that it is not shown when I run it).
MyTimer.qml and main.qml are specified in resources.qrc.
-
In Qt Creator I am trying to use a custom qml class I can add objects but I get this error:
Invalid property name 'x' (M16)whenever I set a property.
And nothing is displayed when I launch the app.main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQmlContext> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; qmlRegisterType(QUrl("qrc:/MyTimer.qml"), "MyTimers", 1, 0, "MyTimer"); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }main.qml import QtQuick import QtQuick.Window import QtMultimedia import QtQuick.Controls import QtQuick.Layouts import MyTimers Window { width: 640 height: 480 visible: true title: qsTr("Timers") color: "#000000" MyTimer { id: timer1 countdownValue: 30 } }MyTimer.qml
import QtQuick import QtQuick.Controls Item { id: root property int countdownValue: 30 Rectangle { anchors.fill: parent color: "red" width: 600 height: width } }Since it wasn't working I changed the class to have only a rectangle (that it is not shown when I run it).
MyTimer.qml and main.qml are specified in resources.qrc.
-
@realroot Your
MyTimeris defined as anItemwhich needs to have a size specified in order for it to be shown. I am not sure what will happen with the childRectangleas you are both filling the parent (whose size is 0) and setting its width and height.@Bob64 said in Qml class doesn't work:
I am not sure what will happen with the child Rectangle as you are both filling the parent (whose size is 0) and setting its width and height.
anchors.fillhas the priority overwidthandheight -
@realroot Your
MyTimeris defined as anItemwhich needs to have a size specified in order for it to be shown. I am not sure what will happen with the childRectangleas you are both filling the parent (whose size is 0) and setting its width and height. -
R realroot has marked this topic as solved on