<?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[QObject derivated Class copyable]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I found a good piece of software: <a href="https://code.google.com/p/cellardoor/" target="_blank" rel="noopener noreferrer nofollow ugc">https://code.google.com/p/cellardoor/</a><br />
It has a datamodel class winedata which inherits from qobject and uses the property functionality for interact with qml.<br />
Now the curiosity i dont understand:<br />
Line 65 in controller.cpp he instaniate the template database as type of WineData<br />
m_database(Database&lt;WineData&gt;::instance(this))<br />
But WineData inherits from QObject and the copy and assignment is private<br />
why does e.g. the function fillUpType and retrieveTypes function?</p>
<p dir="auto">I didn't get it to work.</p>
<p dir="auto"><a href="http://qt-project.org/doc/qt-5/QObject.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5/QObject.html</a><br />
Here is also mentioned to use QObject subclasses in lists only with pointers.</p>
<p dir="auto">Code copied from database.cpp line 232<br />
@<br />
template &lt;class Type&gt;<br />
Type Database&lt;Type&gt;::fillUpType(const QSqlRecord &amp;record) const<br />
{<br />
Type item;</p>
<p dir="auto">QStringList list;<br />
Utils::extractObjectProperties(item.metaObject(), &amp;list, false, DB_PREFIX);<br />
foreach (const QString &amp;property, list) {<br />
item.setProperty(qPrintable(property), record.value(QString(property).remove(DB_PREFIX)));<br />
}</p>
<p dir="auto">return item;<br />
}</p>
<p dir="auto">template &lt;class Type&gt;<br />
QList&lt;Type&gt; Database&lt;Type&gt;::retrieveTypes(Filter arg) const<br />
{<br />
QList&lt;Type&gt; wineList;</p>
<p dir="auto">if (!m_wineModel) {<br />
qCritical() &lt;&lt; "Unable to insert a wine";<br />
goto exit;<br />
}</p>
<p dir="auto">if (arg == OrderByAgeDesc) {<br />
m_wineModel-&gt;setSort(4, Qt::DescendingOrder);<br />
}<br />
m_wineModel-&gt;select();</p>
<p dir="auto">for (int i = 0; i &lt; m_wineModel-&gt;rowCount(); ++i) {<br />
const QSqlRecord record = m_wineModel-&gt;record(i);<br />
wineList &lt;&lt; fillUpType(record);<br />
}</p>
<p dir="auto">exit:<br />
return wineList;<br />
}<br />
@</p>
<p dir="auto">Greets<br />
Tobi</p>
]]></description><link>https://forum.qt.io/topic/42040/qobject-derivated-class-copyable</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 22:42:18 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/42040.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 31 May 2014 14:54:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QObject derivated Class copyable on Mon, 02 Jun 2014 22:09:37 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">However it's still wrong. He should rather have a clone function that creates a new object and then set all parameters on it. Disabling the copy of QObject is not done for nothing.</p>
]]></description><link>https://forum.qt.io/post/230775</link><guid isPermaLink="true">https://forum.qt.io/post/230775</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 02 Jun 2014 22:09:37 GMT</pubDate></item><item><title><![CDATA[Reply to QObject derivated Class copyable on Mon, 02 Jun 2014 07:25:15 GMT]]></title><description><![CDATA[<p dir="auto">I got it, its possible because he defines a new assignment and copy operator/constructor himself for the QObject derivated class.</p>
]]></description><link>https://forum.qt.io/post/230686</link><guid isPermaLink="true">https://forum.qt.io/post/230686</guid><dc:creator><![CDATA[tobias.h]]></dc:creator><pubDate>Mon, 02 Jun 2014 07:25:15 GMT</pubDate></item></channel></rss>