Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

When to use QTableWidgetItem?



  • Is it a case of use it when you need to, or should you always create an instance for every cell of a QTableWidget? A related question: is the QTableWidgetItem object purely a conduit to pass values to a cell of a QTableWidget object (so that the QTableWidgetItem object can be immediately deleted)?


  • Lifetime Qt Champion

    Hi @Guerrian, welcome to the forums.

    Is it a case of use it when you need to, or should you always create an instance for every cell of a QTableWidget?

    Yes, the typical usage is to create a new QTableWidgetItem if you change the cell, see the example at http://doc.qt.io/qt-5/qtablewidgetitem.html#details

    A related question: is the QTableWidgetItem object purely a conduit to pass values to a cell
    of a QTableWidget object

    Yes, that is correct.

    (so that the QTableWidgetItem object can be immediately deleted)?

    No, you don't delete it! The QTableWidget takes ownership of your QTableWidgetItem: http://doc.qt.io/qt-5/qtablewidget.html#setItem so you are no longer responsible for that.

    Regards


Log in to reply