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. QProcess arguments are not passed using class method.
Forum Updated to NodeBB v4.3 + New Features

QProcess arguments are not passed using class method.

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 550 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    adutzu89
    wrote on last edited by
    #1

    Hello,
    I encountered an issue and I'm not sure if it's a bug or I am calling the method wrong.
    I am trying to call Qt installer framework's updater to check for updates and if there are then I would notify the user.
    I am calling the updater through QProcess, but if I use process.setArguments(QStringList() << "--checkupdates"); the argument isn't passed down to the process.
    Example:
    This passes the arguments and the updater checks for updates:

    QProcess process;
    process.start(updaterPath, QStringList() << "--checkupdates");
    

    This doesn't pass the arguments and the updater's UI is opened:

    QProcess process;
    process.setArguments(QStringList() << "--checkupdates");
    process.start(updaterPath);
    

    From docs:
    void QProcess::setArguments(const QStringList &arguments)

    Set the arguments to pass to the called program when starting the process. This function must be called before start().

    This happens on Windows 10 x64, application built with Qt 5.12.6, MSVC2017 x32 compiler.

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      see the documentation for QString::start(const QString &command, QIODevice::OpenMode mode = ReadWrite)

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • A adutzu89

        Hello,
        I encountered an issue and I'm not sure if it's a bug or I am calling the method wrong.
        I am trying to call Qt installer framework's updater to check for updates and if there are then I would notify the user.
        I am calling the updater through QProcess, but if I use process.setArguments(QStringList() << "--checkupdates"); the argument isn't passed down to the process.
        Example:
        This passes the arguments and the updater checks for updates:

        QProcess process;
        process.start(updaterPath, QStringList() << "--checkupdates");
        

        This doesn't pass the arguments and the updater's UI is opened:

        QProcess process;
        process.setArguments(QStringList() << "--checkupdates");
        process.start(updaterPath);
        

        From docs:
        void QProcess::setArguments(const QStringList &arguments)

        Set the arguments to pass to the called program when starting the process. This function must be called before start().

        This happens on Windows 10 x64, application built with Qt 5.12.6, MSVC2017 x32 compiler.

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

        @adutzu89
        @Christian-Ehrlicher is telling you that the void QProcess::start(const QString &command, QIODevice::OpenMode mode = ReadWrite) you are failing with requires a single string argument of the complete command line. It does not append any arguments you have set with QProcess::setArguments().

        Only the void QProcess::start(QIODevice::OpenMode mode = ReadWrite) overload, and bool QProcess::startDetached(qint64 *pid = nullptr) refer to QStringList QProcess::arguments() const, and they require you to use setProgram() for the executable path.

        I think the docs might be clearer on this, it can be easy to misunderstand which spawners are using setArguments() and which are not. You just have to read carefully and try them.

        1 Reply Last reply
        1
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          There is even a macro which prevents the use of this somewhat strange function: QT_NO_PROCESS_COMBINED_ARGUMENT_START

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          JonBJ 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            There is even a macro which prevents the use of this somewhat strange function: QT_NO_PROCESS_COMBINED_ARGUMENT_START

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

            @Christian-Ehrlicher
            There is indeed, but that (enabled or not) would not make it use the setArguments() which is the user's expectation.

            EDIT Hmm:

            Disables the QProcess::start() overload taking a single string. In most cases where it is used, the user intends for the first argument to be treated atomically as per the other overload.

            and

            In virtually all cases, using the other overload is the preferred method.

            Frankly, I find this even more confusing than before! :)

            I think we're saying: if you use setArguments() you then need to do start() via setProgram()....

            1 Reply Last reply
            0
            • A Offline
              A Offline
              adutzu89
              wrote on last edited by
              #6

              @Christian-Ehrlicher & @JonB , ty for your answers, it's clear now.

              1 Reply Last reply
              0

              • Login

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