Is QStandardItemModel and QStandardItem destuction needed?



  • If I use the following code,

    1. Will QStandardItemModel be deleted automatically when it is replaced by new QStandardItemModel?

    2. If use 3rd code, new on QStandardItem only, how QStandardItem will be deleted?

    Thanks

    @QStandardItemModel *ElementList::getTableModel()
    {
    QStandardItemModel model(this->count(),2); //x Rows and 5 Columns
    model.setHorizontalHeaderItem(0, new QStandardItem(QString("El")));
    model.setHorizontalHeaderItem(1, new QStandardItem(QString("%")));
    for(int i=0; i < this->count();i++){
    ResultElement re=this->at(i);
    model.setItem(i,0,new QStandardItem(re.getName()));
    model.setItem(i,1,new QStandardItem(QString::number(re.percentage())));
    }
    return model;
    }
    @
    @QStandardItemModel *tableModel = list->getTableModel();
    qDebug() << tableModel->parent();
    ui->tableView->setModel(tableModel);
    qDebug() << tableModel->parent();@

    @QStandardItemModel model(4, 4);
    for (int row = 0; row < 4; ++row) {
    for (int column = 0; column < 4; ++column) {
    QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
    model.setItem(row, column, item);
    }
    }@


  • Lifetime Qt Champion

    Hi,

    It's all explained in the "setItem":http://doc.qt.io/qt-5/qstandarditemmodel.html#setItem documentation


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.