<?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[[SOLVED]Show qml file in qwidget]]></title><description><![CDATA[<p dir="auto">Hi ,I use qt 5.3 on mac. i want to show qml file in qwidget. look at the codes:</p>
<p dir="auto">@<br />
<a href="//mainwindow.cpp" target="_blank" rel="noopener noreferrer nofollow ugc">//mainwindow.cpp</a></p>
<p dir="auto">void MainWindow::createQMLWindow()<br />
{<br />
QQmlEngine engine;<br />
QQmlComponent <em>component = new QQmlComponent(&amp;engine);<br />
component-&gt;loadUrl(QUrl("qrc:///main.qml"));<br />
if(!component-&gt;isReady())<br />
{<br />
qDebug() &lt;&lt; "Component Error:" &lt;&lt; component-&gt;errorString();<br />
}<br />
QQuickWindow * mywin = qobject_cast&lt;QQuickWindow</em>&gt;(component-&gt;create()); //the error occures here<br />
QWidget *container = QWidget::createWindowContainer(mywin , this);<br />
setCentralWidget(container);<br />
QVBoxLayout *layout = new QVBoxLayout;<br />
container-&gt;setLayout(layout);<br />
container-&gt;setMinimumSize(200,200);<br />
container-&gt;setMaximumSize(200,200);<br />
}<br />
@</p>
<p dir="auto">when i run my program , after a few seconds,  the program crashed:<br />
this error: the program has unexpectedly finished.</p>
<p dir="auto">please help me to fix it. Thanks</p>
<p dir="auto"><em>[edit: cleaned use of coding tags SGaist]</em></p>
]]></description><link>https://forum.qt.io/topic/47441/solved-show-qml-file-in-qwidget</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 14:29:17 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/47441.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 26 Oct 2014 08:53:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED]Show qml file in qwidget on Mon, 27 Oct 2014 07:01:29 GMT]]></title><description><![CDATA[<p dir="auto">finally i found another way to use UIImagePickerController in qt5.3 (on mac) without using qml window type.I created a subclass of UIViewController in .mm file and implemented an UIImagePickerController in that and defined a cpp bridge method. So i don't need to embed a qml file in QWidget anymore.<br />
Thank you very much.</p>
]]></description><link>https://forum.qt.io/post/249095</link><guid isPermaLink="true">https://forum.qt.io/post/249095</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 27 Oct 2014 07:01:29 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED]Show qml file in qwidget on Mon, 27 Oct 2014 06:13:27 GMT]]></title><description><![CDATA[<p dir="auto">I used window type in qml because i want to use UIImagePickerController to pick an image from photo library.</p>
]]></description><link>https://forum.qt.io/post/249090</link><guid isPermaLink="true">https://forum.qt.io/post/249090</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 27 Oct 2014 06:13:27 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED]Show qml file in qwidget on Mon, 27 Oct 2014 06:10:26 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="hasti66" date="1414389434"]If i use QQuickView like you said, i get this error:</p>
<p dir="auto">QQuickView only supports loading of root objects that derive from QQuickItem.<br />
In my qml file i've used window type.[/quote]</p>
<p dir="auto">Then that is not necessary, remove Window and use Rectangle instead :-)</p>
]]></description><link>https://forum.qt.io/post/249089</link><guid isPermaLink="true">https://forum.qt.io/post/249089</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Mon, 27 Oct 2014 06:10:26 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED]Show qml file in qwidget on Mon, 27 Oct 2014 05:57:14 GMT]]></title><description><![CDATA[<p dir="auto">If i use QQuickView like you said, i get this error:</p>
<p dir="auto">QQuickView only supports loading of root objects that derive from QQuickItem.<br />
In my qml file i've used window type.</p>
]]></description><link>https://forum.qt.io/post/249088</link><guid isPermaLink="true">https://forum.qt.io/post/249088</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 27 Oct 2014 05:57:14 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED]Show qml file in qwidget on Mon, 27 Oct 2014 05:43:12 GMT]]></title><description><![CDATA[<p dir="auto">Please put your code between '@' tags here on the forum, otherwise it's hard to read.</p>
<p dir="auto">Why not use "QQuickView":<a href="http://qt-project.org/doc/qt-5/qquickview.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5/qquickview.html</a>, which is a QWindow? The code is much simpler there:<br />
@<br />
MainWindow w;<br />
QVBoxLayout *layout = new QVBoxLayout(w);<br />
w.setLayout(layout);</p>
<p dir="auto">QQuickView *view = new QQuickView;<br />
view-&gt;setSource(QUrl::fromLocalFile("myqmlfile.qml"));</p>
<p dir="auto">QWidget container *cont = QWidget::createWindowContainer(view, w);<br />
layout-&gt;addWidget(container);<br />
w.show();<br />
@</p>
]]></description><link>https://forum.qt.io/post/249087</link><guid isPermaLink="true">https://forum.qt.io/post/249087</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Mon, 27 Oct 2014 05:43:12 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED]Show qml file in qwidget on Mon, 27 Oct 2014 05:35:20 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for your answer. I've tried to move code to main.cpp, but i doesn't work.<br />
@<br />
<a href="//main.cpp" target="_blank" rel="noopener noreferrer nofollow ugc">//main.cpp</a></p>
<p dir="auto">MainWindow w;<br />
QQmlEngine engine;<br />
QQmlComponent <em>component = new QQmlComponent(&amp;engine);<br />
component-&gt;loadUrl(QUrl("qrc:///main.qml"));<br />
if(!component-&gt;isReady())<br />
{<br />
qDebug() &lt;&lt; "Component Error:" &lt;&lt; component-&gt;errorString();<br />
}<br />
QQuickWindow * mywin = qobject_cast&lt;QQuickWindow</em>&gt;(component-&gt;create());<br />
w.createQMLWindow();<br />
w.show();</p>
<pre><code>//mainwindow.cpp
 
void MainWindow::createQMLWindow(QQuickWindow * mywin)
{  
  QWidget *container = QWidget::createWindowContainer(mywin , this);
  setCentralWidget(container);
  QVBoxLayout *layout = new QVBoxLayout;
  container-&gt;setLayout(layout);
  container-&gt;setMinimumSize(200,200);
  container-&gt;setMaximumSize(200,200);
}
</code></pre>
<p dir="auto">@</p>
]]></description><link>https://forum.qt.io/post/249086</link><guid isPermaLink="true">https://forum.qt.io/post/249086</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 27 Oct 2014 05:35:20 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED]Show qml file in qwidget on Sun, 26 Oct 2014 18:17:53 GMT]]></title><description><![CDATA[<p dir="auto"><em>engine</em> is deleted when createQMLWindow() goes out of scope - maybe that is the problem.</p>
]]></description><link>https://forum.qt.io/post/249029</link><guid isPermaLink="true">https://forum.qt.io/post/249029</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Sun, 26 Oct 2014 18:17:53 GMT</pubDate></item></channel></rss>