Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to recent signal from proxyModel to model?



  • Hello, i have next problem "QObject::connect(QItemSelectionModel, mainForm): invalid null parameter"

    I just tried to connect signal, want to make some manipulations with form on selection, my code:

    connect(tbSC->selectionModel(), &QItemSelectionModel::selectionChanged, this, &mainForm::enableButtons);
    
    void mainForm::enableButtons(const QItemSelection &selected, const QItemSelection &)
    {
        foreach(QModelIndex index, selected.indexes())
        {
            if(mdlSC->Columns[index.row()][0].toString()=="")
                continue;
            else
            {
                ui->btnMS->setEnabled(true);
                break;
            }
        }
    }
    

    slot is not called

    I have next structure:

        tbSC = new tableSM(this);
        proxySM = new ProxyModelSM(tbSC);
        mdlSC = new modelSM(proxySM);
    
    ...
    
       proxySM->setSourceModel(mdlSC);
       tbSC->setModel(proxySM);
    

    class tableSM : public QTableView
    class modelSM : public QAbstractTableModel
    class ProxyModelSM : public QSortFilterProxyModel

    I think i must make smth like mapToSource, but idk how it make with signals, please help



  • Your connect(tbSC->selectionModel() should be after tbSC->setModel(proxySM);


  • Qt Champions 2019

    @zloi_templar said in How to recent signal from proxyModel to model?:

    connect(tbSC->selectionModel(), &QItemSelectionModel::selectionChanged, this, &mainForm::enableButtons);

    Sounds like tbSC->selectionModel() returns a null pointer



  • Your connect(tbSC->selectionModel() should be after tbSC->setModel(proxySM);



  • @VRonin yea, ty, already fix it