Emit dataChanged not updating my data



  • I am using an AbstractItemModel and I can't seem to get my table to update the changed data. I have the table view within a docked widget, If i lose focus to the window or regain focus or change the widget window size the data will update but I can't seem to get the data to just update using the dataChanged event. Does anyone know what I might be doing wrong?

    @void QuoteTableModel::HandleNewQuote(const std::string& in_symbol, double in_bid, double in_ask)
    {
    if (this->m_symbolToQuotes.find(in_symbol) == this->m_symbolToQuotes.end())
    {
    QuoteItem* quoteItem = new QuoteItem(in_symbol, in_bid, in_ask, this->m_items.size());
    beginInsertRows(QModelIndex(), this->m_symbolToQuotes.size(), this->m_symbolToQuotes.size());
    this->m_symbolToQuotes[in_symbol] = quoteItem;
    this->m_items.push_back(quoteItem);
    endInsertRows();
    }
    else
    {
    this->m_symbolToQuotes[in_symbol]->HandleNewQuote(in_bid, in_ask);
    }

    QModelIndex firstIndex = createIndex(this->m_symbolToQuotes[in_symbol]->Row(), 1, this->m_symbolToQuotes[in_symbol]);
    this->setData(firstIndex, QVariant(CU::to_string(this->m_symbolToQuotes[in_symbol]->Bid()).c_str()), Qt::DisplayRole);

    QModelIndex secondIndex = createIndex(this->m_symbolToQuotes[in_symbol]->Row(), 2, this->m_symbolToQuotes[in_symbol]);
    this->setData(secondIndex, QVariant(CU::to_string(this->m_symbolToQuotes[in_symbol]->Ask()).c_str()), Qt::DisplayRole);

    emit dataChanged(firstIndex, secondIndex);
    }

    @



  • have you connected the dataCHanged signal anywhere?



  • No I did not connect a signal.. I was assuming the QTableView did that when you set your data model on it. If that is not the case even if I set up a signal/slot, how do I get my QTableView to update only the changed cells?



  • I believe you must reimplement QTableView to create your own slot in which you update your data... Haven't worked with this so I'm not sure... I'm just assuming that this is the case...

    L.E. After reading for a bit... I think you can create your slot and in it go through all of the cells of your table and use QAbstractItemView::update(QModelIndex) on each one...


Log in to reply
 

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