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. QListView in combination with a QSqlRelationTableModel - setData in relationModel - view is not updated

QListView in combination with a QSqlRelationTableModel - setData in relationModel - view is not updated

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 435 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello Forum,

    I have a comprehension question about the QListView in combination with a QSqlRelationTableModel.

    The following example works as well:

    //mGermanFungusNameDataModel = QSqlRelationTableModel
                        auto a = mGermanFungusNameDataModel->relationModel(2)->setData(mGermanFungusNameDataModel->relationModel(2)->index(relationRow, Column::Name), newGermanName, Qt::EditRole);
                        auto b = mGermanFungusNameDataModel->setData(mGermanFungusNameDataModel->index(sourceRow, Column::RowId), id, Qt::EditRole);
                        auto c = mGermanFungusNameDataModel->setData(mGermanFungusNameDataModel->index(sourceRow, Column::Name), fungusId, Qt::EditRole);
                        auto d = mGermanFungusNameDataModel->setData(mGermanFungusNameDataModel->index(sourceRow, Column::GermanName), nameId, Qt::EditRole);
                        
                        qDebug() << "a:" << a << ", b:" << b << ", c:" << c << ", d:" << d;
                        
                        mGermanFungusNameDataModel->relationModel(2)->submitAll();
                        mGermanFungusNameDataModel->submitAll();
    

    a-d return true. The data is also written to the database. But now if I omit submitAll() the QListView is not populated with the new data. I want to call the submitAll() later via a save button so that the data is written into the database. But the data in the QListView should already be updated so kind of "cache".

    Do I need my own delegate for this or is there another way?

    Thanks for tips and help

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How is your view setup ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      ? 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        How is your view setup ?

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @SGaist

        Very simple:

        mGermanNameEditor = new ToggleListView(this);
        
        mGermanNameEditor->setModel(mGermanFungusNameDataModel);
        mGermanNameEditor->setModelColumn(Column::GermanName);
        

        And ToggleListView is subclassed from QListView and this class looks like this:

        togglelistview.h

        #ifndef TOGGLELISTVIEW_H
        #define TOGGLELISTVIEW_H
        
        #include <QListView>
        #include <QMouseEvent>
        #include <QDebug>
        
        class ToggleListView : public QListView
        {
            Q_OBJECT
        public:
            explicit ToggleListView(QWidget *parent = nullptr);
            ~ToggleListView();
        protected:
            void mousePressEvent(QMouseEvent *event) override;
        };
        
        #endif // TOGGLELISTVIEW_H
        
        

        togglelistview.cpp

        #include "togglelistview.h"
        
        ToggleListView::ToggleListView(QWidget *parent): QListView(parent) {}
        
        ToggleListView::~ToggleListView() {}
        
        void ToggleListView::mousePressEvent(QMouseEvent *event)
        {
            Qt::KeyboardModifiers keys;
            keys.setFlag(Qt::ControlModifier);
            event->setModifiers(keys);
            QListView::mousePressEvent(event);
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Which submitAll does your code require ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          ? 1 Reply Last reply
          0
          • SGaistS SGaist

            Which submitAll does your code require ?

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @SGaist

            mGermanFungusNameDataModel->relationModel(2)->submitAll();
            mGermanFungusNameDataModel->submitAll();
            

            Both. If I comment out one of them, the entry in the QListView is not updated. Just tried it again.

            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