Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What am i doing wrong with QFile::rename?
Forum Updated to NodeBB v4.3 + New Features

What am i doing wrong with QFile::rename?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MathSquare
    wrote on last edited by
    #1

    @
    Qstring oldName = ("/home/myusername/Desktop/11.txt");
    Qstring newName = ("/home/myusername/Desktop/22.txt");
    bool QFile::rename ( const QString & oldName, const QString & newName );
    @

    http://qt-project.org/doc/qt-4.8/qfile.html#rename

    Please tell me how to fix it and post the code since i am a new user to qt and coming from basic.net.

    [[Moved another thread out of QnA and added code formating, Tobias]]

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Code_ReaQtor
      wrote on last edited by
      #2

      Seems like the title is different from your goal/link...

      Please visit my open-source projects at https://github.com/Code-ReaQtor.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Code_ReaQtor
        wrote on last edited by
        #3

        This works in windows, just change the oldName and newName to machine-specific uri.
        Also, it is only a commandline program.

        @#include <QCoreApplication>
        #include <QFile>
        #include <QDebug>

        int main(int argc, char *argv[])
        {
        QCoreApplication a(argc, argv);
        QString oldName = "D:\11.txt";
        QString newName = "D:\22.txt";
        qDebug()<<QFile::rename(oldName,newName);
        return a.exec();
        }@

        Note that I used qDebug() to show if the "rename" is successful or not.
        QFile::rename() will be only true if "oldName" exists!

        Please visit my open-source projects at https://github.com/Code-ReaQtor.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BelenMuñoz
          wrote on last edited by
          #4

          I think the problem is that you are declaring twice the same variables. When you call the function with arguments that are existing variables, just use the name.

          QFile::rename (oldName, newName );

          PD: As somebody told you in another post, you should learn more about C++.

          Me casé con un enano pa jartarme de reí.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved