Results 1 to 7 of 7

Thread: QProcess and Mac OS 10.6.7 Snow Leopard

  1. #1
    Join Date
    Apr 2011
    Location
    Poland
    Posts
    10
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QProcess and Mac OS 10.6.7 Snow Leopard

    Hi
    I have some problems with running terminal commands using QProcess. Is there any special way to do it?

    Here is my code:
    Qt Code:
    1. void MainWindow::on_actionCreate_triggered()
    2. {
    3. p.start("tar -zcvf " + archivename + " " + filenames);
    4. bool success = p.waitForStarted();
    5. ui->textEdit->append(p.readAllStandardOutput());
    6. ui->textEdit_2->append(p.readAllStandardError());
    7. if(success)
    8. {
    9. std::cout << "tar -zcvf " + archivename.toStdString() + " " +
    10. filenames.toStdString() << std::endl;
    11. }
    12. p.terminate();
    13. }
    To copy to clipboard, switch view to plain text mode 

    My output:
    Starting /Users/olivia/....app/Contents/MacOS/wtorek...
    tar -zcvf archive.tgz *.h *.cpp
    Of course I have tar and in Terminal.app everything is working.
    I have Qt 4.7.2.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QProcess and Mac OS 10.6.7 Snow Leopard

    What is the output of
    Qt Code:
    1. qDebug() << QDir::currentDirPath();
    To copy to clipboard, switch view to plain text mode 
    Does it works if you change the dir before invoking QProcess:
    Qt Code:
    1. QDir::setCurrent("/path/to/dir with/cpp and h files");
    To copy to clipboard, switch view to plain text mode 
    ?

  3. #3
    Join Date
    Apr 2011
    Location
    Poland
    Posts
    10
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess and Mac OS 10.6.7 Snow Leopard

    currentDirPath is not working, so I used currentPath instead (QAssistants advice).

    It shows "/.../wtorek-build-desktop/wtorek.app/Contents/MacOS" what is incorrect. I fixed it with:
    Qt Code:
    1. QDir::setCurrent("../../../../wtorek");
    To copy to clipboard, switch view to plain text mode 

    I also edited p.start:
    Qt Code:
    1. p.start("tar", QStringList() << " -zcvf " + archivename + " " + filenames);
    To copy to clipboard, switch view to plain text mode 

    Now it prints the correct command line command:
    tar -zcvf archive.tgz *.h *.cpp
    But it doesn't work either... I think don't think it starts process, or path to tar is wrong. I also tried /usr/bin/tar without any luck.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QProcess and Mac OS 10.6.7 Snow Leopard

    If you want to provide an argument list, you have to use operator << to add new files, not +. Following code works ok:
    Qt Code:
    1. p.start("C:/Program Files/7-zip/7z.exe", QStringList() << "a" << "test.zip" << "*.cpp");
    2. p.waitForStarted();
    To copy to clipboard, switch view to plain text mode 
    I don't think you should call p.terminate(), maybe your process simply couldn't finish before you teminated it. Try to wait for finished as well:
    Qt Code:
    1. void MainWindow::on_actionCreate_triggered()
    2. {
    3. p.start("tar -zcvf " + archivename + " " + filenames);
    4. if( ! p.waitForStarted() ){
    5. qDebug() << "waitForStarted failed";
    6. return ;
    7. }
    8. ui->textEdit->append(p.readAllStandardOutput());
    9. ui->textEdit_2->append(p.readAllStandardError());
    10. if( !p.waitForFinished() ){
    11. qDebug() << "waitForFinished failed";
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Apr 2011
    Location
    Poland
    Posts
    10
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess and Mac OS 10.6.7 Snow Leopard

    After applaying all your hints I was able to create a working version. I used:
    Qt Code:
    1. void MainWindow::on_actionCreate_triggered()
    2. {
    3. //only for Mac OS X!
    4. QDir::setCurrent("../../../../wtorek");
    5. connect(&p, SIGNAL(readyReadStandardOutput()), this, SLOT(showOutput()));
    6. connect(&p, SIGNAL(readyReadStandardError()), this, SLOT(showErrors()));
    7. p.start("tar -zcvf " + archivename + " " + filenames); --> only version working, others are having troubles with f option and filename
    8. if(!p.waitForStarted() ) {
    9. qDebug() << "waitForStarted failed";
    10. return ;
    11. }
    12. if( !p.waitForFinished() ){
    13. qDebug() << "waitForFinished failed";
    14. }
    15. p.terminate(); --> I can terminate now
    16. }
    17. void MainWindow::showOutput() {
    18. ui->textEdit->append(p.readAllStandardOutput());
    19. }
    20. void MainWindow::showErrors() {
    21. ui->textEdit_2->append(p.readAllStandardError());
    22. }
    To copy to clipboard, switch view to plain text mode 

    But there are still some problems. Why wildcards are not accepted (example *.h)? Moreover in Mac everything is written to sdterr instead of stdout.

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QProcess and Mac OS 10.6.7 Snow Leopard

    p.start("tar -zcvf " + archivename + " " + filenames); --> only version working, others are having troubles with f option and filename
    Maybe you should watch out for additional spaces, because I don't think options passed to program have any influence on QProcess internals, try without the spaces:
    Qt Code:
    1. p.start("tar -zcvf", QStringList() << archivename << filenames.split(QRegExp("\\s"),QString::SkipEmptyParts) );
    To copy to clipboard, switch view to plain text mode 
    p.terminate(); --> I can terminate now
    Yes, but... the process is already finished
    Moreover in Mac everything is written to sdterr instead of stdout.
    Sorry, I'm not a Mac user, can't help you with this one. But have you tried QProcess::setReadChannel ?
    Last edited by stampede; 14th April 2011 at 12:34. Reason: typo in code

  7. #7
    Join Date
    Apr 2011
    Location
    Poland
    Posts
    10
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess and Mac OS 10.6.7 Snow Leopard

    Thanks for help. Additional spaces or no spaces were the problem.

    In Mac OS there is something wrong with channels. App works great on Linux.

Similar Threads

  1. Can't build QtOpenCl on mac snow leopard
    By shaolin in forum Qt Programming
    Replies: 7
    Last Post: 11th December 2010, 13:57
  2. Qt Nokia SDK 1.0 (beta) on Mac os X Snow Leopard
    By SlowTree in forum Installation and Deployment
    Replies: 1
    Last Post: 24th September 2010, 12:50
  3. installing mysql on snow leopard
    By hamid ghous in forum Installation and Deployment
    Replies: 0
    Last Post: 14th January 2010, 11:41
  4. PyQt4 on Snow Leopard in 64 bit
    By bgturk in forum Installation and Deployment
    Replies: 0
    Last Post: 15th September 2009, 20:53
  5. snow leopard broke my QT
    By rogerholmes in forum Installation and Deployment
    Replies: 11
    Last Post: 2nd September 2009, 08:18

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.