QTableWidget's. setText() does not set any text to cells

  • Hello,
    I use QTableWidgetItem to insert some text to cells in a table but all that happens is that it crashes with a segmentation error. Code below:

    QTableWidgetItem *item = new QTableWidgetItem;
    item = ui->tablewidget->item(2, 2);

    so when the last line executes it crashes with a segmentation fault that takes me to some at header file ?.

    any ideas?

    Frik Brits

  • You are not setting the item in the cell first. item is null.

    The fastest solution is to replace your 3 lines with:

    auto model = ui->tablewidget->model();

  • Try,

    QTableWidgetItem *item = new QTableWidgetItem;
    ui->tablewidget->setItem(2, 2, item);

Log in to reply