PDA

View Full Version : Problem with QProgress in Qt4



fyanardi
7th May 2006, 09:26
Hi all,

I'm new in this forum, and also new to Qt4. I have a problem with the new QProgess in Qt4. I need to start an application (a browser) from my application and I have successfully done that in Qt 3 using something similar to this:


QProcess process;
process.setArguments(QStringList() << "mozilla" << url);
if(process.start())
return true;
else
{
process.setArguments(QStringList() << "konqueror" << url);
if (process.start())
return true;
}
return false;

For Qt 4 version, I tried to change
if (process.start()) with
if (QProcess::startDetached("mozilla", QStringList() << url)) return true;
But QProcess::startDetached always returns true even though I dont have mozilla executable (even if I change "mozilla" to "asdf", it still returns true) :confused: .

I tried to use QProcess::start() and QProcess::waitForFinished() but seems that it just makes my application freezing even though the browser was successfully started :( .

Any suggestions? Thanks for your help ;)

jacek
7th May 2006, 14:19
You might try something like this:
QProcess *process = new QProcess();
connect( process, SIGNAL( finished( int, QProcess::ExitStatus ) ), process, SLOT( deleteLater() ) );

process->setArguments( QStringList() << "konqueror" << url );
if( process->waitForStarted() ) {
return true;
}

process->setArguments( QStringList() << "mozilla" << url );
if( process->waitForStarted() ) {
return true;
}

delete process;
return false;But IMO it will be better if you implement a class, for example BrowserLauncher, that would use only non-blocking methods.

Check this: http://qds.berlios.de/services.html#Launcher

fyanardi
7th May 2006, 17:59
Hi, thanks for your help, it solved my problem. But from the documentation I read that Qt4's QProcess no longer has setArgument method, so I changed it to: process->start( "konqueror", QStringList() << url );

Thanks :)