Results 1 to 2 of 2

Thread: QProcess::startDetached fails on Mac

  1. #1
    Join Date
    Aug 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QProcess::startDetached fails on Mac

    Use the following code to launch and external program that needs to continue running after the app that launches it closes:
    QString app = "myApp";
    QProcess::startDetached(app);

    This works fine in windows but it fails on the Mac. Why? The app attempting the launch doens't hang, it just returns a false for success/failure.

    I've tried adding the .app after the name, I've even tried setting the working directory to both the apps dir and the myApp.app/Contents/MacOS directory. Still nothing.

    Any help is appreciated!

    [Added by Edit]
    I can successfully launch myApp by the following:
    QProcess::startDetached("/usr/bin/open", QStringList() << "path_to_myApp/myApp.app");

    Does it have to be like this?
    Thanks
    Last edited by sgmurphy19; 19th September 2008 at 22:30.

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess::startDetached fails on Mac

    The applications path is different on all OS!

    This is a way to find installed MiniScribus http://code.google.com/p/fop-miniscribus/

    first get path from appication executable and after run its...


    Qt Code:
    1. /* find cpl MiniScribus path or exe
    2. */
    3. static inline QString getFOPDefaultExeName()
    4. {
    5. QString exename;
    6. QString foppath;
    7. #if defined Q_WS_WIN
    8. QFileInfo Pinfo;
    9. // Try to locate Miniscribus thanks to the qsetting
    10. QSettings softs("HKEY_LOCAL_MACHINE\\Software",QSettings::NativeFormat);
    11. QStringList allsoftware = softs.childGroups();
    12. QStringList ppkonly = allsoftware.filter(QRegExp("1-PPK-Schweiz"));
    13. for (int i = 0; i < ppkonly.size(); ++i) {
    14. const QString RealName = ppkonly.at(i); /* realpath */
    15. ///////////qDebug() << "### soft " << RealName;
    16. if (softs.value(RealName+"/FOP MiniScribus/path").toString().size() > 6 ) {
    17. foppath = softs.value(RealName+"/FOP MiniScribus/path").toString();
    18. foppath.append(softs.value(RealName+"/FOP MiniScribus/Bundlename").toString()+".exe");
    19. return foppath;
    20. }
    21.  
    22.  
    23. }
    24.  
    25. /* win not having GPL Ghostscript ! */
    26. foppath = "";
    27. return foppath;
    28. #endif
    29. #if defined Q_WS_MAC
    30. foppath = "/Applications/MiniScribus.app/Contents/MacOS/MiniScribus";
    31. #endif
    32. #if defined Q_WS_X11
    33. foppath = getGSLinuxPath(QString("MiniScribus") );
    34. #endif
    35. return foppath;
    36. /* forum http://www.qtcentre.org/forum/f-qt-programming-2/t-qsettings-read-only-avaiable-10254.html */
    37. }
    38.  
    39. extern inline QString getGSLinuxPath( QString apps = QString("gs") )
    40. {
    41. QStringList potential_paths;
    42. potential_paths.append("/usr/local/bin");
    43. potential_paths.append("/sw/bin"); /* to use on mac as same */
    44. potential_paths.append("/opt/bin");
    45. QProcess *process = new QProcess(NULL);
    46. process->setReadChannelMode(QProcess::MergedChannels);
    47. QStringList env = process->systemEnvironment();
    48. env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;"+potential_paths.join(";"));
    49. process->setEnvironment(env);
    50.  
    51. process->start( QString("which") , QStringList() << apps , QIODevice::ReadOnly );
    52. if (!process->waitForFinished()) {
    53. return QString();
    54. } else {
    55. QString finder = process->readAll().trimmed();
    56. if (finder.endsWith(apps,Qt::CaseInsensitive)) {
    57. ///////////// qDebug() << "### finder " << finder;
    58. return finder;
    59. } else {
    60. return QString();
    61. }
    62. }
    63. }
    To copy to clipboard, switch view to plain text mode 


    and here run appication + params to create a pdf from template...

    Qt Code:
    1. proc = new QProcess(this); /* */
    2. connect(proc, SIGNAL(finished(int)),this, SLOT(RegisterPDFstream(int)));
    3. proc->start(Generate_Command());
    4.  
    5. /* if finished get pdf stream and save on db mysql */
    6.  
    7.  
    8.  
    9. QString Invoice::Generate_Command()
    10. {
    11.  
    12. if (Current_Faktura.barcode_value.size() < 1) {
    13. QMessageBox::information(0, tr("File Error"),tr("Unable to read barcode nummer!"));
    14. return QString();
    15. }
    16. Result_fop_file_final = QString("%1/%2_result_code.fop")
    17. .arg(FAKTURA_CACHEDIR)
    18. .arg(Current_Faktura.barcode_value);
    19.  
    20. QFile f( Result_fop_file_final ); /* old pdf file */
    21. if (f.exists()) {
    22. f.remove();
    23. }
    24.  
    25. registro->FillOnFile(FopWorkingActual.absoluteFilePath(),textEdit->toPlainText(),0,Result_fop_file_final);
    26. QFile f2( PRINTONFILEFAKE ); /* old pdf file */
    27. if (f2.exists()) {
    28. f2.remove();
    29. }
    30.  
    31.  
    32. #if defined Q_WS_WIN
    33. cmd.append("\""+FopAppsFullPath+"\"");
    34. cmd.append("-pdf");
    35. cmd.append("\""+PRINTONFILEFAKE+"\"");
    36. cmd.append("\""+Result_fop_file_final+"\"");
    37. #else
    38. cmd.append(FopAppsFullPath);
    39. cmd.append("-pdf");
    40. cmd.append(PRINTONFILEFAKE);
    41. cmd.append(Result_fop_file_final);
    42. #endif
    43. QString makepnggreycommand = cmd.join(" ");
    44. return makepnggreycommand;
    45. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. compiling hello world after fresh install fails
    By kvesi in forum Installation and Deployment
    Replies: 3
    Last Post: 19th September 2008, 13:55
  2. TableModel update fails with qt4.4.1
    By maxel in forum Qt Programming
    Replies: 0
    Last Post: 4th September 2008, 18:01
  3. Release build fails to find some resource images
    By MrGarbage in forum Installation and Deployment
    Replies: 3
    Last Post: 8th December 2007, 16:04
  4. CreateCompatibleBitmap fails in QPixmap
    By JimBrown in forum Qt Programming
    Replies: 14
    Last Post: 29th May 2007, 15:24
  5. Qt 4.1.2 Fails to build on Linux
    By rohandhruva in forum Installation and Deployment
    Replies: 6
    Last Post: 16th April 2006, 21:44

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.