0

I have my QTableWidge here called ui->availableMeasurementsTableWidget and I want to set the row names and column names.

My goal is to use the variable columnName to change each row of the ui->availableMeasurementsTableWidget but every time I insert a new item inside ui->availableMeasurementsTableWidget it crash.

Why does this happen?

/* Find total rows */
    int totalRows = MeasurementTable::staticMetaObject.propertyCount() - MeasurementTable::staticMetaObject.propertyOffset();
    ui->availableMeasurementsTableWidget->setRowCount(totalRows);
    ui->availableMeasurementsTableWidget->setColumnCount(1);
    for(int i = 0; i < totalRows; i++){
        int typeID = MeasurementTable::staticMetaObject.property(i).typeId();
        QString columnName = MeasurementTable::staticMetaObject.property(i).name();
        QTableWidgetItem *qTableWidgetItem = new QTableWidgetItem();

        /* Set it to a checked state */
        qTableWidgetItem->setCheckState(Qt::CheckState::Unchecked);

        /* How can I change the row name for the availableMeasurementsTableWidget ? */
        
        /* Insert -> Here it crash */
        ui->availableMeasurementsTableWidget->setItem(i,0, qTableWidgetItem);
    }
euraad
  • 2,467
  • 5
  • 30
  • 51
  • you can use QTableWidgetItem::setText (https://doc.qt.io/qt-5/qtablewidgetitem.html#setText) method to change the text of the item or use the appropriate constructor and pass the text by the way maybe providing a table of local variables would help for the crash – Morteza Sherafati Feb 23 '22 at 05:33
  • Whenever something does crash there is a log, kindly post that; but if there is no log, probably some `.dll` file is missing or not compatible. – Top-Master Feb 23 '22 at 06:05
  • @Top-Master It seems that `ui->availableMeasurementsTableWidget->item(i, 0) == nullptr` – euraad Feb 23 '22 at 10:34
  • I found the issue now! You cannot use SLOTS for this table widget. – euraad Feb 23 '22 at 11:41

0 Answers0