Reputation: 11
The line m_total_hour_series->append(pair.first, pair.second);
is the source of the problem. The error message says: No matching function for call to 'QtCharts::QLineSeries::append(int&,Date&)'
I have looked at examples of the line chart and looked for appending date data, to no avail.
I am trying to make a line chart from data in the database. I am passing a list of pairs for values for the series. My window.cpp file has the following variables:
QLineSeries* m_total_hour_series;
QChart* m_total_hour_chart;
QDateTimeAxis* m_total_hour_axis_x;
QValueAxis* m_total_hour_axis_y;
QChartView* m_total_hour_chart_view;
My model.cpp file contains the following code:
QList<QPair<int,QDateTime>> ScannerModel::GetTotalHourSeries()
{
QList<QPair<int,QDateTime>> total_hour_series;
QString query_string;
QDateTime intervals;
QSqlDatabase db = QSqlDatabase::database(m_database_connection);
QList<QPair<int,QDateTime>> graph_point;
query_string = QString("SELECT COUNT(BagId) AS num_bags, ");
query_string += QString(" sec_to_time(time_to_sec(ScannedOn) - time_to_sec(ScannedOn)%(15*60)) AS intervals ");
query_string += QString("FROM Bag ");
query_string += QString("WHERE ScannedOn > date_sub(now(), INTERVAL 3 HOUR) ");
query_string += QString("GROUP BY intervals ");
QSqlQuery query(query_string, db);
if (query.size() > 0)
{
while (query.next())
{
graph_point.first = query.value(0).toInt();
intervals = query.value(1).toDateTime();
intervals.addSecs(m_time_zone.offsetFromUtc(intervals));
graph_point.second = intervals;
total_hour_series->append(graph_point);
}
qApp->processEvents();
}
return (total_hour_series);
}
My window.cpp file contains the following code:
void ScannerWindow::UpdateChartTotalHour()
{
QList<QPair<int,QDateTime>> listOfPairs;
m_total_hour_series->clear();
listOfPairs = m_model->GetTotalHourSeries();
for (int i = 0; i < listOfPairs.size(); i++)
{
QPair<int, QDateTime> pair = listOfPairs.at(i);
m_total_hour_series->append(pair.first, pair.second);
}
m_total_hour_chart->addSeries(m_total_hour_series);
qApp->processEvents();
m_total_hour_axis_x->setTickCount(12);
m_total_hour_axis_x->setFormat("HH:mm");
m_total_hour_chart->addAxis(m_total_hour_axis_x, Qt::AlignBottom);
m_total_hour_series->attachAxis(m_total_hour_axis_x);
m_total_hour_axis_y->setLabelFormat("%i");
m_total_hour_chart->addAxis(m_total_hour_axis_y, Qt::AlignLeft);
m_total_hour_series->attachAxis(m_total_hour_axis_y);
}
Thank you for your help.
Upvotes: 1
Views: 374
Reputation: 11
I searched on QDateTimeAxis. The answer is to use .toMSecsSinceEpoch(). Here is the site: doc.qt.io/qt-/qdatetimeaxis.html
Upvotes: 0