PDA

View Full Version : Trying to use QProcess



hybrid_snyper
20th October 2009, 11:43
Hi again,

Just wondering if anyone would mind having a look at an issue I am having and maybe point out where I am going wrong.

I have created a simple widget with a push button it Qt Designer, I have created Signals and Slots, clicked() and process_started() respectively. I am trying to run another Qt application when the push button is pressed.

However I keep getting compile errors which I cannot seem to resolve, so hopefully a fresh pair of eyes may be able to assist.



mainwindow.cpp:19: error: ISO C++ forbids declaration of ‘process_started’ with no type
mainwindow.cpp:19: error: prototype for ‘int mainwindow::process_started()’ does not match any in class ‘mainwindow’
mainwindow.h:25: error: candidate is: void mainwindow::process_started()




class mainwindow : public QMainWindow
{
Q_OBJECT

public:
mainwindow();
QProcess *process;

public slots:
void process_started();




mainwindow::mainwindow()
{
process = new QProcess();
widget.setupUi(this);
}

mainwindow::process_started()
{
process->start("./home/i386-qt-rss");
}




int main(int argc, char *argv[])
{
QApplication app(argc, argv);
mainwindow w;
w.show();
return app.exec();
}


Thanks very much for having look.

HS

spirit
20th October 2009, 11:52
you forgot to add forward declaration for QProcess class


...
class QProcess;
class mainwindow : public QMainWindow
{
...
};

spirit
20th October 2009, 11:55
also, you forgot to specify type for function


void mainwindow::process_started()
{
process->start("./home/i386-qt-rss");
}

hybrid_snyper
20th October 2009, 12:00
also, you forgot to specify type for function


void mainwindow::process_started()
{
process->start("./home/i386-qt-rss");
}


You know something, I am sitting here looking at some example code and I don't know how I missed that, once you pointed it out I gave my forehead a bloody hard slap.

Thanks very much.

hybrid_snyper
20th October 2009, 12:10
Just to add, this has now compiled, however I thought the app the process is linked to would have started and opened up. I can see that there hass been a thread created when I click the pushbutton but nothing appears on screen. Is this normal?

spirit
20th October 2009, 12:19
if you need call program in a new process use QProcess::startDetached. in this case you will see a separate window.

hybrid_snyper
20th October 2009, 14:49
So I take it once startDetached is called then the first application is not aware of the second, ie when the launched app has finished and has been cloased?

spirit
20th October 2009, 14:55
it depends on how it works.
if you need to know when this app will stopped then you should use QProcess::start and handle signals QProcess::started & QProcess::finished.