Line chart with sqlite database
Unsolved
General and Desktop
-
i am trying to put a line chart in the program but the program keeps crashing and wont let me go any further. here is the snippet of the function that's showing the error
Any suggestions will be very very helpful```
code_text{ QSqlQuery qry1, qry2,qry3; qry2.prepare("select count(*) from fitness where username = '"+current+"'"); qry2.exec(); qry2.first(); int noofrows = qry2.value(0).toInt(); qDebug() << noofrows; int offset = noofrows - 5; QLineSeries *series = new QLineSeries(); int i; qry3.prepare("select * from fitness where username = '"+current+"' limit 5 offset :offsetvalue "); qry3.bindValue(":offsetvalue",offset); qDebug() << current; int count = 0; if (qry3.exec()){ while (qry3.next()){ count = count + 1; } } qry1.prepare("select * from fitness username = '"+current+"' limit 5 offset :offsetvalue"); qry1.bindValue(":offsetvalue",offset); qry1.exec(); for (i=0; i<count; i++){ qry1.next(); QStringList dates = qry1.value(0).toString().split("-").mid(0,3); QDateTime momentInTime; momentInTime.setDate(QDate(dates[0].toInt(), dates[1].toInt() , dates[2].toInt())); series -> append(momentInTime.toMSecsSinceEpoch(), qry1.value(1).toDouble()); } QChart *chart = new QChart(); chart -> addSeries(series); chart -> legend() -> hide(); chart -> setTitle("Weight Record"); chart -> setTheme(QChart::ChartThemeHighContrast); QDateTimeAxis *axisX = new QDateTimeAxis; axisX->setFormat("dd MMM"); axisX->setTitleText("Date"); axisX->setTickCount(count); chart->addAxis(axisX, Qt::AlignBottom); series->attachAxis(axisX); QValueAxis *axisY = new QValueAxis; axisY->setLabelFormat("%i"); axisY->setRange(66,75); axisY->setTickCount(10); axisY->setTitleText("Weight"); chart->addAxis(axisY, Qt::AlignLeft); series->attachAxis(axisY); chart -> setAnimationOptions(QChart::GridAxisAnimations); chart -> setAnimationOptions(QChart::SeriesAnimations); chart -> setAnimationEasingCurve(QEasingCurve::OutCubic); QChartView *chartView = new QChartView(chart); chartView -> setRenderHint(QPainter::Antialiasing); chartView -> setParent(ui->horizontalFrame_chart); }``` database: ![5d3e9be7-6604-4922-909a-b72cb63fab98-image.png](https://ddgobkiprc33d.cloudfront.net/9a0c6196-5586-4340-b2b5-ed129ff48cd1.png)
-
@krist0 said in Line chart with sqlite database:
the program keeps crashing and wont let me go any further. h
Then use your debugger and see where exactly it crashes.
QStringList dates = qry1.value(0).toString().split("-").mid(0,3);
momentInTime.setDate(QDate(dates[0].toInt(), dates[1].toInt() , dates[2].toInt()));You should check if you really get three strings here.