Important: Please read the Qt Code of Conduct -

QChart axisX actualized DateTime

  • Hi,
    axisX shows 08:21 18.01.70 only, I would to show actualized DT on axisX. axisY Value type work properly, code:

    QLineSeries *sData = new QLineSeries();
    QDateTime actualDateTime =  QDateTime::currentDateTime();
    sData->append(actualDateTime.toSecsSinceEpoch(),tepl01.toFloat());//toMsecSinceEpoch() do overflow variable and shows nothing
    QChart *tempChart = new QChart();
    tempChart->setTitle("Ser data");
    tempChart->createDefaultAxes();//not work without this
    QDateTimeAxis *axisX = new QDateTimeAxis;
    axisX->setFormat("hh:mm dd.MMM.yy");
    //tempChart->addAxis(axisX, Qt::AlignBottom);//shows seconds from epoch only, not DateTime format
    tempChart->setAxisX(axisX, sData);
    QValueAxis *axisY = new QValueAxis;
    axisY->setTitleText("Serial data");

    // tempChart->addAxis(axisY, Qt::AlignLeft);
    tempChart->setAxisY(axisY, sData);

    QChartView *showChart = new QChartView(tempChart);

    Is problem overflowing q64 due big toMsecSinceEpoch() or...?

  • Hi!
    There's a typo in your code, should be toMSecsSinceEpoch, not toSecsSinceEpoch:


    Have a look at the DateTimeAxis Example.

  • Hi,
    code above is in periodically called method void MainWindow::serialData() in file mainwindow.cpp I researched that mentioned problem is probably caused by leaving this method and code entering to main method to show window. Object QChartView maybe corrupted or destructed. Creating window object and show it: MainWindow w;; from this method not work.
    How to show main window from this method or how to solve this situation?

  • I had similar problem with toMSecssinceEpoch() method. The ChartView does not show plotted points. I changed it to toSecsSinceEpoch() and QDatetimeAxis is shown in ChartView. Thanks.

Log in to reply