Results 1 to 5 of 5

Thread: Problem while trying to copy an XML file from one location to another in Linux

  1. #1
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem while trying to copy an XML file from one location to another in Linux

    Hi all,

    I am facing one problem while copying an XML file from one place to another place in my filesystem.I am using following code for copying. Test1 and Test2 are the different folders.

    but everytime both the boolean variables are returning false.I dont have any idea.

    Could anyone plz help me ?

    Qt Code:
    1. QString FirstPath = QDir::currentPath()+QDir::separator()+"Test1"+ QDir::separator() +"Test1.xml";
    2. FirstPath = QDir::toNativeSeparators(FirstPath);
    3. qDebug()<<FirstPath;
    4.  
    5. QString SecondFilePath = QDir::currentPath()+QDir::separator()+"Test1" + QDir::separator()+ "Test2" +QDir::separator()+ "Test2.xml";
    6. SecondFilePath = QDir::toNativeSeparators(SecondFilePath);
    7. qDebug()<<SecondFilePath;
    8. QFile file;
    9.  
    10. if (!file.exists(FirstPath))
    11. {
    12. QFile file(SecondFilePath);
    13. bool ret1= file.copy(FirstPath);
    14. qDebug()<<ret1;
    15. }
    16. QFile prefFile(FirstPath);
    17.  
    18. bool ret2= prefFile.setPermissions(QFile::WriteUser);
    19. qDebug()<<ret2;
    To copy to clipboard, switch view to plain text mode 

    Trying to access these paths,

    Test1->Test2->Test2.xml & Test1->Test1.xml

  2. #2
    Join Date
    Mar 2007
    Posts
    57
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem while trying to copy an XML file from one location to another in Linux

    Why don't you use: bool QFile::copy ( const QString & fileName, const QString & newName ) [static]

    Furthermore, did you check whether the source file exists according to QFile?

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

    Default Re: Problem while trying to copy an XML file from one location to another in Linux

    Are you trying to overwrite a file?
    Note that if a file with the name newName already exists, copy() returns false (i.e. QFile will not overwrite it).
    ==========================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.

  4. #4
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: Problem while trying to copy an XML file from one location to another in Linux

    yaa, i tried with bool QFile::copy ( const QString & fileName, const QString & newName ) [static] also...............


    but the result is same....its not copied............

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem while trying to copy an XML file from one location to another in Linux

    Your code is confusing. What are you trying? Copying FirstPath to SecondFilePath or SecondFilePath to FirstPath. If you want "FirstPath to SecondFilePath" then your syntax if wrong.
    How does your file system and privileges look like? Post the return of "ls -lAhR" inside your directory: QDir::currentPath()+QDir::separator()+"Test1".

    EDIT: forget about the "ls -lAhR" since you are working on windows. Then you must write it by hand...

Similar Threads

  1. Copy a log file
    By fortyhideout12 in forum Qt Programming
    Replies: 2
    Last Post: 15th August 2009, 08:05
  2. Copy a File with QT
    By undercover in forum Newbie
    Replies: 3
    Last Post: 13th February 2009, 16:33
  3. copy file
    By deepa.selvaraj in forum Qt Programming
    Replies: 1
    Last Post: 25th October 2007, 07:53
  4. Copy a file?
    By whitefurrows in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 21:05
  5. file copy in Qt 3.3.4 ?
    By npc in forum Newbie
    Replies: 6
    Last Post: 31st March 2006, 14:43

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
  •  
Qt is a trademark of The Qt Company.