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. Is QStandardItemModel and QStandardItem destuction needed?

Is QStandardItemModel and QStandardItem destuction needed?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 524 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.
  • S Offline
    S Offline
    sharethl
    wrote on last edited by
    #1

    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);
    }
    }@

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

      Hi,

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

      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

      • Login

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