Results 1 to 3 of 3

Thread: Command in process does'nt work

  1. #1
    Join Date
    Mar 2008
    Posts
    55
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Command in process does'nt work

    Hello everyone, I've a function which save my firebird db.
    Qt Code:
    1. if(!QFile::exists(QString("%1/Db/TSF_CARNET_REVEILS.FDB").arg(qApp->applicationDirPath())))
    2. {
    3. QMessageBox::critical(this,AppName,"Fichier de base de données introuvable.");
    4. return;
    5. }
    6.  
    7. QProcess proc_copy_db;
    8. QString cmd_proc = QString("copy \"%1\\Db\\TSF_CARNET_REVEILS.FDB\" \"%1\\Db\SaveDb\"").arg(qApp->applicationDirPath().replace("/", "\\"), QDate::currentDate().toString("dd_MM_yyyy"));
    9. proc_copy_db.start(cmd_proc);
    10.  
    11. if (!proc_copy_db.waitForStarted())
    12. return ;
    13.  
    14. proc_copy_db.closeWriteChannel();
    15.  
    16. if (!proc_copy_db.waitForFinished())
    17. return;
    To copy to clipboard, switch view to plain text mode 
    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.

  2. #2
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Command in process does'nt work

    test this function.
    void QProcess::start ( const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite )
    at result you have started() signal or not?

  3. #3
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Command in process does'nt work

    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:
    Qt Code:
    1. QFile f(QString("%1/Db/TSF_CARNET_REVEILS.FDB").arg(qApp->applicationDirPath()));
    2. if (!f.exists())
    3. {
    4. QMessageBox::critical(this, AppName, "Fichier de base de données introuvable.");
    5. return;
    6. }
    7. f.copy(QString("%1/Db/SaveDb/%2").arg(qApp->applicationDirPath(), QDate::currentDate().toString("dd_MM_yyyy")));
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to communicate Qt Process with non-qt process
    By nrabara in forum Qt for Embedded and Mobile
    Replies: 9
    Last Post: 15th February 2009, 21:01
  2. Process Read/Write
    By QbelcorT in forum Newbie
    Replies: 0
    Last Post: 20th November 2008, 03:08
  3. QActions don't work with menubar hidden
    By Pepe in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 01:04
  4. Send a key to process
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2007, 17:37
  5. How to activate another process?
    By gtthang in forum Qt Programming
    Replies: 6
    Last Post: 3rd February 2006, 07:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.