<?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[QtChart window disappears]]></title><description><![CDATA[<p dir="auto">Hello all,</p>
<p dir="auto">I'm trying to use the simple linechart example to work in my code.  I'm trying to get the chart window to display from within a button function that does some calculations to get the data points.  When the time comes for the chart to display, I can see it pop up and disappear almost instantly.  After a lot of reading, I think it has to do with trying to create a new QMainWindow from inside the button?  Here is my most recent code that is supposed to set up the chart window:</p>
<pre><code>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QtCharts/QChartView"
#include "QtCharts/QLineSeries"
#include "QtCharts/QLegend"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);
    //  Hide all Buttons            //
    ui-&gt;btnHeading-&gt;setVisible(false);
}
    QMainWindow *chartWindow = new QMainWindow(0);
    chartWindow-&gt;setCentralWidget(&amp;ChartView);
    chartWindow-&gt;resize(800,600);

MainWindow::~MainWindow()
{
    delete ui;
}
</code></pre>
<p dir="auto">And here is the button that is supposed to display the chart:</p>
<pre><code>void MainWindow::on_btnHeading_clicked()
{
    QLineSeries *series = new QLineSeries();

    PGNListCount = PGNList.count();
    qDebug() &lt;&lt; PGNListCount;
    for (int i=0;i&lt;PGNListCount;i++) {
        if (PGNList.at(i).contains("127250")) {
            DB21Data &lt;&lt; DB2.at(i) + (DB1.at(i));
            //graphTime &lt;&lt; timeStamp.at(i);
            }
     }

    int DB21DataCount = DB21Data.count();
    for (int i=0; i&lt;DB21DataCount;++i) {
        DB21hex = (((DB21Data.at(i).toInt(&amp;ok, 16))*0.0001)*57.296);
        series-&gt;append(i, DB21hex);
        //qDebug() &lt;&lt; series &lt;&lt; DB21hex;
    }

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

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

//        QMainWindow window;
//            window.setCentralWidget(chartView);
//            window.resize(800, 600);
            chartWindow-&gt;show();

}
</code></pre>
<p dir="auto">I've tried a few different things - this code errors on the two lines:</p>
<pre><code>chartWindow-&gt;setCentralWidget(&amp;ChartView);
    chartWindow-&gt;resize(800,600);
</code></pre>
<p dir="auto">with "chartWindow does not name a type"</p>
<p dir="auto">Any hints on how I can approach this would be much appreciated!</p>
]]></description><link>https://forum.qt.io/topic/78415/qtchart-window-disappears</link><generator>RSS for Node</generator><lastBuildDate>Sun, 17 May 2026 17:58:27 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/78415.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 19 Apr 2017 14:49:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QtChart window disappears on Fri, 21 Apr 2017 13:45:24 GMT]]></title><description><![CDATA[<p dir="auto">Aaah!  I get it!  That solved the error message.</p>
]]></description><link>https://forum.qt.io/post/389134</link><guid isPermaLink="true">https://forum.qt.io/post/389134</guid><dc:creator><![CDATA[MScottM]]></dc:creator><pubDate>Fri, 21 Apr 2017 13:45:24 GMT</pubDate></item><item><title><![CDATA[Reply to QtChart window disappears on Fri, 21 Apr 2017 13:38:10 GMT]]></title><description><![CDATA[<p dir="auto">You don't want to just call <code>setLayout()</code> in this case, you want to call <code>chartWindow-&gt;setLayout()</code> -- otherwise you are calling the member of your current object (your main window).</p>
]]></description><link>https://forum.qt.io/post/389133</link><guid isPermaLink="true">https://forum.qt.io/post/389133</guid><dc:creator><![CDATA[Chris Hennes]]></dc:creator><pubDate>Fri, 21 Apr 2017 13:38:10 GMT</pubDate></item><item><title><![CDATA[Reply to QtChart window disappears on Fri, 21 Apr 2017 13:35:59 GMT]]></title><description><![CDATA[<p dir="auto">Okay, this code:</p>
<pre><code>QChartView *chartView = new QChartView(chart);
        chartView-&gt;setRenderHint(QPainter::Antialiasing);

        QWidget * chartWindow = new QWidget(0);

        QVBoxLayout *layout = new QVBoxLayout(chartWindow);
        layout-&gt;addWidget(chartView);
        setLayout(layout);
        layout-&gt;activate();
        
        chartWindow-&gt;resize(480,320);
        chartWindow-&gt;show();
</code></pre>
<p dir="auto">opens my chart in a new window like I want, but, I get this error message in the debugger:</p>
<p dir="auto">QWidget::setLayout: Attempting to set QLayout "" on MainWindow "MainWindow", which already has a layout</p>
<p dir="auto">Also, if I close the window then click the button again, I get two charts side by side.  I'm thinking there must be some code that properly resets everything when you close the window?</p>
<p dir="auto">Thanks again for all the help!</p>
]]></description><link>https://forum.qt.io/post/389132</link><guid isPermaLink="true">https://forum.qt.io/post/389132</guid><dc:creator><![CDATA[MScottM]]></dc:creator><pubDate>Fri, 21 Apr 2017 13:35:59 GMT</pubDate></item><item><title><![CDATA[Reply to QtChart window disappears on Fri, 21 Apr 2017 04:25:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mscottm">@<bdi>MScottM</bdi></a> Just call <a href="http://doc.qt.io/qt-5/qwidget.html#show" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qwidget.html#show</a> on your dialog instead of exec()</p>
]]></description><link>https://forum.qt.io/post/388980</link><guid isPermaLink="true">https://forum.qt.io/post/388980</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Fri, 21 Apr 2017 04:25:11 GMT</pubDate></item><item><title><![CDATA[Reply to QtChart window disappears on Thu, 20 Apr 2017 20:13:34 GMT]]></title><description><![CDATA[<p dir="auto">Are you subclassing QWidget or QDialog?</p>
]]></description><link>https://forum.qt.io/post/388900</link><guid isPermaLink="true">https://forum.qt.io/post/388900</guid><dc:creator><![CDATA[Chris Hennes]]></dc:creator><pubDate>Thu, 20 Apr 2017 20:13:34 GMT</pubDate></item><item><title><![CDATA[Reply to QtChart window disappears on Thu, 20 Apr 2017 17:53:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chris-hennes">@<bdi>Chris-Hennes</bdi></a>  Thanks again - I'm struggling with how to get it into a separate window that can be closed when done, instead of displaying on top of my existing window.</p>
]]></description><link>https://forum.qt.io/post/388885</link><guid isPermaLink="true">https://forum.qt.io/post/388885</guid><dc:creator><![CDATA[MScottM]]></dc:creator><pubDate>Thu, 20 Apr 2017 17:53:56 GMT</pubDate></item><item><title><![CDATA[Reply to QtChart window disappears on Thu, 20 Apr 2017 14:29:46 GMT]]></title><description><![CDATA[<p dir="auto">YES!  Got it to display a chart with the data I want - now on to fine tuning everything.</p>
<p dir="auto">Thanks again for the hints that got me on the right track!</p>
]]></description><link>https://forum.qt.io/post/388853</link><guid isPermaLink="true">https://forum.qt.io/post/388853</guid><dc:creator><![CDATA[MScottM]]></dc:creator><pubDate>Thu, 20 Apr 2017 14:29:46 GMT</pubDate></item><item><title><![CDATA[Reply to QtChart window disappears on Thu, 20 Apr 2017 14:03:10 GMT]]></title><description><![CDATA[<p dir="auto">I typically subclass QDialog for everything. So in that case, if you are doing it by hand (rather than using Designer) you are probably looking for something like this (from the QWidget docs):</p>
<pre><code> QVBoxLayout *layout = new QVBoxLayout;
 layout-&gt;addWidget(chartView);
 setLayout(layout);
</code></pre>
]]></description><link>https://forum.qt.io/post/388850</link><guid isPermaLink="true">https://forum.qt.io/post/388850</guid><dc:creator><![CDATA[Chris Hennes]]></dc:creator><pubDate>Thu, 20 Apr 2017 14:03:10 GMT</pubDate></item><item><title><![CDATA[Reply to QtChart window disappears on Thu, 20 Apr 2017 13:38:01 GMT]]></title><description><![CDATA[<p dir="auto">Okay!  Thanks for the suggestions.  I am now able to create and show a qwidget window, now I'm working on how to put the QtChart on there...</p>
]]></description><link>https://forum.qt.io/post/388844</link><guid isPermaLink="true">https://forum.qt.io/post/388844</guid><dc:creator><![CDATA[MScottM]]></dc:creator><pubDate>Thu, 20 Apr 2017 13:38:01 GMT</pubDate></item><item><title><![CDATA[Reply to QtChart window disappears on Thu, 20 Apr 2017 04:48:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mscottm">@<bdi>MScottM</bdi></a> As "Main" in QMainWindow suggests a main window is the main window in an application (so many main :-)). That means - a Qt application can only have one QMainWindow. All other windows can be implemented using QWidget or QDialog (as <a class="plugin-mentions-user plugin-mentions-a" href="/user/chris-hennes">@<bdi>Chris-Hennes</bdi></a> suggested).</p>
]]></description><link>https://forum.qt.io/post/388777</link><guid isPermaLink="true">https://forum.qt.io/post/388777</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 20 Apr 2017 04:48:10 GMT</pubDate></item><item><title><![CDATA[Reply to QtChart window disappears on Wed, 19 Apr 2017 20:24:07 GMT]]></title><description><![CDATA[<p dir="auto">You don't want your chart in a <code>QMainWindow</code> (an app has one of those), you want it in a <code>QDialog</code>.</p>
]]></description><link>https://forum.qt.io/post/388722</link><guid isPermaLink="true">https://forum.qt.io/post/388722</guid><dc:creator><![CDATA[Chris Hennes]]></dc:creator><pubDate>Wed, 19 Apr 2017 20:24:07 GMT</pubDate></item></channel></rss>