Results 1 to 2 of 2

Thread: Problem with QFile and copying;

  1. #1
    Join Date
    Sep 2009
    Posts
    34
    Thanks
    28
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Problem with QFile and copying;

    Hi there guys,

    I have a bit of a problem here, I have the following code:

    Qt Code:
    1. QFile file;
    2. QString newpath;
    3. newpath = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
    4. "/", QFileDialog::ShowDirsOnly
    5. | QFileDialog::DontResolveSymlinks);
    6.  
    7. file.copy ( "/Applications/medadmin/sampledatabase", newpath);
    To copy to clipboard, switch view to plain text mode 

    The problem is: it doesn't copy the file to the place the user has selected it to.

    What am I doing wrong? Any suggestions would be greatly appreciated;


    Thanks in advance,

    Nefastious

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QFile and copying;

    The 'copy' method you are using is static, so doesn't require an object. Therefore QFile::copy is fine, rather than file.copy. I doesn't make any difference but I like to emphasize that fact in the code, and if your only using static methods from a class, why waste the memory allocating the object?

    Secondly, what does 'copy' return? You should always check return values of functions that return such values. If it's false then the function failed, most likely because the destination file already exists, couldn't be opened, or the path is invalid.

    The documentation mentions nothing about copying to just a path (ie. no filename included), so I would assume this means it doesn't handle it.

  3. The following 2 users say thank you to squidge for this useful post:

    Nefastious (31st October 2009), rawfool (18th June 2013)

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.