PDA

View Full Version : Quick help on QProcess



devilj
17th July 2007, 19:56
I am trying to use QProcess to call a perl script. Here is my code:

Window.h


private slots:
void processIT();
void output(const QString &text);
private:
QProcess process;

Window.cpp


void Window::processIT()
{
connect(process,SIGNAL(readyReadStandardOutput()),
this,SLOT(output(const QString &)));
connect(process,SIGNAL(readyReadStandardError(cons t QString &)),
this,SLOT(output()));
QString path(dirEdit->text());
QString program("perl /home/jim/perlQt/moalq.pl ");
program += path;
process.start(program);
}

//....

void Window::output(const QString &text)
{
out->append(text);

}




my app compiles but I get the following at runtime:

Object::connect: No such slot Window::process()


Any ideas?

marcel
17th July 2007, 20:05
First of all, this is not correct:


connect(process,SIGNAL(readyReadStandardOutput()),
this,SLOT(output(const QString &)));

A slot may have a shorter signature than the incoming signal, but not the way around.
Hint: make the parameter for output a default one:


void output(const QString &text = "");
...
connect(process,SIGNAL(readyReadStandardOutput()),
this,SLOT(output()));

This will work.

As for the runtime error, that does not make any sense unless you have somewhere in your application a slot called process or you try connecting a signal to an nonexistent process() slot.

Regards

jacek
17th July 2007, 20:48
QObject::connect: No such slot Window::process()
Shouldn't it be processIT()?

marcel
17th July 2007, 20:51
Shouldn't it be processIT()?
Yes, that confuses me too.
Maybe it is just a copy paste error.

But, if it is processIT, where do you connect to processIT? Could you post that code too?

Regards

devilj
17th July 2007, 22:16
You guys are right!


I had this for my process button:
processButton = createButton(tr("&Process"), SLOT(process()));

should be ...SLOT(processIT()));


A slot may have a shorter signature than the incoming signal, but not the way around.
Hint: make the parameter for output a default one:

Should I forget about passing a parameter to the output() function.
in essence:

//......
connect(&process,SIGNAL(readyReadStandardOutput()),
this,SLOT(output()));
//.......
and then setup output as:


void Window::output()
{
out->append(QString(process.readyReadStandardOutput())) ;
}