PDA

View Full Version : Command in process does'nt work



mourad
1st June 2009, 09:25
Hello everyone, I've a function which save my firebird db.
if(!QFile::exists(QString("%1/Db/TSF_CARNET_REVEILS.FDB").arg(qApp->applicationDirPath())))
{
QMessageBox::critical(this,AppName,"Fichier de base de données introuvable.");
return;
}

QProcess proc_copy_db;
QString cmd_proc = QString("copy \"%1\\Db\\TSF_CARNET_REVEILS.FDB\" \"%1\\Db\SaveDb\"").arg(qApp->applicationDirPath().replace("/", "\\"), QDate::currentDate().toString("dd_MM_yyyy"));
proc_copy_db.start(cmd_proc);

if (!proc_copy_db.waitForStarted())
return ;

proc_copy_db.closeWriteChannel();

if (!proc_copy_db.waitForFinished())
return;
The problem is that the process exit from waitForStarted. I've tried to obtain the exitCode and Error but always I've 0 and Unknow Error.
Can anyone tell me where I'm wrong and what to do to resolve this problem.
This function is lunched by button clik.
Many thanks in advance.
Best regards.

kwisp
1st June 2009, 21:12
test this function.


void QProcess::start ( const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite )


at result you have started() signal or not?

shentian
2nd June 2009, 09:12
You forgot to escape the backslash before SaveDb. This results probably in an invalid copy command, and thats why the process doesn't start.

Also, a %2 seems to be missing in the copy command string to take the second argument of QString::arg.

Did you consider using QFile::copy instead of starting a process:


QFile f(QString("%1/Db/TSF_CARNET_REVEILS.FDB").arg(qApp->applicationDirPath()));
if (!f.exists())
{
QMessageBox::critical(this, AppName, "Fichier de base de données introuvable.");
return;
}
f.copy(QString("%1/Db/SaveDb/%2").arg(qApp->applicationDirPath(), QDate::currentDate().toString("dd_MM_yyyy")));