So...

  1. There is a table QTableView tableViewMain.

  2. there is a class TableAmdinWidget (let's call for an example like this =)), which manages various tables in the application, including this one.

  3. in the declaration of this class, the AmdinWidgetSqlModel class inherited from QSqlQueryModel is connected. In which the methods are overridden
    bool setData(const QModelIndex &index,const QVariant &value, int role);

  4. And in general, the essence of the problem, when editing a tableViewMain, the data of other tables should be automatically updated. I cause in the designer TableAmdinWidget
    QObject::connect(model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(initViewRez(QTableView*)));

Does not work

QObject::connect' : none of the 3 overloads could convert all the argument types

Explanations.

  • In TableAmdinWidget there is a method that receives a pointer to a table.
  • There is also an initViewRez slot (QTableView *) in which we put this pointer - it takes data from the database and displays it on the table.
  • model is a pointer to the AmdinWidgetSqlModel class.

In general, somehow everything ... how to solve this problem. And as it is generally possible, if possible, so that when updating the model model , others would be updated automatically.

    2 answers 2

    • SIGNAL and SLOT must have the same arguments ( SLOT may not have them at all, but cannot have an argument other than the SIGNAL'a argument). See here for more details .

    • Implement a controller for your models that will catch dataChanged from one model and project / change data in other models.

    • In the application design plans, you can not move from the ideology of Model / View used in Qt , but simply create an auxiliary class of the AggregatedModel type, which will be engaged in projecting changes.

    • I thought about it. made private slots: void initUpdate (); void TableAmdinWidget :: initUpdate () {} the same result .. - Kirill_m
    • It is possible in more detail. The point is that I have 1 model inherited from QSqlQueryModel. all other pure QSqlQueryModel which are connected to QTableView (and they are not editable.) what is most interesting is that in the old version of the program where QSqlTableModel - editable was associated with QTableView. through the same signal and similar slot. everything worked .. - Kirill_m

    Everything is easier than written in the comments.

    1. TableAmdinWidget should inherit from QObject

    .h

    class TableAmdinWidget: public QObject {

     Q_OBJECT 

    public: TableAmdinWidget (QObject * parent = 0);

    .cpp

    TableAmdinWidget :: TableAmdinWidget (QObject * parent): QObject (parent) {model = new AmdinWidgetSqlModel; QObject :: connect (model, SIGNAL (dataChanged (QModelIndex, QModelIndex)), this, SLOT (initUpdate ())); }

    1. Also in AmdinWidgetSqlModel in overridden

    bool setData (const QModelIndex & index, const QVariant & value, int role);

    call the dataChanged signal explicitly (QModelIndex, QModelIndex).

    emit dataChanged (index, index)

    PS I apologize to the moderators that the code in the quotation issued. Well, it does not work in the code)