Results 1 to 4 of 4

Thread: Renaming file using QDir::rename

  1. #1
    Join Date
    Jul 2013
    Posts
    27
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Renaming file using QDir::rename

    Hello friends,
    I am trying to swap two file names using QDir::rename. I have 2 files 100.jpg and 101.jpg. But it fails as the new filename exists and rename fails if new filename already exists. I tried the old engineering method, a,b,c the three variables. Then c=a, a=b, b=c. But this also fails with rename. Kindly let me know what to do. Thank you for your time.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Renaming file using QDir::rename

    Please post your code.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jul 2013
    Posts
    25
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Renaming file using QDir::rename

    I need to rename pushbutton's name dynamically.
    Can you suggest a method for that..
    Thanks in advance

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Renaming file using QDir::rename

    I tried the old engineering method, a,b,c the three variables. Then c=a, a=b, b=c. But this also fails with rename. Kindly let me know what to do. Thank you for your time.
    Do this..
    1. Copy a to c
    2. Delete a
    3. Copy b to a
    4. Delete b
    5. Copy c to b
    6. Delete c
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Rename File
    By lsropia in forum General Programming
    Replies: 3
    Last Post: 22nd October 2011, 12:47
  2. rename file name
    By weixj2003ld in forum Qt Programming
    Replies: 11
    Last Post: 8th April 2010, 11:27
  3. QFile or QDir rename()
    By maxpower in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2009, 18:50
  4. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 20:41
  5. How to rename a file after opening ?
    By npc in forum Newbie
    Replies: 2
    Last Post: 1st June 2006, 14:36

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.