Results 1 to 6 of 6

Thread: QTextEdit not deleted when implemented as list

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default QTextEdit not deleted when implemented as list

    Dear All
    I have list of QTextEdit, I am creating the edit box and then trying to delete but its not deleting. Can u anyone tell me what I am doing wrong.

    Qt Code:
    1. QList<QTextEdit *> list;
    2. int w = 100;
    3. int h= 25;
    4. int incre=0;
    5. for(i=0; i<2; i++)
    6. {
    7. list.append(new QTextEdit(this));
    8. list.at(i)->setGeometry(0,0+incre,w,h);
    9. list.at(i)->show();
    10. incre = incre+h+10;
    11. }
    12.  
    13. int cnt = list.count();
    14. for(int i=0; i<cnt; i++)
    15. delete list.at(i);
    16. list.clear();
    To copy to clipboard, switch view to plain text mode 

    But even after deleting the edit boxes I can still see them, means they’re not being deleted. Whats wrong , any help would be appreciated.
    Last edited by wysota; 23rd June 2011 at 17:14. Reason: missing [code] tags

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTextEdit not deleted when implemented as list

    Use takeAt() instead of at()
    Qt Code:
    1. //int cnt = list.count();
    2. //for(int i = 0; i < cnt; i++)
    3. // delete list.takeAt(i);
    4. //list.clear();
    5.  
    6. while(list.count())
    7. delete list.takeAt(0);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit not deleted when implemented as list

    at() should be ok too. The problem is elsewhere. What is the value of cnt in line #13?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: QTextEdit not deleted when implemented as list

    Agree, it is valid and working code (or it would be if int would be added before"i" in the first loop).

  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTextEdit not deleted when implemented as list

    using at() should also work

    probably your delete is never being called, set a breakpoint and see it ever gets executed

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit not deleted when implemented as list

    From what I understand these are two separate pieces of code. It would be stupid to create something and delete it three lines later without using it. So there is a good chance the list goes out of scope (or is a member variable) and the OP creates a new one with the same name expecting it to have the same content. That's why I asked for the size of the list prior to deleting items from it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. MultiScale support can be implemented?
    By umituzun84 in forum Qwt
    Replies: 1
    Last Post: 7th February 2011, 10:23
  2. SIP stack implemented with Qt
    By iaguirre in forum Qt-based Software
    Replies: 0
    Last Post: 26th January 2011, 16:19
  3. How to add nest list in QTextEdit?
    By FinderCheng in forum Qt Programming
    Replies: 0
    Last Post: 11th December 2010, 06:23
  4. QDirectPainter::unlock () implemented?
    By TTGator in forum Qt Programming
    Replies: 0
    Last Post: 20th November 2008, 20:40
  5. An Implemented QHttp Object
    By bhs-ittech in forum Qt Programming
    Replies: 11
    Last Post: 18th August 2006, 14:47

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.