qmlRegisterType dont' recogized into qml file



  • Hello,
    Now i'm sudy use webengine (into ubuntu 32bit with QT 5.5)
    i have declare in main.cpp

     qmlRegisterType<engineIndexHtml>("PageIndexHtml", 1, 0, "engineIndexHtml");
    

    thi is a class qith file engineIndexHtml.h

    class engineIndexHtml : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(int answerToLife READ answerToLife NOTIFY answerToLifeChanged)
    public:
        explicit engineIndexHtml(QObject *parent = 0);
        int answerToLife() const;
        Q_INVOKABLE void changeAnswerToLife();
    signals:
        void answerToLifeChanged(int answer);
    private:
        int m_answerToLife;
    
    };
    

    and engineIndexHtml.cpp

    #include "engineindexhtml.h"
    
    engineIndexHtml::engineIndexHtml(QObject *parent)
        : QObject(parent),
          m_answerToLife(42)
    {
    }
    
    int engineIndexHtml::answerToLife() const
    {
        return m_answerToLife;
    }
    void engineIndexHtml::changeAnswerToLife()
    {
        m_answerToLife = (int) (m_answerToLife * 8.5f) % 43;
        emit answerToLifeChanged(m_answerToLife);
    }
    

    After i want use object into QML file

    . . . .
    import PageIndexHtml 2.0
    
    Window {
        engineIndexHtml {
            id: oldBeardedMan
            WebChannel.id: "wiseMan"
        }
    

    Why QmlApplicationEngine don't load component and wirte this error ?

    Cannot assign to non-existent property "engineIndexHtml"
    

    The meaning of the message is clear but why? what is missing ?


  • Moderators

    @elicat said in qmlRegisterType dont' recogized into qml file:

    qmlRegisterType<engineIndexHtml>("PageIndexHtml", 1, 0, "engineIndexHtml");

    import PageIndexHtml 2.0

    You declared it as a 1.0 version but imported a 2.0 version.


  • Moderators

    @elicat said in qmlRegisterType dont' recogized into qml file:

    Cannot assign to non-existent property "engineIndexHtml"

    beside what @ambershark said, types always must start with a capital letter!



  • Additionally to the previous posters,

    you need to register your types before creating the QQmlApplicationEngine object:

    qmlRegisterType<YX>(....);
    
    QQmlApplicationEngine engine;
    engine.load(...);
    


  • @raven-worx I had forgotten the rule, thank you and the row of register it had been put before

     QQmlApplicationEngine engine;
    

    Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.