-1

I'm having a GUI interface done with Qt containing a button with an event handler function.

When I click the button , the event handler is fired and inside it I create a new process and taking into account that this process can require either no input , single input or multiple input commands. I want to know if there is a signal that could tell me when this new process requires bytes to be written to it ? or how I could possibly know ?

Note : The only solution I did is busy waiting with a while(true) nested inside it another while checking if there are bytes to be written to the process or not on a seperate QThread but sadly it's not thread safe (i.e The UI closes unexpectedly).

Any suggestions ?

Code :

Sample::Sample(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Sample)
{
    ui->setupUi(this);
    stdinThread = new StdinThread(this);
}

Sample::~Sample()
{
    delete stdinThread;
    delete runProcess;
    delete ui;
}

void Sample::on_runBtn_clicked()
{
    // Clear the console before using it

    ui->qConsole->clear();

    runProcess = new QProcess(this);

    runProcess->start(process , argumentList );

    runProcess->waitForStarted();

    stdinThread->start();

    runProcess->waitForFinished();

    // Get the process realtime stdout stream

**Some code for looping on stdout bytes written to the pipe
THEN**

    // Terminate the thread then the process
    stdinThread->terminate();
    runProcess->close();
    runProcess->terminate();
}

Thanks in advance.

1 Answers1

1

There is no way to programmatically determine whether another (unknown) process requires any input. Or even what type of input it requires. You have to know what you start and how that behaves.

Matthias247
  • 9,836
  • 1
  • 20
  • 29
  • Can you explain the part "You have to know what you start and how that behaves." ? Because I didn't get it because what I understood is that you mean I have to know how the process behaves but imagine if you're starting a process like "python" and you wish to know when "python" requires an input or not that's what I'm trying to accomplish. – user3719235 Jun 14 '14 at 13:33
  • I meant when you know that you start something that expects exactly one line of input then you can send that to the other process. If you don't know that or even start something completely unknown like a python program you won't know that the programm expects to read something from stdin. – Matthias247 Jun 14 '14 at 18:12
  • I'm trying something like when the process waitForFinished() it waits until the process finishes executing then I created a seperate thread that busy waits for bytes written by calling waitForBytesWritten() but unfortunately the GUI closes unexpectedly but it works fine , do you know a possible cause for this issue could be , I'm using QTThreads – user3719235 Jun 14 '14 at 20:59