activeProcs.append(proc.name());
proc.start(KProcess::OwnGroup, KProcess::All); /// ownGroup so children spawned by proc can be killed too + comm=alloutput
/// to prevent queueing of messages we start a timer
connect( timer, SIGNAL(timeout()), this, SLOT(postAllEvents()) );
timer->start(2*1000);
while (proc.isRunning() || (proc.readln(Buffer) != -1))
{
/// the output will not be processed/interpreted by this call, but instead
/// by the gui thread, because that has relevant information neede
if (Buffer!="")
{
Buffer.remove('\n');
Buffer.
remove(QChar(13));
qDebug("posting 1 event");
}
if (toBeStoppedProcs.contains(proc.name()) || toBeStoppedProcs.contains("*")) /// should be interrupted
{
proc.kill(SIGINT); /// try to terminate nicely
if (!proc.wait(2))
proc.kill(SIGKILL);/// then we kill it
Buffer = "--> Process interrupted by User."; /// get line from output and make it red
}
Buffer = "";
}
timer->stop();
delete timer;
/// erase it from both lists
activeProcs.erase(activeProcs.find(proc.name()));
while (toBeStoppedProcs.contains(proc.name()))
toBeStoppedProcs.erase(toBeStoppedProcs.find(proc.name()));
QApplication::postEvent(this,
new QCustomEvent
((QEvent::Type)1202,
NULL));
/// signal it out
activeProcs.append(proc.name());
proc.start(KProcess::OwnGroup, KProcess::All); /// ownGroup so children spawned by proc can be killed too + comm=alloutput
/// to prevent queueing of messages we start a timer
QTimer *timer = new QTimer(this);
connect( timer, SIGNAL(timeout()), this, SLOT(postAllEvents()) );
timer->start(2*1000);
while (proc.isRunning() || (proc.readln(Buffer) != -1))
{
/// the output will not be processed/interpreted by this call, but instead
/// by the gui thread, because that has relevant information neede
if (Buffer!="")
{
Buffer.remove('\n');
Buffer.remove(QChar(13));
qDebug("posting 1 event");
QApplication::postEvent(this, new QCustomEvent((QEvent::Type)1200, new QString(Buffer))); /// signal it out
}
if (toBeStoppedProcs.contains(proc.name()) || toBeStoppedProcs.contains("*")) /// should be interrupted
{
proc.kill(SIGINT); /// try to terminate nicely
if (!proc.wait(2))
proc.kill(SIGKILL);/// then we kill it
Buffer = "--> Process interrupted by User."; /// get line from output and make it red
QApplication::postEvent(this, new QCustomEvent((QEvent::Type)1201, new QString(Buffer))); /// signal it out
}
Buffer = "";
}
timer->stop();
delete timer;
/// erase it from both lists
activeProcs.erase(activeProcs.find(proc.name()));
while (toBeStoppedProcs.contains(proc.name()))
toBeStoppedProcs.erase(toBeStoppedProcs.find(proc.name()));
QApplication::postEvent(this, new QCustomEvent((QEvent::Type)1202, NULL)); /// signal it out
To copy to clipboard, switch view to plain text mode
i have changed bahviuor so that a timer in the thread sendsallpostedevents every 2 seconds and i have a second timer in the gui class that calls processEvents() every 2 seconds.
Bookmarks