Error while using qmlRegisterType



  • Hi

    I am trying to expose a C++ class to qml and I have used the following line of code in main.cpp after including the class header.

    qmlRegisterType<FlightMapSettings>("FlightMapSettings",1,0,"MapSettings");
    

    But I get these errors:

    ...../Qt5.6.0/5.6/gcc_64/include/QtQml/qqmlprivate.h:102: error: use of deleted function 'QQmlPrivate::QQmlElement<FlightMapSettings>::QQmlElement()'
    void createInto(void *memory) { new (memory) QQmlElement<T>; }

    ..../Qt5.6.0/5.6/gcc_64/include/QtQml/qqmlprivate.h:93: error: no matching function for call to 'FlightMapSettings::FlightMapSettings()'
    ^

    What could be the possible issue?

    Thanks


  • Moderators

    Hi! Please show us said header file.



  • @Wieland

    #include <QObject>
    #include <QStringList>
    
    class FlightMapSettings : public QWidget
    {
        Q_OBJECT
    
    public:
        FlightMapSettings(QWidget *parent);
    signals:
    void mapProviderChanged(const QString& mapProvider);
        void mapTypesChanged(const QStringList& mapTypes);
    };
    

  • Moderators

    First of all , #include <QWidget> is missing. Second is the missing default constructor:

    explicit FlightMapSettings(QWidget *parent = Q_NULLPTR);
    

  • Moderators

    BTW, why do you register a QWidget derived class to the QML engine?



  • @Wieland

    I have given the default constructor and it works. It was a copy paste mistake and I have removed the QWidget.

    Thanks a lot!!


Log in to reply
 

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