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. How to update parents QTableView
Forum Updated to NodeBB v4.3 + New Features

How to update parents QTableView

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 463 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.
  • P Offline
    P Offline
    Panoss
    wrote on last edited by
    #1

    I have a form QMainWindow, this is the parent.
    It opens the child which has a QTableView ('positionsTable').
    After the positionsTable is updated I want parent's data (displayed in a QTableView also) to be updated,
    So I did it like this (code is in the child, parentmodel is passed in the consrtructor, where connection also happens with updateParent):

    positionsForm::positionsForm(QSqlRelationalTableModel *parentmodel, QWidget *parent) :
        QDialog(parent),
        ui(new Ui::positionsForm)
    
        connect(ui->positionsTable->model(),
                SIGNAL(dataChanged(QModelIndex,QModelIndex)), this,
                SLOT(updateParent(parentmodel)));
    

    And the updateParent code:

    void positionsForm::updateParent(QSqlRelationalTableModel *parentmodel){    
        parentmodel->select();   
    }
    

    The updateParent is called, but the parent table view is not updated.
    How can I do it?

    Christian EhrlicherC 1 Reply Last reply
    0
    • P Panoss

      I have a form QMainWindow, this is the parent.
      It opens the child which has a QTableView ('positionsTable').
      After the positionsTable is updated I want parent's data (displayed in a QTableView also) to be updated,
      So I did it like this (code is in the child, parentmodel is passed in the consrtructor, where connection also happens with updateParent):

      positionsForm::positionsForm(QSqlRelationalTableModel *parentmodel, QWidget *parent) :
          QDialog(parent),
          ui(new Ui::positionsForm)
      
          connect(ui->positionsTable->model(),
                  SIGNAL(dataChanged(QModelIndex,QModelIndex)), this,
                  SLOT(updateParent(parentmodel)));
      

      And the updateParent code:

      void positionsForm::updateParent(QSqlRelationalTableModel *parentmodel){    
          parentmodel->select();   
      }
      

      The updateParent is called, but the parent table view is not updated.
      How can I do it?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @Panoss said in How to update parents QTableView:

      SLOT(updateParent(parentmodel)));

      How should this work?

      QObject::connect() returns false, fix your slot. You should use the new signal/slot syntax for this.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • P Offline
        P Offline
        Panoss
        wrote on last edited by
        #3

        It says:

        New: connecting to simple function
        
        The new syntax can even connect to functions, not just QObjects:
        
        connect(
            sender, &Sender::valueChanged,
            someFunction
        );
        
        

        I don't know how to fix the slot, I don't understand, I have connected to some function.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then use the old signal/slot syntax, save parentmodel as member and use it in the connected slot.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Panoss
            wrote on last edited by Panoss
            #5

            I did it this way:

            connect(ui->positionsTable->model(), &QSqlRelationalTableModel::dataChanged,
                          this, positionsForm::updateParent(parentmodel));
            

            I get this error:

            positionsform.cpp:50:5: error: no matching member function for call to 'connect'
            qobject.h:197:36: note: candidate function not viable: no known conversion from 'void (QAbstractItemModel::*)(const QModelIndex &, const QModelIndex &, const QList<int> &)' to 'const char *' for 2nd argument
            qobject.h:200:36: note: candidate function not viable: no known conversion from 'void (QAbstractItemModel::*)(const QModelIndex &, const QModelIndex &, const QList<int> &)' to 'const QMetaMethod' for 2nd argument
            qobject.h:443:41: note: candidate function not viable: no known conversion from 'void (QAbstractItemModel::*)(const QModelIndex &, const QModelIndex &, const QList<int> &)' to 'const char *' for 2nd argument
            qobject.h:217:43: note: candidate template ignored: substitution failure [with Func1 = void (QAbstractItemModel::*)(const QModelIndex &, const QModelIndex &, const QList<int> &), Func2 = void]: no type named 'Object' in 'QtPrivate::FunctionPointer<void>'
            qobject.h:258:13: note: candidate template ignored: requirement 'int(QtPrivate::FunctionPointer<void>::ArgumentCount) >= 0 && !QtPrivate::FunctionPointer<void>::IsPointerToMemberFunction' was not satisfied [with Func1 = void (QAbstractItemModel::*)(const QModelIndex &, const QModelIndex &, const QList<int> &), Func2 = void]
            qobject.h:297:13: note: candidate template ignored: substitution failure [with Func1 = void (QAbstractItemModel::*)(const QModelIndex &, const QModelIndex &, const QList<int> &), Func2 = void]: argument may not have 'void' type
            qobject.h:249:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
            qobject.h:289:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
            
            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Panoss said in How to update parents QTableView:

              positionsForm::updateParent(parentmodel))

              Again: you can't pass a parameter in your slot this way - a slot can only take the parameters coming from a signal.

              Then use the old signal/slot syntax, save parentmodel as member and use it in the connected slot.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2
              • P Offline
                P Offline
                Panoss
                wrote on last edited by Panoss
                #7

                Ok it works!
                In the constructor:

                positionsForm::positionsForm(QSqlRelationalTableModel *parentmodel, QWidget *parent) :
                    QDialog(parent),
                    ui(new Ui::positionsForm)
                
                    this->parentmodel = parentmodel;
                
                    connect(ui->positionsTable->model(),
                            SIGNAL(dataChanged(QModelIndex,QModelIndex)), this,
                            SLOT(updateParent()));
                

                And the function:

                void positionsForm::updateParent(){
                    qDebug() << "updateParent called!!";
                    this->parentmodel->select();
                }
                
                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