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. Efficiency between QProcess and "system"
Forum Updated to NodeBB v4.3 + New Features

Efficiency between QProcess and "system"

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 994 Views 2 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.
  • MihanM Offline
    MihanM Offline
    Mihan
    wrote on last edited by
    #1

    Hi
    I want to know the efficiency between using QProcess to run bash to do some commands and using system or popen to do that( include getting content from stdout ).

    I think QProcess is convenient to do that but I have no idea whether QProcess is more efficient than system or not

    Regards
    Mihan

    1 Reply Last reply
    1
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by Kent-Dorfman
      #2

      If you want to manage the process asynchronously then you use QProcess. If you want to subshell process and stall the parent while the work is being done then system() works. QProcess is the "Qt" way of doing things. They both can be used for the same purpose but QProcess is more robust.

      Efficiency is irrelevant since they both probably use much of the same underlying code.

      MihanM 1 Reply Last reply
      4
      • Kent-DorfmanK Kent-Dorfman

        If you want to manage the process asynchronously then you use QProcess. If you want to subshell process and stall the parent while the work is being done then system() works. QProcess is the "Qt" way of doing things. They both can be used for the same purpose but QProcess is more robust.

        Efficiency is irrelevant since they both probably use much of the same underlying code.

        MihanM Offline
        MihanM Offline
        Mihan
        wrote on last edited by
        #3

        Thanks, @Kent-Dorfman
        I think I know how to improve my project.

        JonBJ 1 Reply Last reply
        0
        • MihanM Mihan

          Thanks, @Kent-Dorfman
          I think I know how to improve my project.

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

          @Mihan
          When using Qt there is no reason to prefer system() over QProcess. Even @Kent-Dorfman's "stall the parent while the work is being done" can now be achieved with the one-liner convenience static function https://doc.qt.io/qt-5/qprocess.html#execute introduced a couple of releases ago if that's what you want. And unless you are doing something special with popen(), Qt's QProcess offers pipe redirection on stdin/stdout/stderr in a convenient package.

          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