Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Emit dataChanged not updating my data

    General and Desktop
    2
    4
    2433
    Loading More Posts
    • 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
      glavian last edited by

      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 Reply Quote 0
      • B
        b1gsnak3 last edited by

        have you connected the dataCHanged signal anywhere?

        1 Reply Last reply Reply Quote 0
        • G
          glavian last edited by

          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 Reply Quote 0
          • B
            b1gsnak3 last edited by

            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 Reply Quote 0
            • First post
              Last post