I am new to Qt creator C++. I have designed a application where the data is displayed on a tableView fetching it from Sqlite database, till here i am successfull, but now i want to plot the graph on a customplot by giving values for x and y axis from the database which i have fetched it and displayed on tableView widget.Example: the data from my database is like Time and Temperature-Now i want to give values for X axis in Time and Y axis in Temperature, please help me out in the code-
I am able to plot the graph normally as shown in the below code,how do i add the database values on x and y axis..
void MainWindow::makePlot()
{
QVector<double> x(100), y(101);
// x[0]=1;Here I want the application to take the values from tableView,like
Time on X axis and Temp on Y axis.
// x[1]=2;
// x[2]=3;
// x[3]=4;
// y[0]=1;
// y[1]=2;
// y[2]=3;
// y[3]=4;
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(x, y);
ui->customPlot->xAxis->setLabel("Time");
ui->customPlot->yAxis->setLabel("Temp");
ui->customPlot->xAxis->setRange(1, 15);
ui->customPlot->yAxis->setRange(1, 15);
ui->customPlot->replot();
}
Here is the code that displays the Database in tableView on push button.
void MainWindow::on_pushButton_clicked()
{
MainWindow conn;
QSqlQueryModel * modal=new QSqlQueryModel();
conn.connOpen();
QSqlQuery* qry=new QSqlQuery(conn.mydb);
qry->prepare("select * from empdata");
qry->exec();
modal->setQuery(*qry);
ui->tableView->setModel(modal);
conn.connClose();
qDebug() <<(modal->rowCount());
}[![enter image description here][1]][1]
Please help me out..Thanks in advance..