PDA

View Full Version : QProcess issue



bunjee
15th July 2009, 14:18
Hey there,

I keep having the same issue with QProcess:

My run function:


void qkReceptor::run()
{
// A timer to avoid high CPU charge
QTimer timer;

connect(&timer, SIGNAL(timeout()), this, SLOT(onCheckStdin()), Qt::DirectConnection);
connect(this, SIGNAL(newLine(QString)), this, SLOT(onNewLine(QString)), Qt::BlockingQueuedConnection);

timer.start(100);

QThread::exec();
}

My stop function:


void qkReceptor::stop()
{
if (this->isRunning())
{
this->quit();
this->wait(); // This never return
}
}

My stop function doesn't seem to work on MacOSX, although it works on win32.

Anyone ?

wysota
15th July 2009, 14:28
How do you call it? It has to be called from outside the thread. Are you sure you want the connection with the timer to be a direct connection? You do realize it will be a direct call "across" threads? The slot will be called on an object living in the main thread from the context of the worker thread.

bunjee
15th July 2009, 15:52
Looks like we're right on it.

When I comment :

connect(&timer, SIGNAL(timeout()), this, SLOT(onCheckStdin()), Qt::DirectConnection);

The program exits properly.

With DirectConnection I thought it would call the slot inside the thread.

This thread is suppose to watch stdin.

bunjee
15th July 2009, 16:57
Tried this:


void qkReceptor::run()
{
// A timer to avoid high CPU charge
QTimer timer;

qkReceptorThread receptor;

connect(&timer, SIGNAL(timeout()), &receptor, SLOT(onCheckStdin()), Qt::DirectConnection);
connect(&receptor, SIGNAL(newLine(QString)), this, SLOT(onNewLine(QString)), Qt::BlockingQueuedConnection);

timer.start(100);

QThread::exec();
}

void qkReceptorThread::onCheckStdin()
{
QTextStream stream(stdin);

// return; // When returning here, the program exits properly.

// Do we have a new line to be read ?
QString line = stream.readLine();

while (line.isNull() == false)
{
if (line.isEmpty() == false)
{
// Do something with our line
emit newLine(line);
}

line = stream.readLine();
}
}

Still doesn't work.

wysota
15th July 2009, 21:07
I'd say you are blocking on readLine(). If there is nothing to read the function probably blocks until there is something to be read. You should use QSocketNotifier instead of such solution.

Rajeshsan
21st December 2009, 08:40
Hi to all,
I'm using Embedded Linux Board. I tried to do Qprocess class implementation. by using all available examples I'm able to open Terminal program in Qt. Just i have a button on clicked.
QString program="Terminal.exe";
proc =new QProcess;
proc->start(program);

Now i'm gettin Terminal Window.I can execute some exe files by giving its exact PATH in program.Next process is to send Command "ls" to terminal by using Qt. By clicking on next (new) button.How can i send to terminal. now clicking on button, so im getting terminal Window, in the same window in need to send command "ls -l".