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 989 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.
  • S Offline
    S Offline
    SalemSabrehagen
    wrote on 12 Nov 2022, 12:38 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

    J 1 Reply Last reply 12 Nov 2022, 12:51
    0
    • S SalemSabrehagen
      12 Nov 2022, 12:38

      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

      J Offline
      J Offline
      JonB
      wrote on 12 Nov 2022, 12:51 last edited by JonB 11 Dec 2022, 12:57
      #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" } );
      
      S 1 Reply Last reply 12 Nov 2022, 13:15
      2
      • J JonB
        12 Nov 2022, 12:51

        @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" } );
        
        S Offline
        S Offline
        SalemSabrehagen
        wrote on 12 Nov 2022, 13:15 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

        J S 2 Replies Last reply 12 Nov 2022, 15:04
        0
        • S SalemSabrehagen
          12 Nov 2022, 13:15

          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

          J Offline
          J Offline
          JonB
          wrote on 12 Nov 2022, 15:04 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
          • S SalemSabrehagen
            12 Nov 2022, 13:15

            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 14 Nov 2022, 08:37 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

            1/5

            12 Nov 2022, 12:38

            • Login

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