A simple question: How to update multi form on mainwindows. use view and model ?
-
wrote on 3 Jul 2024, 03:02 last edited by
-
for example , on following image:
i want to update name , when server modify the user name.
wrote on 3 Jul 2024, 04:08 last edited by Pl45m4 7 Mar 2024, 04:09Yes, either a model which fetches the data and updates the view or you send update manually via signal&slot to your display field.
Depends on how much data you have, how you want to organize it and what you want to do with it.
Implementing your own model + view just to update the first name / last name, is not worth it if you ask me.
If you have more data and want to store multiple datasets, it's probably the cleanest and best way. -
for example , on following image:
i want to update name , when server modify the user name.
wrote on 3 Jul 2024, 07:49 last edited by@Xrtero
Consider using QDataWidgetMapper. That provides a two-way mapping between widgets and model, so changes in the model update the widget and if the user changes the widget that updates the model.But depends what you mean by "when server modify the user name". If "server" means database server (like MySQL) you will not get a "notification" if a different process updates a database table, that is not supported.
-
Yes, either a model which fetches the data and updates the view or you send update manually via signal&slot to your display field.
Depends on how much data you have, how you want to organize it and what you want to do with it.
Implementing your own model + view just to update the first name / last name, is not worth it if you ask me.
If you have more data and want to store multiple datasets, it's probably the cleanest and best way. -
@Xrtero
Consider using QDataWidgetMapper. That provides a two-way mapping between widgets and model, so changes in the model update the widget and if the user changes the widget that updates the model.But depends what you mean by "when server modify the user name". If "server" means database server (like MySQL) you will not get a "notification" if a different process updates a database table, that is not supported.
wrote on 6 Jul 2024, 03:12 last edited by@JonB
"server" means http server (like when i want get the username ,age ... etc )
so ,as the number of labels increases, the use of signals and slots becomes progressively more complex.
Moreover, if a single page needs to include various types of information ( i meaning different model objects),it will becomes particularly complicated . Using a model and view approach will make the core more simple(just usesetModel
to update view) . that's my impression as beginner. -
@JonB
"server" means http server (like when i want get the username ,age ... etc )
so ,as the number of labels increases, the use of signals and slots becomes progressively more complex.
Moreover, if a single page needs to include various types of information ( i meaning different model objects),it will becomes particularly complicated . Using a model and view approach will make the core more simple(just usesetModel
to update view) . that's my impression as beginner.wrote on 6 Jul 2024, 14:53 last edited by Pl45m4 7 Jun 2024, 14:54@Xrtero said in A simple question: How to update multi form on mainwindows. use view and model ?:
"server" means http server (like when i want get the username ,age ... etc )
So you make HTTP requests? With
QNAM
?as the number of labels increases, the use of signals and slots becomes progressively more complex.
Using more signals doesn't make you app more complex, esp when they just update a string/int in a LineEdit.
Moreover, if a single page needs to include various types of information ( i meaning different model objects),it will becomes particularly complicated
The approach @JonB suggested is still viable. You can map these kind of information to the correct field where they are displayed.
Using a model and view approach will make the core more simple(just use setModel to update view) .
setModel
does not update anything. It only assigns the model to the view.
For a custom model/view there is still a lot to do (re-implement functions, handle your use-case)...that's my impression as beginner.
...might not be that easy, as a beginner :)
-
@JonB
"server" means http server (like when i want get the username ,age ... etc )
so ,as the number of labels increases, the use of signals and slots becomes progressively more complex.
Moreover, if a single page needs to include various types of information ( i meaning different model objects),it will becomes particularly complicated . Using a model and view approach will make the core more simple(just usesetModel
to update view) . that's my impression as beginner. -
1/7