Results 1 to 8 of 8

Thread: How to return a QFile ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2014
    Posts
    15
    Thanks
    3

    Default Re: How to return a QFile ?

    I wanted to use QFile object because I thought is more understandable and "natural". But yes, you're right, I'm going to use a QString better.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: How to return a QFile ?

    QFile is the class that does data I/O.
    If you only need a reference to the file use either QString or QFileInfo.

    If you need the file, e.g. when you function does more than just create the instance, then return a smart pointer

    Qt Code:
    1. QSharedPointer<QFile> MyClass:getFile()
    2. {
    3. // ....
    4.  
    5. QSharedPointer<QFile> file(new QFile(filename);
    6. file->open(...); // or other tasks with file
    7.  
    8. return file;
    9. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 6th May 2013, 08:06
  2. Replies: 1
    Last Post: 2nd January 2013, 09:48
  3. Replies: 4
    Last Post: 9th May 2011, 09:52
  4. QFile &QFile::operator= is private
    By Fallen_ in forum Newbie
    Replies: 1
    Last Post: 15th March 2011, 15:08
  5. Slot with a return value?
    By lalesculiviu in forum Qt Programming
    Replies: 9
    Last Post: 21st December 2009, 06:27

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.