MySQL table views are not updating
-
wrote on 7 Apr 2023, 02:56 last edited by
I have an application that is displaying MySQL table information in QTableViews in the ui editor. When I update a value in the database table I do not see it update the views unless i shut down the program and restart it the value updates in the database. As a note I am looking at a dataview in the database that consists of content from several tables. I do not know if this is a issue.
I wold like to know if there is a function that I can call that will redisplay the value from the database in the current views.
I also have a QTableWidgetView that is doing the same thing. they are all looking at:
QTextStream(&strSQL) << "SELECT * FROM Scheduleview WHERE Status = 'Ready' ;
I am changing the Status from "Ready' then to 'Running" then 'Complete' and showing the Table in different views that I wish to update.
ui->CompleteView->setStyleSheet("QTableView::item::alternate{ background-color:#bfffbf; } QTableView::item {background-color:#deffde; }"); ui->CompleteView->setModel(rdb.queryComplete); ui->RunView->setStyleSheet("QTableView::item::alternate{ background-color:#bfffbf; } QTableView::item {background-color:#deffde; }"); ui->RunView->setModel(rdb.queryRunning);
I am looking for any ideas, I have searched the internet and the documentation and Don't see anything tat seems to work.
-
I have an application that is displaying MySQL table information in QTableViews in the ui editor. When I update a value in the database table I do not see it update the views unless i shut down the program and restart it the value updates in the database. As a note I am looking at a dataview in the database that consists of content from several tables. I do not know if this is a issue.
I wold like to know if there is a function that I can call that will redisplay the value from the database in the current views.
I also have a QTableWidgetView that is doing the same thing. they are all looking at:
QTextStream(&strSQL) << "SELECT * FROM Scheduleview WHERE Status = 'Ready' ;
I am changing the Status from "Ready' then to 'Running" then 'Complete' and showing the Table in different views that I wish to update.
ui->CompleteView->setStyleSheet("QTableView::item::alternate{ background-color:#bfffbf; } QTableView::item {background-color:#deffde; }"); ui->CompleteView->setModel(rdb.queryComplete); ui->RunView->setStyleSheet("QTableView::item::alternate{ background-color:#bfffbf; } QTableView::item {background-color:#deffde; }"); ui->RunView->setModel(rdb.queryRunning);
I am looking for any ideas, I have searched the internet and the documentation and Don't see anything tat seems to work.
Lifetime Qt Championwrote on 7 Apr 2023, 05:32 last edited by Christian Ehrlicher 4 Jul 2023, 05:33How do the values change? From your program or externally? MySQL has no notification support so when it is changed from an external source you have to re-execute the query every time you want to see the new value.
If you change the database by yourself you can listen on the dataChanged() or similar functions and trigger the update on the other view accordingly. -
1/2