Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. How to make use of latest QProcess::startDetached function with argument when starting external apps?
Forum Updated to NodeBB v4.3 + New Features

How to make use of latest QProcess::startDetached function with argument when starting external apps?

Scheduled Pinned Locked Moved Solved C++ Gurus
5 Posts 3 Posters 926 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.
  • SalemSabrehagenS Offline
    SalemSabrehagenS Offline
    SalemSabrehagen
    wrote on last edited by
    #1

    Hi coders,

    when using QProcess::startDetached() on a RasPi using Qt5.15.2 in root mode, which i have to, because if wiringPi:

    QProcess::startDetached("dbus-launch gnome-terminal -- bash -c "sleep 2s;cat "+LogFile+"; exec bash -i"");
    

    or

    QProcess::startDetached("sudo chmod -R 777 "+dir_pizung_sensors.absolutePath());
    

    i get the warning:
    warning: ‘static bool QProcess::startDetached(const QString&)’ is deprecated: Use
    QProcess::startDetached(const QString &program, const QStringList &arguments) instead [-Wdeprecated-declarations]

    Problem:
    When using the latest function, like beneath, the external apps won't start silenty with no error at all:

    QProcess::startDetached("dbus-launch gnome-terminal";{"-- bash -c "sleep 2s;cat "+LogFile+"; exec bash -i""});
    

    or

    QProcess::startDetached("sudo chmod";{"-R 777 "+dir_pizung_sensors.absolutePath()"});
    

    don't work.

    I use the workaround:

    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
    qWarning() << "Using deprecated-declaration QProcess::startDetached(), because no other way!";
    QProcess::startDetached("dbus-launch gnome-terminal -- bash -c "sleep 2s;cat "+LogFile+"; exec bash -i"");
    #pragma GCC diagnostic pop
    

    I know that:
    QProcess::startDetached(const QString &program, const QStringList &arguments)
    works for apps with easier argument with no problem on my RasPi4 under Qt.

    Can someone please give me a hint ?

    /Ralf

    JonBJ 1 Reply Last reply
    0
    • SalemSabrehagenS SalemSabrehagen

      Hi coders,

      when using QProcess::startDetached() on a RasPi using Qt5.15.2 in root mode, which i have to, because if wiringPi:

      QProcess::startDetached("dbus-launch gnome-terminal -- bash -c "sleep 2s;cat "+LogFile+"; exec bash -i"");
      

      or

      QProcess::startDetached("sudo chmod -R 777 "+dir_pizung_sensors.absolutePath());
      

      i get the warning:
      warning: ‘static bool QProcess::startDetached(const QString&)’ is deprecated: Use
      QProcess::startDetached(const QString &program, const QStringList &arguments) instead [-Wdeprecated-declarations]

      Problem:
      When using the latest function, like beneath, the external apps won't start silenty with no error at all:

      QProcess::startDetached("dbus-launch gnome-terminal";{"-- bash -c "sleep 2s;cat "+LogFile+"; exec bash -i""});
      

      or

      QProcess::startDetached("sudo chmod";{"-R 777 "+dir_pizung_sensors.absolutePath()"});
      

      don't work.

      I use the workaround:

      #pragma GCC diagnostic push
      #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
      qWarning() << "Using deprecated-declaration QProcess::startDetached(), because no other way!";
      QProcess::startDetached("dbus-launch gnome-terminal -- bash -c "sleep 2s;cat "+LogFile+"; exec bash -i"");
      #pragma GCC diagnostic pop
      

      I know that:
      QProcess::startDetached(const QString &program, const QStringList &arguments)
      works for apps with easier argument with no problem on my RasPi4 under Qt.

      Can someone please give me a hint ?

      /Ralf

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

      @SalemSabrehagen said in How to make use of latest QProcess::startDetached function with argument when starting external apps?:

      When using the latest function, like beneath, the external apps won't start silenty with no error at all:

      Ignoring the fact that your code is syntactically incorrect (...";{"...) and will not compile (so don't know what you really have)....

      But both your attempts are incorrect. (To get errors you must connect to errorOccurred signal.) The first argument to startDetached() (or start()) is a command. And the second argument is a list of parameters, each parameter must be a separate element.

      QProcess::startDetached("sudo", { "chmod", "-R", "777", dir_pizung_sensors.absolutePath() } );
      
      QProcess::startDetached("dbus-launch", { "gnome-terminal", "--", "bash", "-c", "sleep 2s;cat "+LogFile+"; exec bash -i" } );
      
      SalemSabrehagenS 1 Reply Last reply
      2
      • JonBJ JonB

        @SalemSabrehagen said in How to make use of latest QProcess::startDetached function with argument when starting external apps?:

        When using the latest function, like beneath, the external apps won't start silenty with no error at all:

        Ignoring the fact that your code is syntactically incorrect (...";{"...) and will not compile (so don't know what you really have)....

        But both your attempts are incorrect. (To get errors you must connect to errorOccurred signal.) The first argument to startDetached() (or start()) is a command. And the second argument is a list of parameters, each parameter must be a separate element.

        QProcess::startDetached("sudo", { "chmod", "-R", "777", dir_pizung_sensors.absolutePath() } );
        
        QProcess::startDetached("dbus-launch", { "gnome-terminal", "--", "bash", "-c", "sleep 2s;cat "+LogFile+"; exec bash -i" } );
        
        SalemSabrehagenS Offline
        SalemSabrehagenS Offline
        SalemSabrehagen
        wrote on last edited by
        #3

        Hi @JonB,
        sorry for my bad typing (...";{"...); my code on the Pi was correct.

        Your suggestion works !

        Typing the new command makes it more complicated the ever, but there must be a reason for change.

        Thanks,
        /Ralf

        JonBJ S 2 Replies Last reply
        0
        • SalemSabrehagenS SalemSabrehagen

          Hi @JonB,
          sorry for my bad typing (...";{"...); my code on the Pi was correct.

          Your suggestion works !

          Typing the new command makes it more complicated the ever, but there must be a reason for change.

          Thanks,
          /Ralf

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

          @SalemSabrehagen
          The old way startDetached() (and start()) really did two things: they had to parse-split the command-line string command before getting OS to execute with separate arguments. Now they separated the parsing out into its own method, QStringList QProcess::splitCommand(QStringView command), so you could call that on a command-line string and it should (hopefully!) deliver the same separate arguments as you now need to pass start...(). But it is cleaner this way.

          1 Reply Last reply
          2
          • SalemSabrehagenS SalemSabrehagen

            Hi @JonB,
            sorry for my bad typing (...";{"...); my code on the Pi was correct.

            Your suggestion works !

            Typing the new command makes it more complicated the ever, but there must be a reason for change.

            Thanks,
            /Ralf

            S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #5

            @SalemSabrehagen said in How to make use of latest QProcess::startDetached function with argument when starting external apps?:

            but there must be a reason for change.

            I can only guess. But, I would say the new way is much better. Having all arguments as separate entries in a list does away with having to quote some arguments and escaping quotes where necessary. Sure, this only applies to arguments which have spaces inside them (which is rarely the case), but in general it is much better. In your case with calling bash with arguments it is certainly a much better way. There are countless posts on this forum (both Windows- and Linux-related) where people got this wrong (using the old way).

            1 Reply Last reply
            1

            • Login

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