Passing a structure as a command line argument.
-
I execute Python scripts
QString PROC_Run(QString proc_name, QStringList proc_args) { QProcess proc; QString out; proc.start(proc_name, proc_args); proc.waitForFinished(-1); out = proc.readAll(); return out; }
and pass arguments
python3 my.py "aaa" 123 "bbb"
But actually I pass only string or numeric.
Can I pass a pointer to an array or some structure as an argument? Say the structure will be a common object, recognizable by Qt and Python as well. -
@jenya7 said in Passing a structure as a command line argument.:
Can I pass a pointer to an array or some structure as an argument?
No, you can't. You can only pass parameters which you can also pass in a terminal, so strings and integers.
-
@jenya7 said in Passing a structure as a command line argument.:
But actually I pass only string or numeric.
Actually you can only pass string(s) from the command-line, nothing else. They arrive in the
char *argv[]
parameter to yourmain(int argc, char *argv[])
. The"
s on your command are removed anyway, and the123
arrives as a string not a number (you can call code to convert it to a number in your program if you choose to, but it's a string).If this is really important to you, you could pass a JSON string --- either directly on the command-line or maybe in a file whose name you pass instead --- which represents, say, an array, and then put code into your program to call QJsonDocument QJsonDocument::fromJson() to parse it into an array for your code to use.
python3 my.py "{ 'array': [ 'aaa', 123, 'bbb' ] }"
Just a possibility.