Results 1 to 6 of 6

Thread: PyQT4: application won't start because of spaces in path Qprocess

  1. #1
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default PyQT4: application won't start because of spaces in path Qprocess

    Hello,

    I'm trying to start windows media player using Qprocess (for a windows xp operating system). However, when I run my code, it won't start. I am assuming it is because of the spaces in the path name. How do I fix my code so that it will work with paths that have spaces in it? I am using pyqt4. Thank you in advance.

    Qt Code:
    1. if sys.platform == 'win32':
    2. p = QtCore.QProcess(self)
    3. p.setWorkingDirectory("C:\Program Files\Windows Media Player")
    4. p.start('wmplayer')
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2007
    Posts
    89
    Thanked 21 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PyQT4: application won't start because of spaces in path Qprocess

    Have you tried quoting the path, or escaping the spaces? And also remember to escape slashes: \\
    Qt Code:
    1. p.setWorkingDirectory("\"C:\\Program Files\\Windows Media Player\"")
    2. p.setWorkingDirectory("C:\\Program\\ Files\\Windows Media Player")
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PyQT4: application won't start because of spaces in path Qprocess

    Hello,

    yes, I have tried both, however my gui is still not opening the program. Do you or anyone else have any other suggestions?

  4. #4
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: PyQT4: application won't start because of spaces in path Qprocess

    Try this,

    Qt Code:
    1. QFile file("dummy.bat");
    2.  
    3. if(!file.open(QIODevice::WriteOnly) )
    4. return;
    5.  
    6. file.write(QString("\"C:/Program Files/Windows Media Player/wmplayer\"").toAscii());
    7. file.close();
    8.  
    9. p->start("dummy.bat");
    10.  
    11. if( p->waitForFinished() )
    12. {
    13. file.remove();
    14. return;
    15. }
    To copy to clipboard, switch view to plain text mode 

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

    jaybstory (4th February 2010)

  6. #5
    Join Date
    Nov 2007
    Posts
    89
    Thanked 21 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PyQT4: application won't start because of spaces in path Qprocess

    This is weird. I managed to open a program with the complete path (still have to quote it) but not to open a program in the current working dir. Anyway, I found that if you specify a non existent working directory you will not be able to start any program, neither one in system path (I tried with cmd.exe); so the problem should be not within setWorkingDirectory().
    I hope hat someone with more knowledge about PyQt could help.
    Qt Code:
    1. p = QtCore.QProcess()
    2. p.start("\"C:\\Program Files\\Internet Explorer\\iexplore.exe\"")
    3. # This works.
    4.  
    5. ...
    6.  
    7. p = QtCore.QProcess()
    8. p.setWorkingDirectory("C:\\Program Files\\Internet Explorer")
    9. p.start("cmd.exe")
    10. # This works.
    11.  
    12. ...
    13.  
    14. p = QtCore.QProcess()
    15. p.setWorkingDirectory("C:\\I do not exist")
    16. p.start("cmd.exe")
    17. # This DOES NOT works.
    18.  
    19. ...
    20.  
    21. p = QtCore.QProcess()
    22. p.setWorkingDirectory("C:\\Program Files\\Internet Explorer")
    23. p.start("iexplorer.exe")
    24. # This DOES NOT works.
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to bender86 for this useful post:

    jaybstory (4th February 2010)

  8. #6
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PyQT4: application won't start because of spaces in path Qprocess

    Thanks nikhilqt & bender86. I was able to solve the problem with your guys help!

Similar Threads

  1. QProcess start() failure
    By jacek_ in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2009, 14:04
  2. configuration failure due to spaces in path
    By kondor in forum Installation and Deployment
    Replies: 7
    Last Post: 2nd October 2009, 08:33
  3. QProcess to Start App
    By ManuMies in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2009, 12:58
  4. Replies: 1
    Last Post: 7th April 2008, 16:12
  5. QProcess start automaticaly needed application
    By raphaelf in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 15:11

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.