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. Emit dataChanged not updating my data

Emit dataChanged not updating my data

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.6k 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.
  • G Offline
    G Offline
    glavian
    wrote on last edited by
    #1

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

    @

    1 Reply Last reply
    0
    • B Offline
      B Offline
      b1gsnak3
      wrote on last edited by
      #2

      have you connected the dataCHanged signal anywhere?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        glavian
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          b1gsnak3
          wrote on last edited by
          #4

          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...

          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