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. [SOLVED] How to get QModelIndex needed for QAbstractTableModel::setData?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to get QModelIndex needed for QAbstractTableModel::setData?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.2k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    phamtv
    wrote on last edited by
    #1

    I have a QMap with values << ¨Register 1¨ << ¨Register 2¨ initialized as follow:

    @
    QMap<QString, int> registermap;

    for (int i = 0; i < 10; i++)
    registermap.insert(QString("Register %1").arg(i), i);
    @

    In my application, I have an event that signals me to update a particular row (keyed by ¨Register n¨) in the tableview. I am trying to get the QModelIndex needed as an input to QAbstractTableModel::setData

    @
    QModelIndex currentIndex = registerModel->index(registermap[e->Desc], 0, QModelIndex());
    registerModel->setData(currentIndex, e->Value, Qt::EditRole);
    @

    However, the above implementation always return the value of ¨1¨ even if the e->Desc is ¨Register 9¨... Can someone shine some light on me?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Hard to guess what's going on, we do not know what's your registerModel is based on.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        phamtv
        wrote on last edited by
        #3

        disregard my post... I was handling the signal in the wrong object. What I needed to do was handle the signal in my inherited QAbstractTableModel object and do the following....

        @
        public slots:
        void RegisterValueChanged(QObject* obj, RegData* e)
        {
        registerMap[e->Desc] = e->Value;
        reset();
        }
        @

        [EDIT: code formatting, Volker]

        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