<?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[How to make a QVector of a class usable for ui?]]></title><description><![CDATA[<p dir="auto">First things first: I'm very new in Qt, so it definately can be a stupid question.<br />
I tried to make a QVector that contains Objects of a specific class. Problem here:</p>
<ol>
<li>I cant append dinamically new items (or I am just too stupid) like</li>
</ol>
<pre><code>myVector.append( new myClass(this) );
</code></pre>
<ol start="2">
<li>I cant use the items from the QVector to setup ui like this:</li>
</ol>
<pre><code>ui-&gt;myGraph-&gt;addTab( myVector.last(), "xyz" );
</code></pre>
<p dir="auto">(I also tried to do this stuff with a QVector of pointers etc. but I just got more problems)</p>
<p dir="auto">Any Ideas?<br />
Thanks for answers!</p>
]]></description><link>https://forum.qt.io/topic/81793/how-to-make-a-qvector-of-a-class-usable-for-ui</link><generator>RSS for Node</generator><lastBuildDate>Tue, 09 Jun 2026 02:59:00 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/81793.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 28 Jul 2017 06:50:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to make a QVector of a class usable for ui? on Fri, 28 Jul 2017 08:26:39 GMT]]></title><description><![CDATA[<p dir="auto">Ok, thank you all!<br />
So, as you told me, I just had to use pointers.<br />
When I useed normal objects (no pointers), I was not able to add the new item to the vector and use it as widget for the new tab.<br />
The tab takes pointers, I'm sorry, I didn't see that (but, yup it makes sense).<br />
So now, it looks like:</p>
<pre><code>QVector&lt;myClass*&gt; myClasses;
myClass *testMyClass = new myClass(this);
myClasses-&gt;append(testMyClass);
ui-&gt;Graph-&gt;addTab( myClasses.last(), "xyz");
</code></pre>
<p dir="auto">and it works yaay!<br />
Thanks for all answers!</p>
]]></description><link>https://forum.qt.io/post/407266</link><guid isPermaLink="true">https://forum.qt.io/post/407266</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Fri, 28 Jul 2017 08:26:39 GMT</pubDate></item><item><title><![CDATA[Reply to How to make a QVector of a class usable for ui? on Fri, 28 Jul 2017 08:08:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/niagarer">@<bdi>Niagarer</bdi></a> said in <a href="/post/407252">How to make a QVector of a class usable for ui?</a>:</p>
<blockquote>
<p dir="auto">myVector is a vector of myClass objects</p>
</blockquote>
<p dir="auto">then why are you trying to append pointers?<br />
It should be:</p>
<pre><code>QVector&lt;QWidget*&gt; myVector;
</code></pre>
<p dir="auto">as @J-Hilk said.<br />
Be aware that you should really use pointers as QObjects are not copyable.</p>
]]></description><link>https://forum.qt.io/post/407257</link><guid isPermaLink="true">https://forum.qt.io/post/407257</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Fri, 28 Jul 2017 08:08:38 GMT</pubDate></item><item><title><![CDATA[Reply to How to make a QVector of a class usable for ui? on Fri, 28 Jul 2017 08:08:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/niagarer">@<bdi>Niagarer</bdi></a><br />
hi<br />
With Widgets the vector must be pointers.<br />
Just as both <a class="plugin-mentions-user plugin-mentions-a" href="/user/artwaw">@<bdi>artwaw</bdi></a>  and @J-Hilk shows</p>
<p dir="auto">You cannot store the actual widget in the list. must be with new and pointer.</p>
]]></description><link>https://forum.qt.io/post/407256</link><guid isPermaLink="true">https://forum.qt.io/post/407256</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 28 Jul 2017 08:08:30 GMT</pubDate></item><item><title><![CDATA[Reply to How to make a QVector of a class usable for ui? on Fri, 28 Jul 2017 08:03:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a><br />
Yes, I'm sorry.<br />
myVector is a vector of myClass objects.<br />
myClass is a custom QWidget Class.<br />
I want to create a new object of myClass when I add a new tab in the window and store it in the QVector.</p>
]]></description><link>https://forum.qt.io/post/407252</link><guid isPermaLink="true">https://forum.qt.io/post/407252</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Fri, 28 Jul 2017 08:03:11 GMT</pubDate></item><item><title><![CDATA[Reply to How to make a QVector of a class usable for ui? on Fri, 28 Jul 2017 08:06:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/niagarer">@<bdi>Niagarer</bdi></a> you haven't jet shown us, how you create/define your QVector.</p>
<p dir="auto">something like this:</p>
<pre><code>QVector&lt;QWidget*&gt; myVector;

QWidget *w = new QWidget(..);
myVector.append(w);
</code></pre>
<p dir="auto">defenitly work.</p>
]]></description><link>https://forum.qt.io/post/407251</link><guid isPermaLink="true">https://forum.qt.io/post/407251</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Fri, 28 Jul 2017 08:06:34 GMT</pubDate></item><item><title><![CDATA[Reply to How to make a QVector of a class usable for ui? on Fri, 28 Jul 2017 07:58:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/artwaw">@<bdi>artwaw</bdi></a><br />
Thanks for the answer!<br />
The problem here is, that I want to add new items dynamically. When I click a button, it should add a new item.<br />
because of that, I tried to do it the way I showed above (with no specific name, because I dont want to change an existing item, I want to create a new one).</p>
<p dir="auto">But I still can not append it to my vector. it says:</p>
<pre><code>error: no matching function for call to 'QVector&lt;myClass&gt;::append(myClass*&amp;)'
myClasses.append(testMyClass);
</code></pre>
<p dir="auto">The second problem is, that it says</p>
<pre><code>error: no matching function for call to 'QTabWidget::addTab(myClass&amp;, QString&amp;)'
ui-&gt;Graph-&gt;addTab(myClasses.last(), "xyz");
</code></pre>
<p dir="auto">when I try to use the last item of myClasses to set the widget (myClass is a widgetClass) of a new tab.</p>
<p dir="auto"><em>Kind Regards!</em></p>
]]></description><link>https://forum.qt.io/post/407250</link><guid isPermaLink="true">https://forum.qt.io/post/407250</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Fri, 28 Jul 2017 07:58:09 GMT</pubDate></item><item><title><![CDATA[Reply to How to make a QVector of a class usable for ui? on Fri, 28 Jul 2017 07:36:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/niagarer">@<bdi>Niagarer</bdi></a> You should show more code: what is myVector exactly?<br />
"I cant append dinamically new items (or I am just too stupid) like" - what exactly is the problem/error?</p>
]]></description><link>https://forum.qt.io/post/407243</link><guid isPermaLink="true">https://forum.qt.io/post/407243</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Fri, 28 Jul 2017 07:36:51 GMT</pubDate></item><item><title><![CDATA[Reply to How to make a QVector of a class usable for ui? on Fri, 28 Jul 2017 07:27:10 GMT]]></title><description><![CDATA[<p dir="auto">Hi.<br />
You can store pointers to objects this way. In example:</p>
<pre><code>MyClass *myObj = new MyClass(this);
myVector.append(myObj);
</code></pre>
<p dir="auto">However the question is: what exactly would you like to get from 2)? I mean - what's your use case?</p>
]]></description><link>https://forum.qt.io/post/407239</link><guid isPermaLink="true">https://forum.qt.io/post/407239</guid><dc:creator><![CDATA[artwaw]]></dc:creator><pubDate>Fri, 28 Jul 2017 07:27:10 GMT</pubDate></item></channel></rss>