Results 1 to 4 of 4

Thread: QProcess Signal Connection and Type

  1. #1
    Join Date
    Apr 2015
    Posts
    14
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QProcess Signal Connection and Type

    Suppose a QProcess is started() from the main/GUI thread. And suppose the new processes finished() signal is connected to a SLOT in the main/GUI thread. Please confirm this will use a Qt::queuedConnection type.

    I'm almost certain it does as QProcess should be in another thread by definition.

    Thanks,
    -Rich

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    481
    Thanked 71 Times in 67 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess Signal Connection and Type

    Quote Originally Posted by rhb327 View Post
    Please confirm this will use a Qt::queuedConnection type.
    No, there is no need for it
    Quote Originally Posted by rhb327 View Post
    I'm almost certain it does as QProcess should be in another thread by definition.
    Why?

  3. #3
    Join Date
    Apr 2015
    Posts
    14
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess Signal Connection and Type

    By definition a spawned process would run as a different process (and therefore a different thread). In my case the main/GUI thread spawns the external process.

    Within a Qt application / process there can be multiple threads and it's typical that these intra-process threads would communicate with a QueuedConnection signal / slot. Thus, the thinking was surely a separate process would signal another Qt process using a queued connection but that does not appear to be the case.

    In my sample below the queuedconnection throws:

    QObject::connect: Cannot queue arguments of type 'QProcess::ExitStatus'
    (Make sure 'QProcess::ExitStatus' is registered using qRegisterMetaType().)

    ...but the DirectConnection or AutoConnection does not. So my thought now is that QProcess is owned by the main/GUI thread and signaling from within the main/GUI thread would be direct. So finished() is truly emitted by the main/GUI thread in this case. However, I'm now curious how Qt was made aware that the external process was indeed finished. I think there must be an inter process communication that occurs prior and then the main/GUI thread issues finished() as a direct connection within the main/GUI thread.

    Thanks,
    -Rich

    Sample...

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. //connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(pFinished(int, QProcess::ExitStatus)));
    8. connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(pFinished(int, QProcess::ExitStatus)), Qt::QueuedConnection);
    9.  
    10. process.setWorkingDirectory("C:/Users/richard.bair/Downloads/");
    11. QStringList arguments = QStringList() << "/K" << "dir";
    12. process.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments *args)
    13. {
    14. args->flags |= CREATE_NEW_CONSOLE;
    15. args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES;
    16. });
    17. process.start("cmd.exe", arguments);
    To copy to clipboard, switch view to plain text mode 


    Added after 31 minutes:


    Yeah, reading here: https://doc.qt.io/qt-5/ipc.html strongly suggests the "API" for QProcess is where the comms occur form the external process back to my Qt process and then once that comms has occurred then QProcess (owned by main/GUI thread) issues a finished() signal in the same thread so a direct connection is used.
    Last edited by rhb327; 6th February 2020 at 20:47.

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    481
    Thanked 71 Times in 67 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess Signal Connection and Type

    QProcess just starts another process and handles it and is running in your process. There is no need that this handling is done in a separate thread.

  5. The following user says thank you to ChristianEhrlicher for this useful post:

    rhb327 (7th February 2020)

Similar Threads

  1. Can QT application detect which type of connection is used?
    By satya@sipl in forum Qt Programming
    Replies: 1
    Last Post: 1st December 2012, 13:16
  2. Cost of a signal to signal connection
    By hiçbirşeyyok in forum Qt Programming
    Replies: 2
    Last Post: 25th February 2012, 17:11
  3. Replies: 1
    Last Post: 16th March 2010, 15:46
  4. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  5. Signal connection
    By Lele in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2007, 11:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.