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

QSortFilterProxyModel* as signal argument is undefined in QML



  • Hi,
    I have the following class to be used as model for a QML TableView

    class ProcessProxyModel : public QSortFilterProxyModel {
    Q_OBJECT
    ...
    signals:
    void procModelReady(const ProcessProxyModel* procmodel);
    
    private:
    ProcessProxyModel* m_procModel;
    }
    

    The class is registered as:

        qmlRegisterUncreatableType<ProcessProxyModel>("com.dirac", 1, 0, "ProcessProxyModel", "Type is not allowed to be instantiated");
    
    

    When the model is ready, I emit a signal as follows:

    emit procModelReady(m_procModel);
    

    In QML however, the object passed is not recognized and reported as undefined.

    On the other hand, if I explicitly query for the model via:

    Q_INVOKABLE ProcessProxyModel* getProcProxy() const {
       return m_procModel;
    }
    

    it works.

    To summarize, in QML:

    Connections {
            target: sysmon
    
            function onProcModelReady(model)    {
                console.debug(model)                                 // <--- prints undefined
                console.debug(sysmon.getProcProxy()) //<-- Works correctly
            }
    

    Why is the signal argument's type not recognized?


  • Lifetime Qt Champion

    Hi,

    Don't you have any runtime message about an unknown type being used in your signal ?



  • @SGaist
    Thanks, but no such message appears.



  • The problem was due to the const specifier.

    signals:
    void procModelReady(const ProcessProxyModel* procmodel);
    

    Changing it to:

    signals:
    void procModelReady(ProcessProxyModel* procmodel);
    

    works.


Log in to reply