tableView update content
-
Hi and welcome to devnet
Do you have an event loop running?
AFAIK the update should be automatically then. Anyway you can call the widget update, but this requires also that an event loop is running.PS: I have added markdown tags in your code section. This makes the code more readable. in the forum. You find the major tags at the end of this page.
-
Thank you for your answer.
i ran this.update(); but this update the Dialog.
I need to update the tableView which belongs to the parent.
Due to the event loop, my main.cpp looks like thisQApplication a(argc, argv);
InvoicePlusPlus w; QDesktopWidget *desktop = QApplication::desktop(); screenWidth = desktop->width(); screenHeight = desktop->height(); x = (screenWidth - WIDTH) / 2; y = (screenHeight - HEIGHT) / 2; w.resize(WIDTH, HEIGHT); w.move( x, y ); w.setWindowTitle("Invoice++"); w.show(); return a.exec();
-
Hi and welcome to devnet,
Since you are doing things low-level, then yes you have to refresh your model. Why not use QSqlTableModel to handle that ? You can hide the columns you don't want do see and do your update from it. That way both your views and your database will be up to date.
-
In my case, how to update the model?If you thing that the model should be updated, no the table.
When i click another tab from my app and get back the table has being updated.It means that the model is updated, but the tableView didn't. -
If you want to update the model directly, you have to re-set the query on it. Again, since you are modifying your table, QSqlTableModel is better suited.
-
If you are still using QSqlQuery to update the database, you have to call select on the model
-
-
Since you switched to QSqlTableModel, are you using it's functions to add new rows ?