pass variable from tab to dialog
-
Hi
If you make a model with data from the database, and then use
http://doc.qt.io/qt-5/qdatawidgetmapper.html
to hook up the combo boxes, you can then hook up tableview to same model
and it should automatically update when user select new data in tabcomplessivo etc.I asume you did see
http://doc.qt.io/qt-5/qsqltablemodel.html
but it didnt fit your use case. (being single table ) ?@mrjj
the comboboxes was populated from different databasestableview in only a preview of data
on "Registra" click i will store the data from tableview to another database
qdatawidgetmapper is very interesting but i'm not sure this is my way.
Any suggestions?
-
@mrjj
the comboboxes was populated from different databasestableview in only a preview of data
on "Registra" click i will store the data from tableview to another database
qdatawidgetmapper is very interesting but i'm not sure this is my way.
Any suggestions?
@TheCipo76
Hi
Does the data from tableview live in one table or across multiple tables ? ( mean when saved to db) -
@TheCipo76
Hi
Does the data from tableview live in one table or across multiple tables ? ( mean when saved to db) -
@TheCipo76
and in this context, one database is one table ?
Im asking as you could use QSqlTableModel
and write the data from the comboboxes to
the model and view ould just show it. ( and be saved)
https://stackoverflow.com/questions/47318601/inserting-row-into-qsqltablemodel -
@TheCipo76
and in this context, one database is one table ?
Im asking as you could use QSqlTableModel
and write the data from the comboboxes to
the model and view ould just show it. ( and be saved)
https://stackoverflow.com/questions/47318601/inserting-row-into-qsqltablemodel@mrjj sorry.. yes is only one table in the same database
i'm already using QSqlTableModel in my app
but if i use QSqlTableModel for the tableview the data was stored immediately on the database..
instead i want only populate it with comboboxes (to generate a preview)
and then store the data only with "Registra" click (after that i have checked input by code)..all to prevent duplication, error and other problem that can be created by users input.
-
@mrjj sorry.. yes is only one table in the same database
i'm already using QSqlTableModel in my app
but if i use QSqlTableModel for the tableview the data was stored immediately on the database..
instead i want only populate it with comboboxes (to generate a preview)
and then store the data only with "Registra" click (after that i have checked input by code)..all to prevent duplication, error and other problem that can be created by users input.
@TheCipo76
Ah, i assumed user could only select valid data from the combo boxes.
But you could change
QSqlTableModel::setEditStrategy() to QSqlTableModel::OnManualSubmit
check the model from code and do
QSqlTableModel::submitAll() to save to db.
? -
@TheCipo76
Ah, i assumed user could only select valid data from the combo boxes.
But you could change
QSqlTableModel::setEditStrategy() to QSqlTableModel::OnManualSubmit
check the model from code and do
QSqlTableModel::submitAll() to save to db.
?@mrjj how can i access to tabs comboboxes data from mainwindow??
i've declarated in .h file like "public" all the comboboxes (in all the tab forms)
when i click "Aggiorna" i want to read all comboboxes of all tabs (with 2 nidificated loop: 1 for all tab, and inside the first, 1 for all comboboxes of each tab) and populate the qsqltablemodel (tableview) in mainwindow form
i'm trying to store all data in some QString before to insert in model
i've tried with this code:
Lavorazione = tabcomplessivo::array_Lavorazione[j]->currentText();but i have this error:
invalid use of non-static data member 'array_Lavorazione'
-
@mrjj how can i access to tabs comboboxes data from mainwindow??
i've declarated in .h file like "public" all the comboboxes (in all the tab forms)
when i click "Aggiorna" i want to read all comboboxes of all tabs (with 2 nidificated loop: 1 for all tab, and inside the first, 1 for all comboboxes of each tab) and populate the qsqltablemodel (tableview) in mainwindow form
i'm trying to store all data in some QString before to insert in model
i've tried with this code:
Lavorazione = tabcomplessivo::array_Lavorazione[j]->currentText();but i have this error:
invalid use of non-static data member 'array_Lavorazione'
Hi
The syntax you are using would mean a static variable. ( hence the error)
You need a pointer to the dialog. ( i assume the combobox are in other dialog ? )
dialogptr->tabcomplessivo->array_Lavorazione[j]->currentText();Often you would do it same place where you show dialog
like
TheDialog dia; // we dont need to NEW it as we use exec() which blocks.
if(dia.exec() == QDialog::Accepted)
{
// grab the data
dia.tabcomplessivoPtr.array_Lavorazione[j]->currentText();
...
} -
Are you only preparing the data to be stored in the database or will you also be showing entries from the database in that table view ?
-
Hi
The syntax you are using would mean a static variable. ( hence the error)
You need a pointer to the dialog. ( i assume the combobox are in other dialog ? )
dialogptr->tabcomplessivo->array_Lavorazione[j]->currentText();Often you would do it same place where you show dialog
like
TheDialog dia; // we dont need to NEW it as we use exec() which blocks.
if(dia.exec() == QDialog::Accepted)
{
// grab the data
dia.tabcomplessivoPtr.array_Lavorazione[j]->currentText();
...
} -
@mrjj
as you can see in the first post isn't a dialog but
tabcomplessivo and tabcomponente were
simple forms pass like tabs to tabwidget@TheCipo76
So they are actual inside the mainwindow ? -
@TheCipo76
So they are actual inside the mainwindow ? -
Are you only preparing the data to be stored in the database or will you also be showing entries from the database in that table view ?
-
In that case, wouldn't it be easier to use a QTableWidget to setup the rows and then QSqlQuery to update your database when you click on
Registra -
In that case, wouldn't it be easier to use a QTableWidget to setup the rows and then QSqlQuery to update your database when you click on
Registra -
Just to be sure, do you have several different widgets that you built with designer and that you are putting together in that dialog ?
-
Just to be sure, do you have several different widgets that you built with designer and that you are putting together in that dialog ?
@SGaist i've two different forms (but similar 90%)
n.1 tabcomplessivo
some tabcomponente
all in the mainwindowi've created with designer and added to tablewidget with code (first post) and populated dinamically with different table (from database) with different query
i have always only one tabcomplessivo and some (depends by item in database)
tabcomponentecomplessivo = componente + componente +... + componente
i hope that's clear (my english is not very good..)i have to describe all operations on every componente to build one complessivo
-
Then you should implement proper APIs for these different forms to pass values around so each will be an independent entity.
You might have to rethink a bit what element of your UI is responsible of what. For example, does it really make sens that
Aggiornais part of the left widget ? Shouldn't it be outside so that the slot connected to it can grab the data generated and then put them in the QTableWidget. -
Really there's no way to read data from Tabs??

TabWidget (and then all the Tabs) were inside the dialog as you see in the picture..
"Aggiorna" is already in the Dialog (not in TabWidget).
Including tabcomplessivo (form) and tabcomponente (form) in the TabWidget do not have any sense if i can't access to it's data from the Dialog.
Create a single Connect/signal from each comboBox/LineEdit do not allow to insert complete row of Model (TableView).
My idea was:
- firts select/insert in Tabs
- in any moments i can view the actual input with Aggiorna click() that put all selections/input data in the Model (TableView).
I've already implemented QSqlTableModel (TableView) and Aggiorna void to get data from Dialog and insert to Model (Codice, Complessivo..) the only missing part is get data from Tabs (with 2 loop as i've already wrote).
I have to delete all and do with another method??
-
Really there's no way to read data from Tabs??

TabWidget (and then all the Tabs) were inside the dialog as you see in the picture..
"Aggiorna" is already in the Dialog (not in TabWidget).
Including tabcomplessivo (form) and tabcomponente (form) in the TabWidget do not have any sense if i can't access to it's data from the Dialog.
Create a single Connect/signal from each comboBox/LineEdit do not allow to insert complete row of Model (TableView).
My idea was:
- firts select/insert in Tabs
- in any moments i can view the actual input with Aggiorna click() that put all selections/input data in the Model (TableView).
I've already implemented QSqlTableModel (TableView) and Aggiorna void to get data from Dialog and insert to Model (Codice, Complessivo..) the only missing part is get data from Tabs (with 2 loop as i've already wrote).
I have to delete all and do with another method??
@TheCipo76
Hi
The reason I are confused is that is not clear if you simply added
the tabs in Designer. ( with combo boxes and all)
In that case the combobox are directly readable to the dialog via UIOR
You made a new form ui object with the both .h and .cpp
and you make a new instance of your form and use
as Tab widget.
In that case UI is private and you need an access method to get data and the pointer of
the widget as you create it to be used as TabWidget.