Results 1 to 14 of 14

Thread: How to create in memory QFile

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to create in memory QFile

    Who said that QFile should always be on stack? Its depend on you whether you want to allocate in stack or heap.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to create in memory QFile

    QBuffer is the in-memory QIODevice you might want.

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to create in memory QFile

    Quote Originally Posted by sonulohani View Post
    Who said that QFile should always be on stack? Its depend on you whether you want to allocate in stack or heap.
    nobody said that.

    If, however, you are going to write an example that looks like a java programmer wrote it, perhaps you should expect some comeback.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  4. #4
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to create in memory QFile

    Then do coding in java, why r u here? Its depend on your program methodology. And if someone is here than atleast he should know the basic concept of c++(memory allocation). You shouldnt have to think about what they do with this code or if he /she will understand this code or not. Okay, point out the line that is causing memory leak in my code.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to create in memory QFile

    Quote Originally Posted by sonulohani View Post
    Okay, point out the line that is causing memory leak in my code.
    Qt Code:
    1. ...
    2. if (!file->open(QIODevice::WriteOnly | QIODevice::Text))
    3. return; //memoy leak if a file can't be opened
    4. ...
    To copy to clipboard, switch view to plain text mode 
    The simplest way to fix this without using delete it's just provide a parent in QFile's ctor.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to create in memory QFile

    No, simplest way is to say `QFile file;`, not `QFile* file = new ...`
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to create in memory QFile

    Quote Originally Posted by amleto View Post
    No, simplest way is to say `QFile file;`, not `QFile* file = new ...`
    Yup, and change all "->" to "." if you have tons of code.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to create in memory QFile

    Quote Originally Posted by sonulohani View Post
    Then do coding in java, why r u here? Its depend on your program methodology. And if someone is here than atleast he should know the basic concept of c++(memory allocation). You shouldnt have to think about what they do with this code or if he /she will understand this code or not. Okay, point out the line that is causing memory leak in my code.
    You are the one writing like java: Allocating on the heap when only a local variable is needed - check. Using new without delete - check.

    Your leak has been pointed out already, although why you couldn't see it for yourself is concerning.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. QFile &QFile::operator= is private
    By Fallen_ in forum Newbie
    Replies: 1
    Last Post: 15th March 2011, 15:08
  2. Replies: 3
    Last Post: 26th March 2010, 07:26
  3. Replies: 5
    Last Post: 27th May 2009, 12:49
  4. create Memory-mapped file
    By weixj2003ld in forum Newbie
    Replies: 2
    Last Post: 17th April 2009, 10:47
  5. how to create html file in memory
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2007, 09: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.