<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Qml class doesn&#x27;t work]]></title><description><![CDATA[<p dir="auto">In Qt Creator I am trying to use a custom qml class I can add objects but I get this error:</p>
<pre><code>Invalid property name 'x' (M16)
</code></pre>
<p dir="auto">whenever I set a property.<br />
And nothing is displayed when I launch the app.</p>
<p dir="auto">main.cpp</p>
<pre><code>#include &lt;QGuiApplication&gt;
#include &lt;QQmlApplicationEngine&gt;
#include &lt;QQmlContext&gt;

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();
}
</code></pre>
<pre><code>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
        }

}
</code></pre>
<p dir="auto">MyTimer.qml</p>
<pre><code>import QtQuick
import QtQuick.Controls

Item {
    id: root
    property int countdownValue: 30

	Rectangle {
		anchors.fill: parent
		color: "red"
                width: 600
                height: width
	}
}
</code></pre>
<p dir="auto">Since it wasn't working I changed the class to have only a rectangle (that it is not shown when I run it).</p>
<p dir="auto">MyTimer.qml and main.qml are specified in resources.qrc.</p>
]]></description><link>https://forum.qt.io/topic/149385/qml-class-doesn-t-work</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 19:46:14 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/149385.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 11 Sep 2023 14:44:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Qml class doesn&#x27;t work on Tue, 12 Sep 2023 18:15:39 GMT]]></title><description><![CDATA[<p dir="auto">I need to remove from main.cpp:</p>
<pre><code>qmlRegisterType(QUrl("qrc:/MyTimer.qml"), "MyTimers", 1, 0, "MyTimer");
</code></pre>
<p dir="auto">And from main.qml:</p>
<pre><code>import MyTimers
</code></pre>
]]></description><link>https://forum.qt.io/post/772510</link><guid isPermaLink="true">https://forum.qt.io/post/772510</guid><dc:creator><![CDATA[realroot]]></dc:creator><pubDate>Tue, 12 Sep 2023 18:15:39 GMT</pubDate></item><item><title><![CDATA[Reply to Qml class doesn&#x27;t work on Tue, 12 Sep 2023 14:07:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bob64">@<bdi>Bob64</bdi></a> I added the size:</p>
<pre><code>Item {
    id: root
    property int countdownValue: 30
    property int countdown : countdownValue
    width: 600
    height: width
</code></pre>
<p dir="auto">But as before nothing is shown.<br />
And I can't set properties.</p>
]]></description><link>https://forum.qt.io/post/772491</link><guid isPermaLink="true">https://forum.qt.io/post/772491</guid><dc:creator><![CDATA[realroot]]></dc:creator><pubDate>Tue, 12 Sep 2023 14:07:41 GMT</pubDate></item><item><title><![CDATA[Reply to Qml class doesn&#x27;t work on Tue, 12 Sep 2023 12:25:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bob64">@<bdi>Bob64</bdi></a> said in <a href="/post/772467">Qml class doesn't work</a>:</p>
<blockquote>
<p dir="auto">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.</p>
</blockquote>
<p dir="auto"><code>anchors.fill</code> has the priority over <code>width</code> and <code>height</code></p>
]]></description><link>https://forum.qt.io/post/772483</link><guid isPermaLink="true">https://forum.qt.io/post/772483</guid><dc:creator><![CDATA[GrecKo]]></dc:creator><pubDate>Tue, 12 Sep 2023 12:25:50 GMT</pubDate></item><item><title><![CDATA[Reply to Qml class doesn&#x27;t work on Tue, 12 Sep 2023 10:55:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/realroot">@<bdi>realroot</bdi></a> Your <code>MyTimer</code> is defined as an <code>Item</code> which needs to have a size specified in order for it to be shown.  I am not sure what will happen with the child <code>Rectangle</code> as you are both filling the parent (whose size is 0) and setting its width and height.</p>
]]></description><link>https://forum.qt.io/post/772467</link><guid isPermaLink="true">https://forum.qt.io/post/772467</guid><dc:creator><![CDATA[Bob64]]></dc:creator><pubDate>Tue, 12 Sep 2023 10:55:46 GMT</pubDate></item></channel></rss>