Results 1 to 15 of 15

Thread: Memory error for Qlabel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Memory error for Qlabel

    Hello All,


    I m using Qt 4.4.0

    I have below code

    Qt Code:
    1. //in Header file
    2. class C1
    3. {
    4. private:
    5. QLabel *img_label_1;
    6. QLabel *img_label_2;
    7.  
    8. QLabel *img_label_3;
    9. QLabel *img_label_4;
    10. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //in CPP file
    2.  
    3.  
    4. C1::C1(QWidget * parent):QDialog(parent)
    5. {
    6. ui.setupUi(this);
    7. setWindowFlags( Qt::FramelessWindowHint);
    8.  
    9. img_label_4 = NULL;
    10. img_label_1 = NULL;
    11. img_label_2 = NULL;
    12. img_label_3 = NULL;
    13.  
    14.  
    15. if((img_label_1 = new QLabel(ui.frame)) != NULL)
    16. QMessageBox::information(this,"TRUE","");
    17. img_label_1->setPixmap(QPixmap(":/images/pink-1.png"));
    18. img_label_1->setGeometry(6,4,16,16);
    19. img_label_1->setScaledContents(TRUE);
    20. img_label_1->show();
    21.  
    22. img_label_1->setStyleSheet( "border-style:solid;\n"
    23. "border-color:rgb(86,86,86);\n"
    24. "border-width:1px;\n"
    25. );
    26. //In same way I m alloctiing 2 more labels
    27. //And now the turn of 4th label
    28.  
    29. if((img_label_4 = new QLabel(this)) != NULL)
    30. QMessageBox::information(this,"TRUE","");
    31.  
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 
    Now the problem is
    when I include
    Qt Code:
    1. if((img_label_4 = new QLabel(this)) != NULL)
    To copy to clipboard, switch view to plain text mode 
    statement
    after closing the EXE it gives Memory error

    If I comment the above line it doesnt giv any error..

    The drive where program resides has 1.2 G free memory.

    As soon as it allocates memory for 4th label ,it gives memory error after closing EXE.

    Please help
    Last edited by wysota; 4th April 2009 at 10:47. Reason: Changed [quote] to [code]

  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: Memory error for Qlabel

    why you don't create these labels in ui and then in ctor set all needed settings?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory error for Qlabel

    same error is occuring when tried to add label from the designer.

  4. #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: Memory error for Qlabel

    could you attach you project?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory error for Qlabel

    it's size is big & can't attach it here.

  6. #6
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory error for Qlabel

    dont attacht the whole project..just attach C1.cpp, C1.h and related ui file

  7. #7
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory error for Qlabel

    I have submiited all concerned code...


    One thing is for sure that it gives error as soon as it allocates memory for anything after the 3rd label.


    I hav tried creating
    Qt Code:
    To copy to clipboard, switch view to plain text mode 

    and it gave error after closing..

    If I debug the application for error it shows some disassembly code which is beyond understanding...


    It allocates the memory for 4th label but while freeing that particular memory it is facing some problem .

    Any help would be appreciated...
    Last edited by wysota; 4th April 2009 at 10:48. Reason: Changed [quote] to [code]

  8. #8
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Memory error for Qlabel

    And what is that this you are passing to the constructor?

    P.S. And use CODE tags for code, and QUOTE tags for quotes.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  9. #9
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory error for Qlabel

    i still believe there is smth you havent shared with us that is causing the issue, cuz the above code looks pretty benign..could u attach the whole .h, .cpp and .ui files?

  10. #10
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory error for Qlabel

    Pls find attached files.
    Attached Files Attached Files

  11. #11
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory error for Qlabel

    when u r deleting the objects in delete_objects(), set them back to NULL too..read about dangling pointers http://en.wikipedia.org/wiki/Wild_pointer

  12. The following user says thank you to talk2amulya for this useful post:

    Qt Coder (4th April 2009)

Similar Threads

  1. Memory debugging in windows
    By txandi in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2009, 13:45
  2. memory leak question
    By cool_qt in forum General Programming
    Replies: 3
    Last Post: 20th January 2009, 07:49
  3. Memory management
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 20:48
  4. Memory leak weirdness
    By Darhuuk in forum General Programming
    Replies: 10
    Last Post: 10th January 2008, 18:51
  5. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 19:42

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.