PDA

View Full Version : Call QProcess without GUI



mattia
5th November 2007, 12:49
Hi, what what should i write into the connect function to call the slot updateError() that is into the CallApplication class?
The connect function in not declared in this scope but i dont need that the callApplication.h derive by QMainWindow or something like that. Is there a work around?
i want just to call a extern process without any GUI.

callApplication.h


#include <QProcess>

class CallApplication
{
public:
CallApplication();
~CallApplication();
void performApplication();
private slots:
void updateError();
void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
void processError(QProcess::ProcessError error);
public:
QProcess process;
};


callApplication.cpp


#include <callApplication.h>

CallApplication::CallApplication()
{
connect(&process, SIGNAL(readyReadStandardError()), /*CallApplication*/, SLOT(updateError())); //<--the reciver is CallApplication
}

CallApplication::~CallApplication(){}

void CallApplication::performApplication()
{
QStringList args;
args << "-resize" << "100x100" << "/home/mattia/image1/1.jpg";
process.start("mogrify", args);
}
void CallApplication::updateError(){}

void CallApplication::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
}


void CallApplication::processError(QProcess::ProcessErr or error)
{
}

DeepDiver
5th November 2007, 13:04
simply use: this

mattia
5th November 2007, 14:13
Do you mean in this way?

connect(&process, SIGNAL(readyReadStandardError()), this, SLOT(updateError()));
I get this error: connect was not declered in this scope

DeepDiver
5th November 2007, 14:18
Try this:


QObject::connect(&process, SIGNAL(readyReadStandardError()), this, SLOT(updateError()));

mattia
5th November 2007, 14:22
now i get the access at the connect function but something still wrong, i get this error:
no matching function for call to ‘QObject::connect(QProcess*, const char [26], CallApplication* const, const char [15])’

jacek
5th November 2007, 14:29
CallApplication doesn't inherit QObject and it lacks Q_OBJECT macro --- without this signals & slots mechanism won't work.

mattia
5th November 2007, 14:33
So, have i to declare the .h class in this way?


#include <QProcess>

class CallApplication : public QObject
{
Q_OBJECT
public:
CallApplication();
~CallApplication();
void performApplication();
private slots:
void updateError();
void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
void processError(QProcess::ProcessError error);
public:
QProcess process;
};

jacek
5th November 2007, 14:34
So, have i to declare the .h class in this way?
Yes, and don't forget to re-run qmake.

mattia
5th November 2007, 14:39
Done! Now it's working. Thanks so much.