Results 1 to 7 of 7

Thread: QList: out of memory

  1. #1
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QList: out of memory

    Hi,
    I have a class called CMyClass. My application has list of CMyClass object. Module2 is used to create and delete the CMyClass object and append to the Qlist which is in Module1.
    The declaration of the QList as follows:
    QList<CMyClass *>* listObject = new QList<CMyClass *>();
    Initially if i am appending the CMyClass object listObject works fine. if I remove last item from the listObject and try to append one more CMyClass object, then following error occures:
    QList: out of memory

    This error only occures only if I delete one item from list and try to append one more.

    When i debug the program it was crashing in following code(red color):

    Q_OUTOFLINE_TEMPLATE void QList<T>::detach_helper()
    {
    Node *n = reinterpret_cast<Node *>(p.begin());
    QListData:ata *x = p.detach2();
    node_copy(reinterpret_cast<Node *>(p.begin()), reinterpret_cast<Node *>(p.end()), n);
    if (!x->ref.deref())
    free(x);
    }


    Following are the Call stack:
    QtCored4.dll!qt_message_output(QtMsgType msgType=QtFatalMsg, const char * buf=0x001298d4) Line 2032 C++
    QtCored4.dll!qFatal(const char * msg=0x6723a96c, ...) Line 2238 + 0xe bytes C++
    QtCored4.dll!QListData::detach2() Line 76 + 0xa bytes C++
    MainAppd.dll!QList<MyListholdingClass *>::detach_helper() Line 500 + 0x9 bytes C++
    MainAppd.dll!QList<MyListholdingClass *>::detach() Line 99 + 0x23 bytes C++
    MainAppd.dll!QList<MyListholdingClass *>::append(MyListholdingClass * const & t=0x0432fd50) Line 401 C++

    Can anyone please tell me how can i resolve this.
    Last edited by navi1084; 22nd March 2009 at 11:43.

  2. #2
    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: QList: out of memory

    can you show all code?
    btw, what the reason of creation a list in the heap?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    navi1084 (22nd March 2009)

  4. #3
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QList: out of memory

    Thank you for the reply
    I am using following code


    QList<CMyClass *>* listObject = new QList<CMyClass *>();

    To Add I am using following function:

    void addobject(CMyClass *myObject)
    {
    listObject->append(myObject);
    }


    void removeObject()
    {
    listObject->removeAt(i);
    }

    In the destructor of CMyClass i am emitting a signal to delete the object from the list which remove the objct successfully (variable 'i' is calculated inside removeObject). 'delete' operation of the CMyClass object will be done wherever i create it.

  5. #4
    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: QList: out of memory

    you did not answer on my question
    try to modify your code like this
    Qt Code:
    1. QList<CMyClass *> listObject;//make this variable as class-member.
    2.  
    3. void addobject(CMyClass *myObject)
    4. {
    5. listObject.append(myObject);
    6. }
    7.  
    8.  
    9. void removeObject()
    10. {
    11. listObject.removeAt(i); //btw, in this case pointer will not be free.
    12. //use QList::takeAt instead.
    13. //delete listObject.takeAt(i);
    14. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #5
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QList: out of memory

    Sorry I cant show my all the codes. But i can say CMyClass is a abstract class which contains large amount of data.

  7. #6
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QList: out of memory

    Can anyone please help me out

  8. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList: out of memory

    Why dont you try modifying your code as spirit suggested.
    Is there any special reason u are creating list on heap ? QList manages memory well, so why are u taking the headache ?

Similar Threads

  1. QList, copy problems
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 5th February 2010, 00:06
  2. Memory debugging in windows
    By txandi in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2009, 13:45
  3. Memory leak weirdness
    By Darhuuk in forum General Programming
    Replies: 10
    Last Post: 10th January 2008, 18:51
  4. QT4 debug mode output / QList: Out of memory
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2007, 09:53
  5. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43

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.