<?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[Chart cannot read datas from txt]]></title><description><![CDATA[<p dir="auto">It will create a chart, but there is no data on it. Datas on my txt cannot seen on chart. How can I handle with it? Do I use another timer or am i wrong any other part of it?</p>
<pre><code>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include &lt;QFile&gt;
#include &lt;QtCharts/QLineSeries&gt;
#include &lt;QTimer&gt;
#include &lt;QTextStream&gt;
#include &lt;QtCharts&gt;
#include &lt;QChart&gt;
#include &lt;QString&gt;



QT_CHARTS_USE_NAMESPACE

using namespace QtCharts;



QLineSeries *series = new QLineSeries();
QTimer *timer = new QTimer();

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);
  connect(timer, SIGNAL(timeout()), SLOT(Timer_Slot()));

    initChartView();

}

void MainWindow::Timer_Slot(){
    QString line = allLines[curIndex];
    ui-&gt;plainTextEdit-&gt;setPlainText(line);
    if(curIndex &lt; allLines.size() -1 ) {
        curIndex++;
    }
}


MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{

    QFile file("C:/Users/ilknu/Documents/SnDeneme/deneme.txt");

    if (file.open(QIODevice::ReadOnly)) {
          QTextStream in (&amp;file);
          while (!in.atEnd()) {
          QString line = in.readLine();
          allLines.append(line);

      QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
            for(const QString &amp;entry : list) {
            double num = entry.toDouble();
            qDebug()&lt;&lt;num;
                 series-&gt;append(num, num);
                }



            }
            }
    file.close();
    curIndex=0;
    timer-&gt;start(300);
}

void MainWindow::initChartView(){



   QChart *chart = new QChart();
      chart-&gt;addSeries(series);
      chart-&gt;legend()-&gt;hide();
      chart-&gt;setTitle("deneme");

      QValueAxis *axisX = new QValueAxis();
      axisX-&gt;setTitleText("Points");
      axisX-&gt;setLabelFormat("yyyy");
      axisX-&gt;setTickCount(series-&gt;count());
      chart-&gt;addAxis(axisX, Qt::AlignBottom);
      series-&gt;attachAxis(axisX);

      QLogValueAxis *axisY = new QLogValueAxis();
      axisY-&gt;setTitleText("Values");
      axisY-&gt;setLabelFormat("%i");
      axisY-&gt;setBase(8);
      chart-&gt;addAxis(axisY, Qt::AlignLeft);
      series-&gt;attachAxis(axisY);

      QChartView *chartView = new QChartView(chart);
      chartView-&gt;setRenderHint(QPainter::Antialiasing);

      connect(series, &amp;QLineSeries::hovered, this, &amp;MainWindow::on_pushButton_clicked);
      this-&gt;setCentralWidget(chartView);

}
</code></pre>
]]></description><link>https://forum.qt.io/topic/122370/chart-cannot-read-datas-from-txt</link><generator>RSS for Node</generator><lastBuildDate>Sat, 20 Jun 2026 06:13:29 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/122370.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 Jan 2021 09:02:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Chart cannot read datas from txt on Tue, 05 Jan 2021 11:20:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> I've tried. It says Series not in the chart. Please addSeries to chart first.</p>
]]></description><link>https://forum.qt.io/post/635970</link><guid isPermaLink="true">https://forum.qt.io/post/635970</guid><dc:creator><![CDATA[deleted286]]></dc:creator><pubDate>Tue, 05 Jan 2021 11:20:13 GMT</pubDate></item><item><title><![CDATA[Reply to Chart cannot read datas from txt on Tue, 05 Jan 2021 11:10:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/suslucoder">@<bdi>suslucoder</bdi></a> Yes, inside your class declaration as private member variable...</p>
]]></description><link>https://forum.qt.io/post/635968</link><guid isPermaLink="true">https://forum.qt.io/post/635968</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Tue, 05 Jan 2021 11:10:01 GMT</pubDate></item><item><title><![CDATA[Reply to Chart cannot read datas from txt on Tue, 05 Jan 2021 11:08:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> you mean in header file, right?</p>
]]></description><link>https://forum.qt.io/post/635967</link><guid isPermaLink="true">https://forum.qt.io/post/635967</guid><dc:creator><![CDATA[deleted286]]></dc:creator><pubDate>Tue, 05 Jan 2021 11:08:58 GMT</pubDate></item><item><title><![CDATA[Reply to Chart cannot read datas from txt on Tue, 05 Jan 2021 11:03:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/suslucoder">@<bdi>suslucoder</bdi></a> said in <a href="/post/635962">Chart cannot read datas from txt</a>:</p>
<blockquote>
<p dir="auto">chart should be declared globally</p>
</blockquote>
<p dir="auto">Why do you think so?<br />
You just need to declare QChart *chart as member variable instead of a local variable in initChartView()...</p>
]]></description><link>https://forum.qt.io/post/635963</link><guid isPermaLink="true">https://forum.qt.io/post/635963</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Tue, 05 Jan 2021 11:03:24 GMT</pubDate></item><item><title><![CDATA[Reply to Chart cannot read datas from txt on Tue, 05 Jan 2021 10:58:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> for doing it chart should be declared globally. When i declared it global, it causes a crash . any options?</p>
]]></description><link>https://forum.qt.io/post/635962</link><guid isPermaLink="true">https://forum.qt.io/post/635962</guid><dc:creator><![CDATA[deleted286]]></dc:creator><pubDate>Tue, 05 Jan 2021 10:58:19 GMT</pubDate></item><item><title><![CDATA[Reply to Chart cannot read datas from txt on Tue, 05 Jan 2021 10:56:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/suslucoder">@<bdi>suslucoder</bdi></a> said in <a href="/post/635955">Chart cannot read datas from txt</a>:</p>
<blockquote>
<p dir="auto">chart-&gt;addSeries(series);</p>
</blockquote>
<p dir="auto">I think you need to do this after populating series with your data from the file.</p>
]]></description><link>https://forum.qt.io/post/635960</link><guid isPermaLink="true">https://forum.qt.io/post/635960</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Tue, 05 Jan 2021 10:56:15 GMT</pubDate></item><item><title><![CDATA[Reply to Chart cannot read datas from txt on Tue, 05 Jan 2021 10:01:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a>  chart-&gt;addSeries(series);</p>
<p dir="auto">is it wrong?</p>
]]></description><link>https://forum.qt.io/post/635955</link><guid isPermaLink="true">https://forum.qt.io/post/635955</guid><dc:creator><![CDATA[deleted286]]></dc:creator><pubDate>Tue, 05 Jan 2021 10:01:31 GMT</pubDate></item><item><title><![CDATA[Reply to Chart cannot read datas from txt on Tue, 05 Jan 2021 09:04:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/suslucoder">@<bdi>suslucoder</bdi></a> said in <a href="/post/635947">Chart cannot read datas from txt</a>:</p>
<blockquote>
<p dir="auto">qDebug()&lt;&lt;num;<br />
series-&gt;append(num, num);<br />
}</p>
</blockquote>
<p dir="auto">And where in your code do you add series to the chart?!</p>
]]></description><link>https://forum.qt.io/post/635948</link><guid isPermaLink="true">https://forum.qt.io/post/635948</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Tue, 05 Jan 2021 09:04:09 GMT</pubDate></item></channel></rss>