Results 1 to 16 of 16

Thread: Unable to copy a file from one directory to another

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Unable to copy a file from one directory to another

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3. #include <QDir>
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. QDir qd;
    9. QFile srcfile;
    10. QFile destifile;
    11.  
    12. QString dbsrcfilepath = "/Users/user/build-learnOn-Desktop_Qt_5_4_0_clang_64bit-Debug/learnOn.app/Contents/MacOS/learnOn1.sqlite";
    13. dbsrcfilepath = QDir::toNativeSeparators(dbsrcfilepath);
    14. destifile.setFileName(dbsrcfilepath);
    15. if(!(QDir("/Users/user/learnOnContent/").exists()))
    16. QDir().mkdir("/Users/user/learnOnContent/");
    17.  
    18. QString dbdestinationfilepath = "/Users/user/learnOnContent/learnOn.sqlite";
    19. dbdestinationfilepath = QDir::toNativeSeparators(dbdestinationfilepath);
    20. srcfile.setFileName(dbdestinationfilepath);
    21.  
    22. if(!srcfile.exists())
    23. {
    24. bool success = true;
    25. success &= destifile.open( QFile::ReadOnly );
    26. success &= srcfile.open( QFile::WriteOnly | QFile::Truncate );
    27.  
    28. success &= srcfile.write( destifile.readAll() ) >= 0;
    29. destifile.close();
    30. srcfile.close();
    31. }
    32. else
    33. {
    34. srcfile.copy(dbdestinationfilepath);
    35. }
    36.  
    37. return a.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 

    copying from dbsrcfilepath to dbdestinationfilepath
    Last edited by ejoshva; 19th March 2015 at 11:56.

Similar Threads

  1. Replies: 2
    Last Post: 30th January 2015, 17:56
  2. Replies: 1
    Last Post: 27th December 2012, 06:01
  3. QtCreator unable to copy to the clipboard...
    By squimmy in forum Qt Tools
    Replies: 4
    Last Post: 25th December 2012, 12:53
  4. Replies: 2
    Last Post: 15th July 2010, 12:45
  5. Replies: 4
    Last Post: 24th February 2006, 10:30

Tags for this Thread

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.