Results 1 to 6 of 6

Thread: QtabkeView, QStandardItemModel and QSortFilterProxyModel problem.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2019
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default QtabkeView, QStandardItemModel and QSortFilterProxyModel problem.

    Hello all,

    I want to do a QTableView with a custom calculate cell. In the first column I have the name of the device. In the second column I have millisecond field and in the third column I have the rest of the previous millisecond field row and the actual row and write in the second column. Also a have a filter to select the device.

    I have a QStandardItemModel for update the data, and a QSortFilterProxyModel for the filter.

    My code is:

    Qt Code:
    1. this->model = new QStandardItemModel();
    2. this->model->setColumnCount(3);
    3. this->model->setHeaderData(0, Qt::Horizontal, QObject::tr("Time"));
    4. this->model->setHeaderData(1, Qt::Horizontal, QObject::tr("Milliseconds"));
    5. this->model->setHeaderData(2, Qt::Horizontal, QObject::tr("Spend Time"));
    6.  
    7. this->dataTable = new QTableView();
    8. this->dataTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    9. this->dataTable->setSortingEnabled(false);
    10. this->dataTable->sortByColumn(1, Qt::AscendingOrder);
    11.  
    12.  
    13. QRegExp filterString = QRegExp("ARM1", Qt::CaseInsensitive);
    14. this->filterModel->setFilterRegExp(filterString);
    15. this->filterModel->setFilterKeyColumn(-1);
    16. this->dataTable->setModel(filterModel);
    To copy to clipboard, switch view to plain text mode 


    When I don't use the filter, I can write in the data model without problem like this:

    Qt Code:
    1. QStandardItemModel *auxModel = (QStandardItemModel*)this->dataTable->model();
    2. int rows = auxModel->rowCount();
    3. for (int i = 0; i < rows; i++) {
    4. if (i == 0) {
    5. auxModel->setItem(i, 2, new QStandardItem("0"));
    6. } else {
    7. unsigned long aux1 = auxModel->data(auxModel->index(i,1)).toString().toLong();
    8. unsigned long aux2 = auxModel->data(auxModel->index(i-1,1)).toString().toLong();
    9. QString s = QString::number(aux1 - aux2);
    10. auxModel->setItem(i, 2, new QStandardItem(s));
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    But when I use the filter I get a segmentation fault and I cannot found a solution.

    Can anyone hellp me?
    Thanks
    Last edited by d_stranz; 4th January 2024 at 21:03. Reason: missing [code] tags

Similar Threads

  1. Problem in updating QstandardItemmodel.
    By urmila in forum Qt Programming
    Replies: 7
    Last Post: 1st September 2014, 17:12
  2. Replies: 4
    Last Post: 19th April 2013, 13:40
  3. Replies: 2
    Last Post: 11th February 2012, 00:28
  4. Replies: 2
    Last Post: 7th December 2009, 14:15
  5. QStandardItemModel save/load Problem
    By sun in forum Newbie
    Replies: 9
    Last Post: 1st October 2008, 18:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.