<?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[Random lines in QFile]]></title><description><![CDATA[<p dir="auto">Hello guys. Here we go again...</p>
<p dir="auto">I have a Text File and I'm reading from him 3 lines.</p>
<pre><code> QFile file(":/sources/expenses.txt");
    {
        if (file.open(QIODevice::ReadOnly | QIODevice::Text))
        {
            QTextStream in(&amp;file);
            in.setCodec("UTF-8");

            while(!in.atEnd())
            {
                ui-&gt;DrawTitle-&gt;setText(in.readLine());
                ui-&gt;DrawDescrip-&gt;setText(in.readLine());
                ui-&gt;DrawCash-&gt;setText(in.readLine());
            }

            file.close();
        }
    }
</code></pre>
<p dir="auto">I want to read three other, random lines every use of this function.  For example:</p>
<pre><code>//TEXT FILE
1 line
2 line
3 line
4 line 
5 line
6 line
</code></pre>
<p dir="auto">Running the read function reads first lines  (1 line, 2 line, 3 line) and other one time she reads (4 line, 5 line, 6 line) e.t.c</p>
<p dir="auto">Can you help me?</p>
]]></description><link>https://forum.qt.io/topic/122674/random-lines-in-qfile</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 20:45:55 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/122674.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 13 Jan 2021 15:43:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Random lines in QFile on Wed, 13 Jan 2021 16:14:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/naax">@<bdi>naax</bdi></a> If all lines have the same length you can use <a href="https://doc.qt.io/qt-5/qfiledevice.html#seek" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qfiledevice.html#seek</a> to go to the line you want to read.<br />
Or you simply read whole file into a QStringList where each line is a string, then you can access the lines like you want.</p>
]]></description><link>https://forum.qt.io/post/637751</link><guid isPermaLink="true">https://forum.qt.io/post/637751</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 13 Jan 2021 16:14:54 GMT</pubDate></item><item><title><![CDATA[Reply to Random lines in QFile on Wed, 13 Jan 2021 16:30:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a></p>
<p dir="auto">I'll try this. Thanks</p>
]]></description><link>https://forum.qt.io/post/637755</link><guid isPermaLink="true">https://forum.qt.io/post/637755</guid><dc:creator><![CDATA[naax]]></dc:creator><pubDate>Wed, 13 Jan 2021 16:30:41 GMT</pubDate></item><item><title><![CDATA[Reply to Random lines in QFile on Wed, 13 Jan 2021 16:14:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/naax">@<bdi>naax</bdi></a> If all lines have the same length you can use <a href="https://doc.qt.io/qt-5/qfiledevice.html#seek" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qfiledevice.html#seek</a> to go to the line you want to read.<br />
Or you simply read whole file into a QStringList where each line is a string, then you can access the lines like you want.</p>
]]></description><link>https://forum.qt.io/post/637751</link><guid isPermaLink="true">https://forum.qt.io/post/637751</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 13 Jan 2021 16:14:54 GMT</pubDate></item></channel></rss>