Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Passing a structure as a command line argument.
QtWS25 Last Chance

Passing a structure as a command line argument.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 613 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jenya7
    wrote on last edited by
    #1

    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.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • J jenya7

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply
      2
      • jsulmJ jsulm

        @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.

        J Offline
        J Offline
        jenya7
        wrote on last edited by
        #3

        @jsulm
        Thanks. Hope dies last.

        1 Reply Last reply
        0
        • J jenya7

          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.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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 your main(int argc, char *argv[]). The "s on your command are removed anyway, and the 123 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.

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved