How to update parents QTableView
-
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? -
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?@Panoss said in How to update parents QTableView:
SLOT(updateParent(parentmodel)));
QObject::connect() returns false, fix your slot. You should use the new signal/slot syntax for this.
-
-
Then use the old signal/slot syntax, save parentmodel as member and use it in the connected slot.
-
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
-
@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.
-
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(); }