-1

I have a QListwidget in my UI , The items of these are foods like

  • Pizza
  • Turkish Delight
  • Pasta
  • Cake
  • ...

I have 22 of items like these

So whenever I double click on each item, I have a separate modal QDialogbox pop-up which shows its recipe and the QDialog box also takes input with the help of few line edits.

So my question is that having 22 separate QDialogboxes is okay? Any downsides to this? Or can i do anything better as an alternative, because for each dialog box, I also have a .h and .cpp file.

Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
  • Just construct those dialogboxes just in time to avoid high memory usage (in case the number of recipes increases drastically). – m7913d Aug 11 '20 at 14:52

1 Answers1

1

Instead of having 22 different (but identical-except-for-the-text-they-display) dialog classes, you'd be better off having one dialog class that takes arguments containing the text it wants to display. Then you can just keep your recipes in a file (e.g. either in a .cpp file as compile-time constants, or in a .txt file that you read from disk at program startup) and instantiate an object of your one dialog-class with the appropriate text when necessary.

Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
  • Thanks for the suggestion, but that if someof them vary alot, like for example some dialog boxes have multiple QComboboxes and buttons which open file dialogs, would it make sense to have separate for them – Mr_Workalot Jun 26 '20 at 17:23
  • If they are all different, sure; OTOH it might be the case that you can model them as being all special cases of one Uber-dialog-class that contains all of the comboboxes and buttons and so on, just that some of them have some of the extra widgets/features hidden. In that case you could pass in a "flags" argument along with the text, telling the dialog class which features to show and which to hide (e.g. MyDialog = new `MyDialog("Pizza", FLAG_COMBOBOX | FLAG_BUTTONS | FLAG_SOMETHINGELSE);` – Jeremy Friesner Jun 26 '20 at 21:09