Hello!

I have a doubt that is not truuuly problematic, but nevertheless would certainly increase my knowledge in programming and make a code of some of my softwares better.

The idea that I have in mind (and I do have a code that makes that work) is that sometimes I want a window (QDialog, normally) to appear before the actual software is shown, or else I want a window (QDialog) to appear where the user will select between a number of MainWindows to use. The first case has a very common example: imagine a software that all times, before it runs, shows a QDialog for the user to put a password in order to use this software. For the second case, here is the code that I'm using to make that work: (since both codes are very similar, I'm gonna show just this second):

Qt Code:
  1. int decisao;
  2. bool continuaounao = false;
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7.  
  8. NovoMain NM;
  9.  
  10. inicio: decisao = NM.executa();
  11. if (decisao == 1) //Positions
  12. goto spositions;
  13. else if (decisao == 2) //Body
  14. goto body;
  15. else if (decisao == 3) //Outro
  16. goto context;
  17. else if (decisao == 4) //Creditos
  18. goto creditos;
  19. else if (decisao == 0)
  20. return 0;
  21.  
  22. spositions: {
  23. qDebug() << "Positions";
  24. SPositions sp;
  25. sp.setWindowTitle("Positions");
  26. sp.showMaximized();
  27. sp.show();
  28. a.exec();
  29. if (sp.getSaida() == true)
  30. return 0;
  31. else goto inicio;
  32. }
  33.  
  34. body: {
  35. Body bd;
  36. bd.setWindowTitle("Body knowledge");
  37. bd.showMaximized();
  38. bd.show();
  39. a.exec();
  40. if (bd.getSaida() == true)
  41. return 0;
  42. else goto inicio;
  43. }
  44. context: {
  45. Context ct;
  46. ct.setWindowTitle("Context and details");
  47. ct.showMaximized();
  48. ct.show();
  49. a.exec();
  50. if (ct.getSaida() == true)
  51. return 0;
  52. else goto inicio;
  53. }
  54. creditos: {
  55. Credits cd;
  56. cd.setWindowTitle("Credits");
  57. cd.showMaximized();
  58. cd.show();
  59. qDebug() << "Credits";
  60. a.exec();
  61. if (cd.getSaida() == true)
  62. return 0;
  63. else goto inicio;
  64. }
  65. }
To copy to clipboard, switch view to plain text mode 

A example of the basic code used in the getSaida() function (the same for all of them):

Qt Code:
  1. Context::Context(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::Context)
  4. {
  5. ui->setupUi(this);
  6. continua = false;
  7. }
  8.  
  9. Context::~Context()
  10. {
  11. delete ui;
  12. }
  13.  
  14. void Context::on_actionClose_triggered()
  15. {
  16. close();
  17. }
  18.  
  19. void Context::on_actionExit_triggered()
  20. {
  21. continua = true;
  22. close();
  23. }
  24.  
  25. bool Context::getSaida()
  26. {
  27. return continua;
  28. }
To copy to clipboard, switch view to plain text mode 

Note: the NovoMain is a QDialog with a respective QPushButton for each of the possible MainWindow in the code (SPosition, Body, etc.) and, when one of the QPushButton is clicked, it closes the QDialog and return a specific int catch by "decisao".

My question is: is there a better way to do this? Is there a function or something like that that can replace my goto methodology??



Thanks!

Momergil