Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Removing last QWidgetTable row causes crash
QtWS25 Last Chance

Removing last QWidgetTable row causes crash

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael.R.LegakoL-3com.com
    wrote on last edited by
    #1

    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");
    Table.removeRow(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]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What does a run through the debugger gives you ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        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(
                                                                     (row+1)*(column+1)));
                tableWidget->setItem(row, column, newItem);
            }
        }
        tableWidget->show();
        // delete 0th row.
        tableWidget->removeRow(0);@
        

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved