#include <argumentlist.h>
Public Member Functions | ||||
| ArgumentList () | ||||
| retrieve argument list from the qApp->argc() and argv() methods. | ||||
| ArgumentList (int argc, char *argv[]) | ||||
| ||||
| ArgumentList (const QStringList &argumentList) | ||||
| bool | getSwitch (QString option) | |||
| finds and removes a switch from the string list, if it exists. | ||||
| QString | getSwitchArg (QString option, QString defaultRetVal=QString()) | |||
| finds/removes a switch and its accompanying argument from the string list, if the switch is found. | ||||
An object which provides a simple interface to the command line arguments of a program. The methods getSwitch(QString) and getSwitchArg(QString) allow you to process and remove the switches and switched arguments in the command line, so that the remaining entries in the stringlist can be processed as a uniform list.
It also happens to be derived from QStringList, so you can use any of those methods on this object too.
This helps you avoid entirely using the C arrays in your application.
Usage.:
int main(int argc, char** argv) {
ArgumentList args(argc, argv);
bool verbose = args.getSwitch("-v");
// get all other switches
QString outputfile = args.getSwitchArg("-o", "default.out");
qout << args[0]; // prints the name of the executable
qout << args[1]; // prints the first unswitched argument
someObject.processEveryFile(args);
}
Definition at line 45 of file argumentlist.h.
| ArgumentList::ArgumentList | ( | ) |
retrieve argument list from the qApp->argc() and argv() methods.
Only works if a QApplication(argc, argv) was already created.
Definition at line 9 of file argumentlist.cpp.
| ArgumentList::ArgumentList | ( | int | argc, | |
| char * | argv[] | |||
| ) | [inline] |
| argc | number of arguments |
| argv | an array of command line arguments, as supplied to main(). |
Definition at line 60 of file argumentlist.h.
| bool ArgumentList::getSwitch | ( | QString | option | ) |
finds and removes a switch from the string list, if it exists.
| option | the switch to search for |
Definition at line 22 of file argumentlist.cpp.
| QString ArgumentList::getSwitchArg | ( | QString | option, | |
| QString | defaultRetVal = QString() | |||
| ) |
finds/removes a switch and its accompanying argument from the string list, if the switch is found.
Does nothing if the switch is not found.
| option | the switch to search for | |
| defaultReturnValue | the return value if option is not found in the stringlist |
Definition at line 33 of file argumentlist.cpp.
1.5.1