needs to instantiate a dialogue in a switch construct
Good morning,
even if I know that it is not the correct technique to do, I need to instantiate a different type of dialogue depending on the parameter passed on the command line.
Something like that:
Code:
enum class FILTERS
{
AIRPORTS = 1,
FDDI = 2,
RRT = 3,
TARGET = 4,
TRACK = 5
};
int main (int argc, char ** argv)
{
QMap<QString, FILTERS> filterMap;
filterMap["airports"] = FILTERS::AIRPORTS;
filterMap["fddi"] = FILTERS::FDDI;
filterMap["rrt"] = FILTERS::RRT;
filterMap["target"] = FILTERS::TARGET;
filterMap["track"] = FILTERS::TRACK;
QCommandLineParser parser;
parser.
setApplicationDescription(QApplication::translate("main",
"Call the right filter"));
parser.addHelpOption();
QCommandLineOption filterTypeOption
("t",
QApplication::translate("main",
"Specifies the type of filter to call"));
parser.addOption(filterTypeOption);
parser.process(app);
QString filterType
= parser.
value(filterTypeOption
);
FILTERS filter = filterMap[filterType];
switch(filter)
{
case FILTERS::AIRPORTS:
AirportsDialog dialog;
break;
case FILTERS::FDDI:
FDDIDialog dialog;
break;
case FILTERS::RRT:
RRTDialog dialog;
break;
case FILTERS::TARGET:
TargetDialog dialog;
break;
case FILTERS::TRACK;
TrackDialog dialog;
break;
}
dialog.show();
int ret = app.exec();
return ret;
}
An example of a call will be:
Quote:
dialog_caller -t rrt
or
Quote:
dialog_caller -t airports
Is there a better way to achieve this behavior? The different dialogs are totally different from each other.
By instancing the dialog in the switch it will be removed once you exit from the switch?
How to make it remain active until the end of the program?
Re: needs to instantiate a dialogue in a switch construct
Hi, yes, the dialogs will be destroyed when you reach the end of the switch. I would create something like this:
Code:
switch(filter)
{
case FILTERS::AIRPORTS:
dialog = new AirportsDialog ();
break;
// similar for the other cases
...
}
dialog->show();
// remember to delete the dialog
Of course this assumes that your dialogs are derived from QDialog.
Ginsengelf
Re: needs to instantiate a dialogue in a switch construct
Quote:
// remember to delete the dialog
Could do something like this, I think:
Code:
connect( dialog, &QDialog::finished, dialog, &QDialog::dedleteLater );
dialog->show();
or use the QDialog::accepted() and QDialog::rejected() signals in the same way.