Results 1 to 5 of 5

Thread: QProcess use dos comand

  1. #1
    Join Date
    Oct 2008
    Location
    Taiwan
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QProcess use dos comand

    Hi everyone,

    Because QT's rmdir can't really remove the directory which is not empty ,

    therefore, i choose to use QPrcess to execute dos coommand "RD" on windows,

    however it can't work ...

    I type in prmot windows and it works....

    Should the environent set worng ??

    Here is my code:

    void D_DirView::removeFile(void)
    {
    if( m_Process )
    delete m_Process;

    m_Process = new QProcess(this);
    QStringList arguments << "/Q/S" << "D:\\tmp";
    m_Process->start( "RD", arguments )
    }

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QProcess use dos comand

    I don't know, but you could also write a recursive function to empty the dir, then delete it. I did this once:

    Qt Code:
    1. void ResoModule::deleteSoundDir(const QString & dir)
    2. {
    3. QDir sound_dir(dir);
    4.  
    5. //First delete any files in the current directory
    6. QFileInfoList files = sound_dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files);
    7. for(int file = 0; file < files.count(); file++)
    8. {
    9. sound_dir.remove(files.at(file).fileName());
    10. }
    11.  
    12. //Now recursively delete any child directories
    13. QFileInfoList dirs = sound_dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs);
    14. for(int dir = 0; dir < dirs.count(); dir++)
    15. {
    16. deleteSoundDir(dirs.at(dir).absoluteFilePath());
    17. }
    18.  
    19. //Finally, remove empty parent directory
    20. sound_dir.rmdir(sound_dir.path());
    21. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess use dos comand

    Quote Originally Posted by damonlin View Post
    Hi everyone,

    Because QT's rmdir can't really remove the directory which is not empty ,

    therefore, i choose to use QPrcess to execute dos coommand "RD" on windows,
    Baaaaaad idea, because of many reasons. Do it as suggested in the other post.

    however it can't work ...

    I type in prmot windows and it works....

    Should the environent set worng ??
    There is no such thing as "dos command". It's a "command.com command" thus you need to invoke it through command.com instead of calling it directly. There is no binary rd.com on your system, right? So QProcess can't find it.

  4. #4
    Join Date
    Oct 2008
    Posts
    37
    Thanked 2 Times in 2 Posts

    Default Re: QProcess use dos comand

    If you really want to do it the way that you have it - you can probably do via /C for cmd.exe ( cmd /c "rd /q /s whatever" ) and spawn that instead of trying to spawn the nonexistent RD. Putting a /? after cmd in a command prompt will show you all the options available.

    But be warned, as wysota mentioned. It's not a good idea.

  5. #5
    Join Date
    Oct 2008
    Location
    Taiwan
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess use dos comand

    Thank you so much ~~

    I'll implement just like what JimDaniel offer ~~

Similar Threads

  1. Detect First QProcess finished in a group and kill other
    By Davidaino in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 12:53
  2. QProcess exitStatus()
    By user_mail07 in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 20:51
  3. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  4. QProcess extremely slow on Windows?
    By Pepe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 00:25
  5. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 13:30

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.