PDA

View Full Version : QProcess::finished()



T1c4L
8th July 2008, 16:55
Hi

How do I connect signal finished() from QProcess?
It is not working, but connect() returns true.



QProcess* app = new QProcess();
// app params setzen
...

// slot connect
connect(app,SIGNAL(finished(int,QProcess::ExitStat us)),this,SLOT(AppFinished()));


Thanks in advance,
Mike

caduel
8th July 2008, 17:06
looks good.
How do you tell it's not working?

And please show us more code.

jacek
8th July 2008, 23:28
How do you start the process? Make sure you don't use any static methods.

T1c4L
9th July 2008, 00:07
My goal is to achieve the following use case and I believe i missunderstood the usage of QProcess?

My QT program is starting another program with a given filename, example: word.exe and file.doc or the one mentioned in the code. My Qtprogram shouldnt freeze while the other program is activ. Then I want to know, if the user has exited the other program so i can take care of the newly edited doc file...


QProcess* app = new QProcess();
// app params
QStringList args;
args.push_back(Filename().c_str()); // Filename coming from somewhere else looking like this "C:\someplace\file.mm"
app->start("c:\\Programme\\Freemind\\Freemind.exe",args);

// slot connect
connect(app,SIGNAL(finished(int,QProcess::ExitStat us)),this,SLOT(AppFinished()));

jacek
9th July 2008, 00:12
app->start("c:\\Programme\\Freemind\\Freemind.exe",args);

// slot connect
connect(app,SIGNAL(finished(int,QProcess::ExitStat us)),this,SLOT(AppFinished()));
You should make the connection before starting the process to avoid race condition.

What happens if you add the line below?

connect( app, SIGNAL( started() ), qApp, SLOT( about() ) );

T1c4L
9th July 2008, 00:58
hey jacek!

placing the connect before the start() did the trick! its working now, i tested it with notepad, tomorrow i will test it with the freemind program.

I have another question :D, Before QProcess i tested a lil bit with QDesktopServices... and with openurl i was able to lauch a ".mm" file. it was automatically loaded within the apropriate Freemind Tool.

Is it possible to retrieve the location of the freemind.exe ? without searching the entire hdd for it? as you can see the freemind.exe was hardcoded in my previous post. Thats a bad thing we both know it ^^. Any hint for that?

im using STL c++ and QT 4.3.4

T1c4L
9th July 2008, 09:39
Hi Jacek,

the code is not working, it worked with notepad but somehow its not working =(

please take a look:



QStringList args;
args.push_back(filename);
m_MindMapApp = new QProcess();
connect(m_MindMapApp,SIGNAL(finished(int,QProcess: :ExitStatus)),this,SLOT(testv()));
m_MindMapApp->start("c:\\Programme\\FreeMind\\Freemind.exe", args);


testv() slot isnt called once..

caduel
9th July 2008, 09:50
* does your program get started (a window pops up)?
* if not or unsure:
* is the path to your exe correct?
* call waitForStarted() and print the exitCode() to stderr to see if the programm gets executed
* did connect return true?

T1c4L
9th July 2008, 09:54
connect returns true,

the application freemind which im trying to start is open and the file is been loaded too.

But my slot wont be accessed after closing the freemind application.

T1c4L
9th July 2008, 11:34
ok guys! i found the true source of the problem.

the connect n everything is working fine when i use it with winamp, notepad or vlc.

But the Freemind program doesnt! Its only emiting finished() after i started the application but not after quiting it!


The difference between freemind the other tools is, freemind needs Java virtual machine..could that be a problem for QProcess?

any ideas how to solve this problem?

T1c4L
9th July 2008, 15:38
please help me :-(


^^

jacek
9th July 2008, 20:06
Its only emiting finished() after i started the application but not after quiting it!
If it does emit the signal then QProcess works OK. Maybe the application you start spawns another application and quits immediately?