⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Embedding a shared library in a QML File

  • I'm trying to use a shared library (created by me) in a QML file. The project its about a game with virtual players. Each 'virtual' player it's just a shared library that exposes a name and a playing function. All seems to be good until the compiling phase when the next error arises:
    C:\Qt\Qt5.3.0\5.3\mingw482_32\include\QtCore\qmetatype.h:1297: error: 'QObject' is an inaccessible base of 'Player'
    enum { Value = sizeof(checkType(static_cast<T*>(0))) == sizeof(yes_type) };

    this is the .pro file:
    TEMPLATE = app
    QT += qml quick widgets
    SOURCES += main.cpp
    RESOURCES += qml.qrc
    unix|win32: LIBS += -L$$PWD/dlls/ -lplayer
    INCLUDEPATH += $$PWD/dlls
    DEPENDPATH += $$PWD/dlls

    the player.h file:
    #ifndef PLAYER_H
    #define PLAYER_H

    #include "player_global.h"
    #include <QObject>
    #include <QString>

    class PLAYERSHARED_EXPORT Player : QObject
    Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
    QString name;
    Q_PROPERTY(QString id READ getId WRITE setId NOTIFY idChanged)
    QString id;

    Player(QString name);
    const QString getName();
    void setName(const QString name);
    const QString getId();
    void setId(const QString id);

    void nameChanged();
    void idChanged();

    #endif // PLAYER_H

    the player.cpp file:
    #include "player.h"

    Player::Player(QString name = "")
    this->name = name;

    const QString Player::getName()
    return this->name;

    void Player::setName(const QString name)
    this->name = name;

    const QString Player::getId()
    return this->id;

    void Player::setId(const QString id)
    this->id = id;

    the main.cpp:
    #include <QApplication>
    #include <QQmlApplicationEngine>
    #include <QtQml>

    #include "player.h"

    int main(int argc, char *argv[])
    QApplication app(argc, argv);

    qmlRegisterType<Player>("cu.uci.fac5.player", 1, 0, "Player");
    QQmlApplicationEngine engine;
    return app.exec();


  • Moderators

    Hi @Reinier-R.-Gonzalez,

    The class should be declared as:

    class PLAYERSHARED_EXPORT Player : public QObject //Note the public keyword