QTableWidget has clear and clearContents, but none of them does the same as this code. The function itself is generated by QT Creator.