[SOLVED] QTableWidget::clear()/removeCellWidger() vs. QList::clear()/removeAt()



  • Hello,

    I've got a question about reseting my QTableWidget.
    I'm creating a table with about 500 cells, each containing a QWidget (QCheckBox). These QCheckBoxes are previously created in a QList.
    When I update my window, I need to redraw the whole table. That means, I have to remove every QCheckBox from table and then, I also have to delete them to avoid buffer overflows.
    Correct me if I'm wrong, but the command removeLast() in QLists only removes that item from the list, but it doesn't delete them. Also, QList::clear() only removes all items from the list, but they are still "alive" on memory.
    Is that the same on QTableWidget::clear() or QTableWidget::reset() or QTableWidget::removeCellWidget() ? I can't find anything in documentation, and my google search results where not very clear...

    EDIT:
    Found the solution after searching a while. QTableWidget::clear() and also QTableWidget::clearContents() also deletes the contents, so there's no need to care about memory deallocation...
    What I still dont't know is whether QTableWidget::removeCellWidget() also does and, what the difference between clear() and reset() is...


  • Moderators

    A quick peek at the code reveals that removeCellWidget(x,y) just calls setCellWidget(x,y,0) and the docs of setCellWidget() say that it deletes the previous object.

    As for the clear/reset the docs are quite clear. reset() resets the view i.e. clears selection, closes edit boxes and resets scroll. It does not remove any items. clear() removes all items in the table.



  • [quote]A quick peek at the code[/quote]Nice that you mentioned that. I'm searching for Qt's source code for 1 hour now, without success. In other forums they posted the source code of QTableWidget::clear() and everything was clear for me. It would be really helpful to get an insight into Qt's code to answer many questions without posting them here...
    Do you have a link that to a kind of online source or do I have to download that?
    PS: the only link I found while searching is: https://qt.gitorious.org/qt
    .. but I didn't find anything on that website, maybe I'm too foolish for that x(


  • Moderators

    That code I mentioned is actually inlined in the header so you don't need the full source code.

    If you use the online installer there's an option to download source. Also in the link you posted you can click on the qt/qtbase repository (in the right column of the page) and it will take you to the code browser. The code in question is "here":https://qt.gitorious.org/qt/qtbase/source/a3cb057c3d5c9ed2c12fb7542065c3d667be38b7:src/widgets/itemviews/qtablewidget.h#L350



  • Ah, not that easy to find, thank's. But it's still hard to find a specific class in that labyrinth! When I download the source code via online installer, is there a better overview with better navigation like the documentation/QtAssistant or is it as confusing as the online source? I'll download it if I don't have to install many other stuff, too.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.