<?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 change QVector to QString]]></title><description><![CDATA[<p dir="auto">My paint project need save and read DashPattern.</p>
<p dir="auto">Basic use:<br />
QVector&lt;qreal&gt; pattern { 5,5 };<br />
pen.setDashPattern(pattern);</p>
<p dir="auto">QVector to QString needed:<br />
settings.setValue("DashPattern", pattern);</p>
<p dir="auto">QString to QVector needed:<br />
QVector&lt;qreal&gt; pattern = settings.value(("DashPattern", "{ 5,5 }";</p>
]]></description><link>https://forum.qt.io/topic/155065/how-to-change-qvector-to-qstring</link><generator>RSS for Node</generator><lastBuildDate>Fri, 05 Jun 2026 06:31:53 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/155065.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 Mar 2024 05:11:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to change QVector to QString on Wed, 06 Mar 2024 10:29:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sonichy">@<bdi>sonichy</bdi></a><br />
What is your actual question/problem?  If you have a list of numbers (integers or floats) and you want to save it to settings as a string and restore it as a list of numbers, and for some reason you don't want to do it via a <code>QVariant</code> like <a class="plugin-mentions-user plugin-mentions-a" href="/user/chrisw67">@<bdi>ChrisW67</bdi></a> suggested, (is that what you want?) you need to:</p>
<ul>
<li>To save, you need to <em>iterate</em> the list calling <code>QString::number()</code> on each one to build up a comma (or other character)-separated string, then pass that to settings.</li>
<li>To restore, you need to call <code>QString.split()</code> to split the string into items and call <code>QString::toInt</code>/<code>Float()</code> on each one to convert back to numbers.</li>
</ul>
<p dir="auto">Of course, if you have the numbers stored as a separated <em>string</em> in your text edit or elsewhere and you only want to deal with that then you don't need to do joining/splitting/converting from/to numbers.</p>
<p dir="auto"><strong>UPDATE</strong></p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sonichy">@<bdi>sonichy</bdi></a> said in <a href="/post/792283">How to change QVector to QString</a>:</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mpergand">@<bdi>mpergand</bdi></a> I accept your code</p>
</blockquote>
<p dir="auto">You have gone back and changed your post to say "I accept your code" now, maybe you mean you have no problem, I don't know.</p>
]]></description><link>https://forum.qt.io/post/792289</link><guid isPermaLink="true">https://forum.qt.io/post/792289</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 06 Mar 2024 10:29:26 GMT</pubDate></item><item><title><![CDATA[Reply to How to change QVector to QString on Wed, 06 Mar 2024 09:51:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mpergand">@<bdi>mpergand</bdi></a> I accept your code<br />
<a href="https://gitlink.org.cn/sonichy/HTYPaint/commits/a3275f0062" target="_blank" rel="noopener noreferrer nofollow ugc">https://gitlink.org.cn/sonichy/HTYPaint/commits/a3275f0062</a></p>
]]></description><link>https://forum.qt.io/post/792283</link><guid isPermaLink="true">https://forum.qt.io/post/792283</guid><dc:creator><![CDATA[sonichy]]></dc:creator><pubDate>Wed, 06 Mar 2024 09:51:25 GMT</pubDate></item><item><title><![CDATA[Reply to How to change QVector to QString on Tue, 05 Mar 2024 17:57:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sonichy">@<bdi>sonichy</bdi></a> said in <a href="/post/792194">How to change QVector to QString</a>:</p>
<blockquote>
<p dir="auto">how to change the dash value ? So I need QLineEdit and QVector QString exchange.</p>
</blockquote>
<p dir="auto">You can create a float vector like this:</p>
<pre><code>QString text="1.2, 2.4, 5.75, 10.25";
QStringList list=text.split(',');
QVector&lt;float&gt; fVec;

for(QString&amp; s : list) fVec&lt;&lt;s.toFloat();
	
qDebug()&lt;&lt;fVec;  // --&gt; QVector(1.2, 2.4, 5.75, 10.25)
</code></pre>
]]></description><link>https://forum.qt.io/post/792203</link><guid isPermaLink="true">https://forum.qt.io/post/792203</guid><dc:creator><![CDATA[mpergand]]></dc:creator><pubDate>Tue, 05 Mar 2024 17:57:28 GMT</pubDate></item><item><title><![CDATA[Reply to How to change QVector to QString on Tue, 05 Mar 2024 16:42:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chrisw67">@<bdi>ChrisW67</bdi></a> How to change the dash value ? So I need QLineEdit and QVector QString exchange.</p>
]]></description><link>https://forum.qt.io/post/792194</link><guid isPermaLink="true">https://forum.qt.io/post/792194</guid><dc:creator><![CDATA[sonichy]]></dc:creator><pubDate>Tue, 05 Mar 2024 16:42:08 GMT</pubDate></item><item><title><![CDATA[Reply to How to change QVector to QString on Tue, 05 Mar 2024 11:32:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sonichy">@<bdi>sonichy</bdi></a> said in <a href="/post/792135">How to change QVector to QString</a>:</p>
<blockquote>
<p dir="auto">I need set the value by QLineEdit:</p>
</blockquote>
<p dir="auto">Why?</p>
<p dir="auto">If you are using Qt6 then:</p>
<pre><code>QVector&lt;qreal&gt; pattern { 5,5 };
constexpr auto PatternKey = QLatin1String("DashPattern");
settings.setValue(PatternKey, QVariant::fromValue(pattern));
</code></pre>
<p dir="auto">will save something to QSettings that can be restored using:</p>
<pre><code>auto pattern = settings.value(PatternKey).value&lt;QVector&lt;qreal&gt;&gt;();
</code></pre>
<p dir="auto">If the QSetting backing store is an INI file then it might look like this:</p>
<pre><code>$ cat test.ini 
[General]
DashPattern=@Variant(\0\0\0\x7f\0\0\0\xeQList&lt;double&gt;\0\0\0\0\x2@\x14\0\0\0\0\0\0@\x14\0\0\0\0\0\0)
</code></pre>
<p dir="auto">but you really do not need to worry about that.</p>
]]></description><link>https://forum.qt.io/post/792141</link><guid isPermaLink="true">https://forum.qt.io/post/792141</guid><dc:creator><![CDATA[ChrisW67]]></dc:creator><pubDate>Tue, 05 Mar 2024 11:32:32 GMT</pubDate></item><item><title><![CDATA[Reply to How to change QVector to QString on Tue, 05 Mar 2024 11:21:07 GMT]]></title><description><![CDATA[<p dir="auto">Code you wrote now is correct but seems unrelated to the original question, I am confused.</p>
]]></description><link>https://forum.qt.io/post/792137</link><guid isPermaLink="true">https://forum.qt.io/post/792137</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Tue, 05 Mar 2024 11:21:07 GMT</pubDate></item><item><title><![CDATA[Reply to How to change QVector to QString on Tue, 05 Mar 2024 11:06:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> I need set the value by QLineEdit:<br />
settings.setValue("DashPattern", lineEdit-&gt;text());</p>
]]></description><link>https://forum.qt.io/post/792135</link><guid isPermaLink="true">https://forum.qt.io/post/792135</guid><dc:creator><![CDATA[sonichy]]></dc:creator><pubDate>Tue, 05 Mar 2024 11:06:35 GMT</pubDate></item><item><title><![CDATA[Reply to How to change QVector to QString on Tue, 05 Mar 2024 06:11:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sonichy">@<bdi>sonichy</bdi></a> "settings" are QSettings? You don't need to change this to QString, you need a QVariant.</p>
<pre><code>constexpr auto PatternKey = QLatin1String("DashPattern");
settings.setValue(PatternKey, QVariant::fromValue(pattern));
// ...
auto pattern = settings.value(PatternKey).value&lt;QVector&lt;qreal&gt;&gt;();
</code></pre>
]]></description><link>https://forum.qt.io/post/792110</link><guid isPermaLink="true">https://forum.qt.io/post/792110</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Tue, 05 Mar 2024 06:11:40 GMT</pubDate></item></channel></rss>