Important: Please read the Qt Code of Conduct -

Removing last QWidgetTable row causes crash

  • QT VERSION: 4.8
    OS: RHEL (uname -r = 2.6.18-371.8.1.el5)

    When my app starts it loads a QTableWidget with 3 rows of 7 columns worth of strings. I can see that the table is working OK, because I can change the table entries if I want to with no problem. Each entry in the table is provided with its own QTableWidgetItem allocated with new off the heap, then I use setText() to initially provide a string value.

    Everything is fine, until I hit a button to delete the last row. The Slot/Signal for the button works OK. I use a printf() to tell me I'm in the SLOT callback. The Slot callback looks like so:

    void MainWindow::OnDeleteRow()
    int irows = Table.rowCount();
    if (irows-1>1)
    printf("Ready to remove row %d",irows-1");
    printf("Survived row deletion.\n");


    The 1st printf() is printed on execution, the 2nd one is never reached because the program crashes.
    So far I've only tried to delete the 3rd of three rows (row number 2).

    The only peculiar thing I've noticed thus far is that the documentation for QWidgetTable shows removeRow() as a SLOT function.

    Does anybody see anything obviously wrong in the callback?

    [edit: added missing coding tags @ SGaist]

  • Lifetime Qt Champion


    What does a run through the debugger gives you ?

  • Qt Champions 2017

    Try with this and based on this fix your issue.

    @QTableWidget *tableWidget = new QTableWidget(12, 3);

    for(int row=0;row<12;row++){
        for(int column=0;column<12;column++){
            QTableWidgetItem *newItem = new QTableWidgetItem(QObject::tr("%1").arg(
            tableWidget->setItem(row, column, newItem);
    // delete 0th row.

Log in to reply