PDA

View Full Version : Passing data to dialog via dialog or a method



mtnbiker66
2nd February 2012, 20:39
I'm currently passing data to a popup dialog in the following manner:

mainwindow.cpp


RAO_Edit = new RAOEntryDialog();
RAO_Edit->edit_rao(surgemodel);
RAO_Edit->exec();


RAOEntryDialog


void RAOEntryDialog::edit_rao(QSqlTableModel *process_model)
{
...
}


But I can also do it like this:
mainwindow.cpp


RAO_Edit = new RAOEntryDialog(surgemodel);
RAO_Edit->edit_rao();
RAO_Edit->exec();


RAOEntryDialog


RAOEntryDialog::RAOEntryDialog(QSqlTableModel *process_model, QWidget *parent) :
QDialog(parent),
ui(new Ui::RAOEntryDialog)
{
...
}


It's not necessary but I'd like to be able to operate on this model from several of the methods within my RAOEntryDialog class and that's got me a little perplexed as to how, so is there one way of getting the model into the dialog better than the other? This is a QSqlTableModel and I'm planning on transferring the data to a QTableWidget to allow me to treat the data in a spreadsheet fashion (insert, delete, copy, paste), then pass the data back to my mainwindow via signal/slot mechanism...

Thanks!


Kodi

ChrisW67
2nd February 2012, 22:09
In large part I think this is a personal preference thing. If the RAO_Edit cannot function without the model then it makes sense to construct it with one or at least offer a constructor that does. If the model can changed on-the-fly then you need to offer a setModel() function of some sort. For consistency with the Qt classes you would use setModel() but make sure that you handle things gracefully if a model has not yet been set.

mtnbiker66
3rd February 2012, 01:39
The reason behind the dialog is that there's a widget displaying data in the mainwindow (from this model) that's too small to make editing useful, so upon clicking an "Edit" pushbuttom this RAOEntrydialog dialog will pop up; it is much larger and will facilitate easier editing of the model's data...Where it gets tricky is that I need to be able to offer cut-and-paste functionality and a tableview sitting on top of a QSqlTableModel would be hard to manage so what I'm thinking I'll do is copy the data from the model to a tablewidget, implement the editing and then when the "okay" pushbutton on the dialog is clicked, pass the data back to the mainwindow via a slot and repopulate the original QSqlTableModel there...Ideally it would be nice to operate directly on the model inside the popup dialog with a QSqlTableView, but dealing with the management of cutting and pasting seems to be a more cumbersome methodology...

I'm fairly weak in C++ (databases are my expertise) so trying to figure out how to make the model accessible to the popup dialog across multiple methods is a bit of a stretch so I thought passing in via the constructor might help that happen, but I'm still at a loss as to how to get that data to the methods (I was getting an error earlier when I was trying to assign the parameter to a variable name in the constructor), so if that direction doesn't buy me anything I may as well stick to how I've dealt with other parts of my app and that's that pass the data thru on a signal/slot mechanism and pass edited data back and repopulate the model there in my mainwindow

Thanks for opinion!!!

Kodi