Calling external programs?
Hi,
I'm new to QT and I can't get calling external programs to work. I have this:
Code:
class mainwindow
: public QMainWindow,
public Ui
::MainWindow{ Q_OBJECT
private:
[...]
[...]
Code:
void mainwindow::doit(){
arguments << "test";
connect(proc, SIGNAL(readyReadStdout()), this, SLOT(readFromStdout()));
if(!proc->start(program, arguments)){
QMessageBox::critical(0,
"fatal error",
"could not start",
"quit");
exit(-1);
}
}
void mainwindow::readFromStdout(){
textEdit->append(???);
}
First, the "start" does not work:
Code:
mainwindow.
cpp:29: error
: no matching function
for call to ‘
QProcess::QProcess(<unresolved overloaded function type>
)’
Second, what to append to textEdit?
Can someone help?
Re: Calling external programs?
Quote:
Originally Posted by
Hossie
Code:
mainwindow.
cpp:29: error
: no matching function
for call to ‘
QProcess::QProcess(<unresolved overloaded function type>
)’
Did you #include <QProcess>?
Quote:
Second, what to append to textEdit?
QProcess::readAllStandardOutput()
Re: Calling external programs?
mainwindow.cpp:
Code:
#include <QtGui>
#include <QProcess>
#include "mainwindow.h"
Re: Calling external programs?
Where is variable named "parent" declared? Did you mean "this" or "parent()"?
Re: Calling external programs?
That part was just a paste. I looked at the constructor again, and it seems all arguments are optional. If I change it to
At least that error disappeared. Now I got an even worse one. :(
Code:
mainwindow.cpp: In member function ‘void mainwindow::doit()’:
mainwindow.
cpp:33: error
: could not convert ‘
((mainwindow
*)this)->mainwindow
::proc->
QProcess::start(((const QString
&)((const QString*)(& program
))),
((const QStringList
&)((const QStringList*)(& arguments
))), QFlags<QIODevice
::OpenModeFlag>
(ReadWrite
))’ to ‘
bool’
:eek::eek::eek:
€: Without the if part, it compiles. But it does not do what expected:
Code:
Object
::connect: No such
signal QProcess::readyReadStdout()Object::connect: (receiver name: 'MainWindow')
Re: Calling external programs?
Quote:
Originally Posted by
Hossie
That part was just a paste. I looked at the constructor again, and it seems all arguments are optional. If I change it to
At least that error disappeared.
Every QObject (QProcess is a QObject) takes a parent parameter for a reason. Make sure to pass a proper parent or delete the object yourself. Otherwise you'll get a memory leak.
Quote:
Now I got an even worse one. :(
Code:
mainwindow.cpp: In member function ‘void mainwindow::doit()’:
mainwindow.
cpp:33: error
: could not convert ‘
((mainwindow
*)this)->mainwindow
::proc->
QProcess::start(((const QString
&)((const QString*)(& program
))),
((const QStringList
&)((const QStringList*)(& arguments
))), QFlags<QIODevice
::OpenModeFlag>
(ReadWrite
))’ to ‘
bool’
Take a closer look at QProcess::start() docs. It's a void function. No bool is returned.
Re: Calling external programs?
Quote:
Originally Posted by
Hossie
€: Without the if part, it compiles. But it does not do what expected:
Code:
Object
::connect: No such
signal QProcess::readyReadStdout()Object::connect: (receiver name: 'MainWindow')
Again, see QProcess docs and see what signals it offers. Don't guess, read the great docs! :)
PS. And make sure you read correct docs. Qt 3 and Qt 4 are different.
Re: Calling external programs?
Ok, thanks, it works now. I still dont quite understand where to get "parent" from. Should I save the parent argument from the constructor and take that for callin QProcess?
Re: Calling external programs?
Quote:
Originally Posted by
Hossie
I still dont quite understand where to get "parent" from. Should I save the parent argument from the constructor and take that for callin QProcess?
QObjects organize themselves in object trees. Every QObject can access its parent any time via QObject::parent(). Do you want the process object to be deleted when the parent of the window is deleted? Most likely not because top level windows usually don't have any parent. Do you want the process object to be deleted when the window is deleted? If yes, pass the window (ie. "this") as a parent.
Re: Calling external programs?
Ok, now I think everything works. Thank you!! :)
Re: Calling external programs?
€: Nevermind. It's working. :)
Re: Calling external programs?
What does QProcess::waitForFinished() return? If it returns false, what does QProcess::error() return?
Re: Calling external programs?
Ok you answered before I edited. You are too fast. :o
I forgot the proc->start() :o:o:o