<?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[Passing a vector as function argument]]></title><description><![CDATA[<p dir="auto">Apologies if this is the wrong place but;<br />
When defining a QVecotr with:</p>
<pre><code>QVector&lt;double&gt; x(temp),y(temp);
</code></pre>
<p dir="auto">How can I place this into a functions paramater definition?:</p>
<pre><code>void MainWindow::plotGraph(int selectedIndex, QVector&lt;double&gt; x,y)
</code></pre>
<p dir="auto">As the x,y is causing a problem due to the comma.</p>
]]></description><link>https://forum.qt.io/topic/142001/passing-a-vector-as-function-argument</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 21:30:35 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/142001.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 06 Jan 2023 11:52:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Passing a vector as function argument on Fri, 06 Jan 2023 11:55:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sorton">@<bdi>SOrton</bdi></a> said in <a href="/post/742775">Passing a vector as function argument</a>:</p>
<blockquote>
<p dir="auto">As the x,y is causing a problem due to the comma.</p>
</blockquote>
<p dir="auto">Because you don't assign a type for y - in a function call you can't use the shortcut as for a definition and have to properly define all parameters.</p>
]]></description><link>https://forum.qt.io/post/742776</link><guid isPermaLink="true">https://forum.qt.io/post/742776</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Fri, 06 Jan 2023 11:55:36 GMT</pubDate></item><item><title><![CDATA[Reply to Passing a vector as function argument on Fri, 06 Jan 2023 12:35:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sorton">@<bdi>SOrton</bdi></a> said in <a href="/post/742775">Passing a vector as function argument</a>:</p>
<blockquote>
<p dir="auto">QVector&lt;double&gt; x(temp),y(temp);</p>
<p dir="auto">How can I place this into a functions paramater definition?:<br />
void MainWindow::plotGraph(int selectedIndex, QVector&lt;double&gt; x,y)</p>
</blockquote>
<p dir="auto">Ok First thing.  You need to create a "using" or "typedef" declaration for your container, as an alias when refering to the type later in your code</p>
<p dir="auto">using MY_VEC = QVector&lt;double&gt;;</p>
<p dir="auto">MY_VEC v1(27U);<br />
MY_VEC v2 = { 0.0, 1.0, 37.555 };<br />
void someFunction(MY_VEC&amp; v) { v.clear(); }<br />
someFunction(v2);</p>
<p dir="auto">Finally, don't put multiple variable declarations on the same line.  It's considered bad form by most modern coding standards.</p>
]]></description><link>https://forum.qt.io/post/742783</link><guid isPermaLink="true">https://forum.qt.io/post/742783</guid><dc:creator><![CDATA[Kent-Dorfman]]></dc:creator><pubDate>Fri, 06 Jan 2023 12:35:15 GMT</pubDate></item><item><title><![CDATA[Reply to Passing a vector as function argument on Fri, 06 Jan 2023 11:56:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sorton">@<bdi>SOrton</bdi></a><br />
void MainWindow::plotGraph(int selectedIndex, QVector&lt;double&gt; x, QVector&lt;double&gt;y);</p>
<p dir="auto">preferably<br />
void MainWindow::plotGraph(int selectedIndex, const QVector&lt;double&gt; &amp;x, const QVector&lt;double&gt; &amp;y);</p>
]]></description><link>https://forum.qt.io/post/742777</link><guid isPermaLink="true">https://forum.qt.io/post/742777</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Fri, 06 Jan 2023 11:56:10 GMT</pubDate></item><item><title><![CDATA[Reply to Passing a vector as function argument on Fri, 06 Jan 2023 11:55:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sorton">@<bdi>SOrton</bdi></a> said in <a href="/post/742775">Passing a vector as function argument</a>:</p>
<blockquote>
<p dir="auto">As the x,y is causing a problem due to the comma.</p>
</blockquote>
<p dir="auto">Because you don't assign a type for y - in a function call you can't use the shortcut as for a definition and have to properly define all parameters.</p>
]]></description><link>https://forum.qt.io/post/742776</link><guid isPermaLink="true">https://forum.qt.io/post/742776</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Fri, 06 Jan 2023 11:55:36 GMT</pubDate></item></channel></rss>