<?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[Create component from C++]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I have been trying to create qml component from C++, I created it sucessfully, but it did not appear in window.</p>
<p dir="auto">Thanks in advance</p>
<p dir="auto">main.qml</p>
<pre><code>Rectangle {
    color: "white"
}
</code></pre>
<p dir="auto">MyRect.qml</p>
<pre><code>Rectangle {
    width: 100
    height: 100
    color: "red"
}
</code></pre>
<p dir="auto">main.cpp</p>
<pre><code class="language-cpp">#include &lt;QQuickWidget&gt;
#include &lt;QQmlEngine&gt;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QQuickWidget *quickWidget = new QQuickWidget;
    quickWidget-&gt;setResizeMode(QQuickWidget::SizeRootObjectToView);
    quickWidget-&gt;resize(1200, 700);
    quickWidget-&gt;setSource(QStringLiteral("qrc:/main.qml"));

    quickWidget-&gt;show();

    QQmlComponent component(quickWidget-&gt;engine(), QUrl("qrc:/MyRect.qml"));
    qDebug() &lt;&lt; component.create(quickWidget-&gt;rootContext());
    return app.exec();
}
</code></pre>
]]></description><link>https://forum.qt.io/topic/60313/create-component-from-c</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 23:05:55 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/60313.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Nov 2015 17:38:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Create component from C++ on Tue, 03 Nov 2015 21:48:31 GMT]]></title><description><![CDATA[<p dir="auto">Solved by setting object parentItem</p>
]]></description><link>https://forum.qt.io/post/296491</link><guid isPermaLink="true">https://forum.qt.io/post/296491</guid><dc:creator><![CDATA[Zondar]]></dc:creator><pubDate>Tue, 03 Nov 2015 21:48:31 GMT</pubDate></item></channel></rss>