<?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[add line x in the QFile (text file )]]></title><description><![CDATA[<p dir="auto">Hi guys,<br />
my problem is , i want to write (add)  a QString in a file ( text file ) in line x without losing the other lines<br />
for exemple my text file contains 200 lines , i want to add "hello world" in line 150 (so the file will contains 201 lines )<br />
I tried with file.write() but it always add in the last position of the text file</p>
<p dir="auto">Someone can help me ? thanks</p>
]]></description><link>https://forum.qt.io/topic/101550/add-line-x-in-the-qfile-text-file</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 06:45:10 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/101550.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 08 Apr 2019 13:48:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to add line x in the QFile (text file ) on Tue, 09 Apr 2019 07:57:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> ok thank you</p>
]]></description><link>https://forum.qt.io/post/522023</link><guid isPermaLink="true">https://forum.qt.io/post/522023</guid><dc:creator><![CDATA[Zunneh]]></dc:creator><pubDate>Tue, 09 Apr 2019 07:57:48 GMT</pubDate></item><item><title><![CDATA[Reply to add line x in the QFile (text file ) on Mon, 08 Apr 2019 14:10:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zunneh">@<bdi>Zunneh</bdi></a><br />
This question gets asked many times :)</p>
<p dir="auto">You cannot do this just by e.g. <code>write</code>, that will either append or overwrite depending on how you opened the file.</p>
<p dir="auto">You wish to <em>insert</em> a line in the middle, moving everything else "downward".  You can only do this one of two ways:</p>
<ol>
<li>
<p dir="auto">Read whole file into memory array/list, insert line, write whole array/list back to file.</p>
</li>
<li>
<p dir="auto">Open existing file for read line at a time, open new, distinct file for output line at a time, loop reading/writing, insert extra line into output at appropriate point.  On successful conclusion, delete original file, rename new file to old file.  Personally I like this way (no memory usage, no potential "partial overwrite" of file), though #1 is less code to write.</p>
</li>
</ol>
]]></description><link>https://forum.qt.io/post/521873</link><guid isPermaLink="true">https://forum.qt.io/post/521873</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 08 Apr 2019 14:10:01 GMT</pubDate></item></channel></rss>