<?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[Registering a type makes the QML code not work]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I am working on something where I have a class called "FloatingMenu" (that is supossed to manage a menu in C++) and its QML alter-ego for the GUI in a file FloatingMenu.qml.<br />
I have a file main.qml where I have a few rectangles and a FloatingMenu, and it shows up as expected.<br />
Now, if I do qmlRegisterType&lt;FloatingMenu&gt;("EasyGraph", 1,0, "FloatingMenu"); in my main.cpp, the graphical part of the FloatingMenu juts desappears.</p>
<p dir="auto">Here is my code:</p>
<p dir="auto">@int main(int argc, char* argv[]){</p>
<p dir="auto">QGuiApplication app(argc, argv);</p>
<p dir="auto">//Register all the needed types in QML.<br />
qmlRegisterType&lt;FloatingMenu&gt;("EasyGraph", 1,0, "FloatingMenu");</p>
<p dir="auto">//The only window known as QDeCView in QML.<br />
QQuickView* view = new QQuickView();<br />
view-&gt;setMinimumHeight(100);<br />
view-&gt;setMinimumWidth(100);<br />
view-&gt;setResizeMode(QQuickView::SizeRootObjectToView);</p>
<p dir="auto">//Context, to set properties from c++ to QML<br />
//QQmlContext* cxt =  view-&gt;rootContext();</p>
<p dir="auto">//Load the base.<br />
view-&gt;setSource(QUrl::fromLocalFile("../qml/MainWindow.qml"));<br />
view-&gt;show();</p>
<p dir="auto">//FloatingMenu* menu = view-&gt;rootObject()-&gt;findChild&lt;FloatingMenu*&gt;("mainMenu"); //When registered, this works</p>
<p dir="auto">return app.exec();<br />
}<br />
@</p>
<p dir="auto">and:<br />
@#ifndef <em>FLOATINGMENU_H</em><br />
#define <em>FLOATINGMENU_H</em></p>
<p dir="auto">#include &lt;QQuickItem&gt;<br />
#include "GraphicalNode.hpp"</p>
<p dir="auto">class FloatingMenu : public QQuickItem {<br />
Q_OBJECT<br />
Q_PROPERTY(GraphicalNode* target READ target WRITE setTarget NOTIFY onTargetNodeChanged)<br />
private:<br />
GraphicalNode* _target;<br />
public:<br />
FloatingMenu(QQuickItem* p = NULL);<br />
GraphicalNode* target() const;<br />
void setTarget(GraphicalNode* n);</p>
<p dir="auto">signals:<br />
void onTargetNodeChanged(GraphicalNode*);<br />
};</p>
<p dir="auto">#endif</p>
<p dir="auto">#include "FloatingMenu.hpp"</p>
<p dir="auto">FloatingMenu::FloatingMenu(QQuickItem* p) : QQuickItem(p), _target(NULL){<br />
setFlag(QQuickItem::ItemHasContents, false); //I tried true and false here. what should it be? It has content, but I don't want to draw it from the C++ side.<br />
}</p>
<p dir="auto">GraphicalNode* FloatingMenu::target() const {<br />
return _target;<br />
}</p>
<p dir="auto">void FloatingMenu::setTarget(GraphicalNode* n) {<br />
_target = n;<br />
}</p>
<p dir="auto">@<br />
my MainWindow.qml:<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/import">@<bdi>import</bdi></a> EasyGraph 1.0<br />
import QtQuick 2.0</p>
<p dir="auto">Rectangle {<br />
width: 400; height: 400<br />
color: "#333333"</p>
<p dir="auto">Flickable {<br />
id: flickable<br />
anchors.fill: parent<br />
width: 400; height: 400</p>
<p dir="auto">FloatingMenu{<br />
objectName: "mainMenu"<br />
id: menu<br />
}</p>
<p dir="auto">}</p>
<p dir="auto">}@<br />
and finally, FloatingMenu.qml:<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/import">@<bdi>import</bdi></a> EasyGraph 1.0<br />
import QtQuick 2.0</p>
<p dir="auto">Rectangle {<br />
width: 30; height: 30<br />
color: "red"<br />
}@</p>
<p dir="auto">I have no idea what I am doing wrong, I dont see how its not working!<br />
The only think I want to do is to bind a QML object with a class and let the QML be the drawing part... I guess I am missing a little option or something...</p>
]]></description><link>https://forum.qt.io/topic/40250/registering-a-type-makes-the-qml-code-not-work</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 14:01:59 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/40250.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 13 Apr 2014 17:18:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Registering a type makes the QML code not work on Sun, 13 Apr 2014 18:12:42 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Dot97.<br />
I tried what you said, but it didn't work... (I remaned everything in QML to FloatingMenuQML).. I think it is ok to have that with two names....<br />
So I still have the problem...</p>
<p dir="auto">Thanks again anyway!</p>
]]></description><link>https://forum.qt.io/post/223214</link><guid isPermaLink="true">https://forum.qt.io/post/223214</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sun, 13 Apr 2014 18:12:42 GMT</pubDate></item><item><title><![CDATA[Reply to Registering a type makes the QML code not work on Sun, 13 Apr 2014 18:05:47 GMT]]></title><description><![CDATA[<p dir="auto">Oh, I think I found the mistake:<br />
You have a FloatingMenu.qml and then you call:<br />
@qmlRegisterType&lt;FloatingMenu&gt;("EasyGraph", 1,0, "FloatingMenu");<br />
@<br />
Don't you have two types with the same name then?! ;)</p>
<p dir="auto">Regards</p>
]]></description><link>https://forum.qt.io/post/223213</link><guid isPermaLink="true">https://forum.qt.io/post/223213</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sun, 13 Apr 2014 18:05:47 GMT</pubDate></item><item><title><![CDATA[Reply to Registering a type makes the QML code not work on Sun, 13 Apr 2014 18:00:03 GMT]]></title><description><![CDATA[<p dir="auto">Hi, thanks for your answer.<br />
There is no output (no error messages or anything).<br />
I forgo to post my main.qml code. I just updated my previous post! :)</p>
]]></description><link>https://forum.qt.io/post/223212</link><guid isPermaLink="true">https://forum.qt.io/post/223212</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sun, 13 Apr 2014 18:00:03 GMT</pubDate></item><item><title><![CDATA[Reply to Registering a type makes the QML code not work on Sun, 13 Apr 2014 17:43:04 GMT]]></title><description><![CDATA[<p dir="auto">Can you show the application output pls?!<br />
Most often you can find the mistake there! ;)</p>
<p dir="auto">Regards</p>
]]></description><link>https://forum.qt.io/post/223211</link><guid isPermaLink="true">https://forum.qt.io/post/223211</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sun, 13 Apr 2014 17:43:04 GMT</pubDate></item></channel></rss>