Results 1 to 5 of 5

Thread: How to copy a file from one directory to another with Qt3.3.3. ?

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default How to copy a file from one directory to another with Qt3.3.3. ?

    Hi,

    I'm looking for a function to copy a file from a directory to another ... but this function is not located in that class.

    Where could I find this function ?

    Then I search a little bit and I discover a class nammed QUrlOperator, is that class could do what I want on a windows file system ? If yes how does it works ?

    I code the two following slots
    Qt Code:
    1. void testDialog::init()
    2. {
    3. QString message;
    4. QUrlOperator op("c:\\user\\AFile.txt");
    5. QUrlInfo fi = op.info("c:\\user\\AFile.txt");
    6. message = "Filename = " + fi.name();
    7. write(message);
    8. }
    9.  
    10. void testDialog::write( const QString &line )
    11. {
    12. lb->insertItem(line);
    13. lb->setBottomItem(lb->count()-1);
    14. }
    To copy to clipboard, switch view to plain text mode 

    ... but it does not write the file name, what's wrong with my code ?

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: How to copy a file from one directory to another with Qt3.3.3. ?

    I made some changes to my code

    Qt Code:
    1. QUrlOperator *op = new QUrlOperator();
    2. QString src = "c:/user/AFile.txt";
    3. QString target = "c:/user/AFileCopied.txt";
    4. op->copy(src, target, false, false);
    5.  
    6. QUrlInfo fi = op->info(target);
    7. write(fi.name());
    To copy to clipboard, switch view to plain text mode 

    The file is well copied but my url info object does not give me any info, why ?

  3. #3
    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: How to copy a file from one directory to another with Qt3.3.3. ?

    Probably because QUrlOperator::copy is an asynchronous operation, so in the time of creating that QUrlInfo object the destination might not exist yet.

  4. #4
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: How to copy a file from one directory to another with Qt3.3.3. ?

    Ok ,so I must connect the finished signals to one of my slot to be sure that the operation is over.

    Qt Code:
    1. void testDialog::init()
    2. {
    3. targetPath = QDir::currentDirPath();
    4. targetFile = targetPath+"/AFile.txt";
    5. op = new QUrlOperator(targetPath);
    6.  
    7. connect(op, SIGNAL(finished(QNetworkOperation*)), SLOT(displayInfo(QNetworkOperation* _nop)));
    8.  
    9. nop = op->listChildren();
    10. }
    11.  
    12.  
    13. void testDialog::write( const QString &line )
    14. {
    15. lb->insertItem(line);
    16. lb->setBottomItem(lb->count()-1);
    17. }
    18.  
    19.  
    20.  
    21.  
    22. void testDialog::displayInfo( QNetworkOperation * _nop )
    23. {
    24. QUrlInfo fi = op->info(targetFile);
    25.  
    26. write(fi.name());
    27. }
    To copy to clipboard, switch view to plain text mode 

    but my slot is never called, what's wrong again ?

  5. #5
    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: How to copy a file from one directory to another with Qt3.3.3. ?

    I don't see the code for starting the operation itself. Did you have a look at the example from Qt docs?

Similar Threads

  1. install help nedded.
    By aj2903 in forum Installation and Deployment
    Replies: 9
    Last Post: 13th November 2008, 08:57
  2. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21
  3. errors while installing Qt4.2 in Linux
    By nimmyj in forum Installation and Deployment
    Replies: 11
    Last Post: 13th December 2006, 12:58
  4. create file in another directory
    By raphaelf in forum Qt Programming
    Replies: 3
    Last Post: 16th February 2006, 11:04
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 13:54

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.