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.