Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Embedding a shared library in a QML File
Forum Updated to NodeBB v4.3 + New Features

Embedding a shared library in a QML File

Scheduled Pinned Locked Moved QML and Qt Quick
qmlshared librarydllc++
2 Posts 2 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reinier R. Gonzalez
    wrote on last edited by
    #1

    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
    resources.qrc
    QML_IMPORT_PATH =
    include(deployment.pri)
    OTHER_FILES +=
    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_OBJECT
    Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
    QString name;
    Q_PROPERTY(QString id READ getId WRITE setId NOTIFY idChanged)
    QString id;

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

    signals:
    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;
    engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
    
    return app.exec();
    

    }

    p3c0P 1 Reply Last reply
    0
    • R Reinier R. Gonzalez

      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
      resources.qrc
      QML_IMPORT_PATH =
      include(deployment.pri)
      OTHER_FILES +=
      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_OBJECT
      Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
      QString name;
      Q_PROPERTY(QString id READ getId WRITE setId NOTIFY idChanged)
      QString id;

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

      signals:
      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;
      engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
      
      return app.exec();
      

      }

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi @Reinier-R.-Gonzalez,

      The class should be declared as:

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

      157

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved