Results 1 to 2 of 2

Thread: Rename a lot of files by QFile and QFileSystemModel

  1. #1
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Rename a lot of files by QFile and QFileSystemModel

    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include <QDir>
    4. #include <QFileSystemModel>
    5. #include <QString>
    6. #include <QTableView>
    7. #include <QTreeView>
    8.  
    9. int main( int argc, char **argv )
    10. {
    11. QApplication app( argc, argv );
    12.  
    13. QFileSystemModel model;
    14. QString const rootPath = "E:/file_test/very big";
    15.  
    16. QTableView view;
    17. view.setModel(&model);
    18. view.setRootIndex(model.setRootPath(rootPath));
    19.  
    20. view.show();
    21. //....select the data you want to rename from the view
    22. //let us assume I select 8000 of jpg files
    23.  
    24. //don't know how to rename the file by QFileSystemModel, so I use QFile instead
    25. QDir::setCurrent(rootPath);
    26. model.blockSignals(true);
    27. view.blockSignals(true);
    28. for(int i = 0; i != 8000; ++i)
    29. {
    30. QFile file(rootPath + "/kkk" + QString::number(i) + ".jpg");
    31. file.rename("jjj" + QString::number(i) + ".jpg");
    32. }
    33. model.blockSignals(false);
    34. view.blockSignals(false);
    35.  
    36. //the program will stall
    37. qDebug() << "finish";
    38.  
    39. return app.exec();
    40. }
    To copy to clipboard, switch view to plain text mode 

    The UI would stall (become "blank" one before the the all of the files have changed their name)
    I do try multi-thread (boost::thread) and QTimer::singleShot, but it is still stallif
    besides, if I using multi-thread if will emit warning like "it is unsafe to use QPixmap in other
    thread", so I better don't use it.

    I added a progress bar to show the progress, but the progress bar also stall
    How could I make the UI become alive when the files being rename?Thanks

  2. #2
    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: Rename a lot of files by QFile and QFileSystemModel

    [wiki]Keeping the GUI Responsive[/wiki]
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following 2 users say thank you to wysota for this useful post:

    owais_blore (7th December 2012), stereoMatching (26th July 2012)

Similar Threads

  1. Using rename in Qfile
    By jvwlong in forum Newbie
    Replies: 1
    Last Post: 24th July 2012, 06:51
  2. adding files to QFileSystemModel
    By gluchu in forum Newbie
    Replies: 1
    Last Post: 11th July 2012, 00:25
  3. how can i list of files to QFileSystemModel?
    By aurora in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2012, 07:28
  4. QFile or QDir rename()
    By maxpower in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2009, 17:50
  5. QFile::rename()
    By Bagstone in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2008, 10:53

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.