Results 1 to 7 of 7

Thread: file copy in Qt 3.3.4 ?

  1. #1
    Join Date
    Mar 2006
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Smile file copy in Qt 3.3.4 ?

    Hi all,

    I am trying to copy directory and it files.

    For that I need to use QFile::copy ..

    But I'm not able to get copy method in Qt 3.3.4 QFile class.

    Where can I find the copy method ... Is there any other option to do that ??

    thanks for any ideas.

  2. #2
    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: file copy in Qt 3.3.4 ?

    EDIT:
    See wysotas answer.

    You will have to implement it your self.
    Along the lines of:
    - open source file
    - open target file
    - read source file
    - write read content in to target file
    - close both files.

    It could look something like:
    Qt Code:
    1. QFile source("file1");
    2. QFile dest("file2");
    3. //open the files with the right IO flags
    4. QDataStream readStream(&source);
    5. QDataStream writeStream(&dest);
    6. writeStream<<readStream;
    7.  
    8. //close files
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 1st March 2006 at 12:02.

  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: file copy in Qt 3.3.4 ?

    QUrlOperator::copy()

  4. #4
    Join Date
    Mar 2006
    Posts
    74
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: file copy in Qt 3.3.4 ?

    Quote Originally Posted by wysota
    QUrlOperator::copy()

    I have not been able to get this to work. Here is my code:

    Qt Code:
    1. QUrlOperator urlOp;
    2.  
    3. ....
    4.  
    5. qDebug(TargetSelector->getFilename());
    6. qDebug(dirs.ref_dir + (QString) "/");
    7.  
    8. // copy the reference file to ~/.lprof/target_refs
    9. urlOp.copy( TargetSelector->getFilename(), dirs.ref_dir + (QString) "/");
    To copy to clipboard, switch view to plain text mode 

    The two qDebug lines are to confirm that the from file name and the to directory name are both correct (they are). I tried with and without the trailing "/" on the to directory. What do I need to do to make this work?

  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: file copy in Qt 3.3.4 ?

    Try without using "~".

  6. #6
    Join Date
    Mar 2006
    Posts
    74
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: file copy in Qt 3.3.4 ?

    I am not using "~". The files are being copied into a user configuration directory. So the reference to ~/.lprof/target_refs in the comment is short hand for the file is being copied to the user's home directory. The code is using the fully qualified path to the location where the file should be copied. It is also using a fully qualified from file name.

    This code is a rewrite of code that built a cp or copy command string (depending on OS) and then called system to copy the file. The code using system call has been in production for some months now. I used qDebug to dump out the from and to file/directory to the console and these are correct. I should have removed the comment as it was aparently confusing.

  7. #7
    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: file copy in Qt 3.3.4 ?

    QUrlOperator in an asynchronous class. It means that when you issue copy(), the application is not blocked until the copy is finished, but it goes on. You created your operator on stack. When you exit the function all stack objects (including your QUrlOperator) are destroyed. QUrlOperator just doesn't have enough time to carry out the operation. Try creating it on heap instead (QUrlOperator *op = new QUrlOperator(...)).

  8. The following user says thank you to wysota for this useful post:

    hvengel (1st April 2006)

Similar Threads

  1. Windows file copy in progress, how can I tell?
    By tgreaves in forum Qt Programming
    Replies: 4
    Last Post: 23rd February 2009, 17:42
  2. Copy a File over the Network
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 17th June 2008, 12:36
  3. copy and run a .exe file in another system
    By sabeesh in forum Installation and Deployment
    Replies: 3
    Last Post: 22nd August 2007, 10:05
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Qt 3.3.4 -> Qt 4.1.2, moc file issue
    By philski in forum Qt Tools
    Replies: 1
    Last Post: 11th September 2006, 21:08

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.