Results 1 to 4 of 4

Thread: QProcess problem to start executable

  1. #1
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QProcess problem to start executable

    Hi to all,
    it's driving me crazy, trust me. Let me show you the code:

    Qt Code:
    1. void frmMain::dumpSqliteDatabase()
    2. {
    3. QString strError;
    4. QString strPathSqlite;
    5.  
    6. QString fileName = "Dump.sql";
    7.  
    8.  
    9. strPathSqlite = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/data/sqlite3.exe");
    10. strPathSqlite.replace("\\","\\\\");
    11.  
    12. p.start(strPathSqlite + " Scrab.db .dump > " + fileName);
    13.  
    14. if (!p.waitForStarted() || !p.waitForFinished(-1) || (p.exitStatus() != QProcess::NormalExit))
    15. {
    16. switch (p.error())
    17. {
    18. case (QProcess::FailedToStart) :
    19. strError = tr("The process failed to start. Either the invoked "
    20. "program is missing, or you may have insufficient permissions to invoke the program.");
    21. break;
    22. case (QProcess::Crashed) :
    23. strError = tr("The process crashed some time after starting successfully.");
    24. break;
    25. case (QProcess::WriteError) :
    26. strError = tr("An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.");
    27. break;
    28. case (QProcess::ReadError):
    29. strError = tr("An error occurred when attempting to read from the process. For example, the process may not be running.");
    30. break;
    31. default:
    32. strError = tr("An unknown error occurred.");
    33. }
    34.  
    35. QMessageBox msgBox;
    36. msgBox.setWindowTitle(tr("!!!"));
    37. msgBox.setIcon(QMessageBox::Warning);
    38. msgBox.setText(strError);
    39. msgBox.setStandardButtons(QMessageBox::Ok);
    40. msgBox.exec();
    41. }
    42. }
    To copy to clipboard, switch view to plain text mode 

    I've tested the same command(C:\data>sqlite3 Scrab.db .dump > Dump.sql) in the windows 7 shell and it works, but the above code doesn't create the dumped file!

    Thanks in advance for yuor help.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess problem to start executable

    QProcess isn't the Windows shell. It doesn't support redirection for example.

  3. The following user says thank you to squidge for this useful post:

    cydside (17th June 2010)

  4. #3
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess problem to start executable

    Hi,

    Try...
    Qt Code:
    1. p.setStandardOutputFile(fileName);
    2. p.start(strPathSqlite + " Scrab.db .dump ");
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to agathiyaa for this useful post:

    cydside (17th June 2010)

  6. #4
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess problem to start executable

    Quote Originally Posted by agathiyaa View Post
    Hi,

    Try...
    Qt Code:
    1. p.setStandardOutputFile(fileName);
    2. p.start(strPathSqlite + " Scrab.db .dump ");
    To copy to clipboard, switch view to plain text mode 
    Thanks, the way is correct!
    I just added the setWorkingDirectory to complete the task as follow:

    Qt Code:
    1.  
    2. p.setStandardOutputFile(fileName);
    3. p.setWorkingDirectory(strWorkingDirectory);
    To copy to clipboard, switch view to plain text mode 

    It finally works!!!

Similar Threads

  1. QProcess Problem: Program doesnt start
    By musaulker in forum Newbie
    Replies: 5
    Last Post: 30th April 2020, 23:07
  2. Replies: 5
    Last Post: 17th March 2010, 18:30
  3. QProcess to Start App
    By ManuMies in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2009, 11:58
  4. How to reload QProcess executable?
    By kommu in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 20:13
  5. Qt3 qprocess, executable exited?
    By triperzonak in forum Newbie
    Replies: 2
    Last Post: 22nd September 2008, 11:21

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.