Nominate our 2022 Qt Champions!

Adding points to a QLineSeries - nothing displayed on chart

  • I'm working in widget space. I create a chart, it shows up with default axes on my GUI. I also create a QLineSeries and assign it to the chart. Later, as data rolls in, I add points to the QLineSeries. But nothing shows up. No line is created. Here is source for instantiating, followed by slot handler source for updating. You can see i rely on QT built in promotion to convert data to qreal.

    void SxDiagTECVerificationView::mCreateTemperatureChart()
    QHBoxLayout* chartLayout = new QHBoxLayout(m_testUI.grpTEC_Chart);
    m_temperatureChart = new QChart();
    m_temperatureChartView = new QChartView(m_temperatureChart);
    m_temperatureLineSeries = new QLineSeries();

    void SxDiagTECVerificationView::on_timeAndTemperatureUpdate(float temperature, unsigned int elapsedTimeMsec)
    m_temperatureLineSeries->append(elapsedTimeMsec, temperature);

  • I figured it out. You must instantiate the line series with a reference to the chart. It is not enough to simply add the series to the chart. I believe that is the fix that finally worked.

Log in to reply