Anyway, the table model is not updated, but this is an issue I'll have to address later.
I use the following pattern whenever I implement a dialog that collects non-trivial information from the user which then must be passed back to the main program:
- create a struct or class that holds the data to be filled in by the dialog. Both the dialog and the main window know about this struct
- before posting the dialog, fill an instance of the struct with appropriate default values
- store the struct instance in the dialog instance
- exec() the dialog
- if exec() returns QDialog::Rejected, do nothing
- if exec() returns QDialog::Accepted then do the following
- retrieve the modified copy of the struct from the dialog
- process it as appropriate to store it in the main app
The code would roughly go like this:
void MainWindow::on_actionAdd_New_triggered()
{
AddRecipe addRecipes ( this );
RecipeTemplate newRecipe; // the struct, filled by default values on construction
addRecipes.setRecipeTemplate( newRecipe );
if ( QDialog::Accepted == addRecipes.
exec() ) {
newRecipe = addRecipes.getNewRecipe();
addNewRecipeToDB( newRecipe );
}
}
void MainWindow::on_actionAdd_New_triggered()
{
AddRecipe addRecipes ( this );
RecipeTemplate newRecipe; // the struct, filled by default values on construction
addRecipes.setRecipeTemplate( newRecipe );
if ( QDialog::Accepted == addRecipes.exec() )
{
newRecipe = addRecipes.getNewRecipe();
addNewRecipeToDB( newRecipe );
}
}
To copy to clipboard, switch view to plain text mode
The dialog doesn't need any extra signals or slots, nor do I need to connect to any existing signals. Everything is handled internally to the MainWindow slot.
Bookmarks