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. How is parameter "QIODevice::OpenMode mode = ReadWrite" used in QProcess?
Forum Updated to NodeBB v4.3 + New Features

How is parameter "QIODevice::OpenMode mode = ReadWrite" used in QProcess?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 747 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
    Anonymous_Banned275
    wrote on last edited by
    #1

    Could somebody kindly assist me in better understanding of this QProcess parameter ?
    I understand QIODevice: can be assigned to QFile, but I fail to see how it

    actually ties to QProcess.

    All I see it has default mode assignment.

    The attached copy of doc really does not say much , except as highlighted.

    void QProcess::start(const QString &program, const QStringList &arguments, QIODevice::OpenMode mode = ReadWrite)
    
    Starts the given program in a new process, passing the command line arguments in arguments.
    
    The QProcess object will immediately enter the Starting state. If the process starts successfully, QProcess will emit started(); otherwise, errorOccurred() will be emitted.
    
    Note: Processes are started asynchronously, which means the started() and errorOccurred() signals may be delayed. Call waitForStarted() to make sure the process has started (or has failed to start) and those signals have been emitted.
    
    Note: No further splitting of the arguments is performed.
    
    Windows: The arguments are quoted and joined into a command line that is compatible with the CommandLineToArgvW() Windows function. For programs that have different command line quoting requirements, you need to use setNativeArguments(). One notable program that does not follow the CommandLineToArgvW() rules is cmd.exe and, by consequence, all batch scripts.
    
    **The OpenMode is set to mode.**
    
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      A QIODevice is not "assigned to" a QFile.
      A QFile is-a QIODevice (through QFileDevice).
      A QProcess is-a QIODevice.
      A QTcpSocket is-a QIODevice also (through QAbstractSocket).

      When you have a QProcess object with a running sub-process then you can read from or write to the QProcess object in the same general way as you can with any QIODevice. QProcess produces signals when data is available just like any other QIODevice.
      Unlike QFile, QProcess is not reading from or writing to a file, it is reading from or writing to the the standard output or input streams of the subprocess. The default is ReadWrite because that is generally what you want.

      A 1 Reply Last reply
      2
      • C ChrisW67

        A QIODevice is not "assigned to" a QFile.
        A QFile is-a QIODevice (through QFileDevice).
        A QProcess is-a QIODevice.
        A QTcpSocket is-a QIODevice also (through QAbstractSocket).

        When you have a QProcess object with a running sub-process then you can read from or write to the QProcess object in the same general way as you can with any QIODevice. QProcess produces signals when data is available just like any other QIODevice.
        Unlike QFile, QProcess is not reading from or writing to a file, it is reading from or writing to the the standard output or input streams of the subprocess. The default is ReadWrite because that is generally what you want.

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @ChrisW67 said in How is parameter "QIODevice::OpenMode mode = ReadWrite" used in QProcess?:

        A QProcess is-a QIODevice.

        OK. just humor me - where is is written that A QProcess is-a QIODevice?

        So if "mode" is set to "write" - do I still get the stdio /stderr from QProcess?

        JonBJ 1 Reply Last reply
        0
        • A Anonymous_Banned275

          @ChrisW67 said in How is parameter "QIODevice::OpenMode mode = ReadWrite" used in QProcess?:

          A QProcess is-a QIODevice.

          OK. just humor me - where is is written that A QProcess is-a QIODevice?

          So if "mode" is set to "write" - do I still get the stdio /stderr from QProcess?

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

          @AnneRanch said in How is parameter "QIODevice::OpenMode mode = ReadWrite" used in QProcess?:

          OK. just humor me - where is is written that A QProcess is-a QIODevice?

          https://doc.qt.io/qt-5/qprocess.html :

          QProcess Class

          ...

          Inherits: QIODevice

          So if "mode" is set to "write" - do I still get the stdio /stderr from QProcess?

          No! Your calling application needs read access to the QProcess/QIODevice in order to read from its stdout/stderr, and it would need write access to in order to write to its stdin, if you need that for the particular command. That is why the default is QIODevice::ReadWrite, to allow either/both. In your particular case QIODevice::ReadOnly would work, but not QIODevice::WriteOnly.

          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