I have an object with some data in it:
class MyObject
{
public:
Recipe(<Some Arguments>);
}
and a dialog to edit the values of this object. This dialog gets a reference to this object and visualizes the values. I use a reference because I want to hold the data only once in memory. So I pass a reference to my data to every window which uses the data.
class MyDialog: public QDialog
{
private:
Ui::MyDialog* _mUi;
MyObject _mNew;
MyObject& _mOld;
};
MyDialog::MyDialog(MyObject& Old, QWidget* parent) : QDialog(parent),
_mUi(new Ui::MyDialog),
_mNew(Old)
_mOld(Old)
{
_mUi->setupUi(this);
// Visualize the values from "Old" in the GUI
}
The dialog also has some slots to fill the Object _mNew
with newer input data from the GUI. When the user has finished the editing he can leave the window by clicking Save
, which triggers the following code:
if(button == _mUi->buttonBox->button(QDialogButtonBox::Save))
{
// Overwrite the old values
_mOld = _mNew;
}
The values get updated and everything works fine.
But I´m not sure that this is a good solution. Is it a good practice to pass a reference to a data pool (MyObject
) into a dialog, edit the values and overwrite the reference with a new address or is there a better approach to realize some kind of editing method?