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. [SOLVED]C++ slot in QML
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]C++ slot in QML

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.8k Views 1 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.
  • E Offline
    E Offline
    ExorcistInc
    wrote on last edited by
    #1

    Hi!
    I have abstract class, let it be IParent, with this structure:
    @class IParent : public QObject
    {
    Q_OBJECT
    public slots:
    virtual void parentSlot() = 0;
    };@

    And its child Child:
    @class Child : public IParent
    {
    public slots:
    void parentSlot() = {//slot definition};
    void childSlot() = {//slot definition};
    };@

    In main.cpp Child class registed as
    @qmlRegisterType<Child>("package", 1, 0, "Child");@

    In QML file when I try to execute childSlot() I get this error:
    @TypeError: Property 'childSlot' of object IParent (0x3625880) is not a function@

    How it is possible to fix it and point QML to execute Child slot instead of IParent?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The thing I currently see is that your are missing the Q_OBJECT macro in your Child class

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ExorcistInc
        wrote on last edited by
        #3

        Is it necessary to use Q_OBJECT macro, if it exists in parent class?

        In real application I have IBluetoothProvider as parent class and SppProvider and BlueEvaProvider as its children. SppProvider does not have Q_OBJECT macro or new slots, it is only defines IBluetoothProvider methods and works fine:)

        Adding Q_OBJECT to BlueEvaProvider class gives me errors like:
        LNK2001 and LNK2019 - unresolved external symbol

        Full error output:
        @main.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall BlueEvaProvider::metaObject(void)const " (?metaObject@BlueEvaProvider@@UBEPBUQMetaObject@@XZ)
        blueevaprovider.obj : error LNK2019: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall BlueEvaProvider::metaObject(void)const " (?metaObject@BlueEvaProvider@@UBEPBUQMetaObject@@XZ) referenced in function "private: virtual void __thiscall BlueEvaProvider::receiveData(void)" (?receiveData@BlueEvaProvider@@EAEXXZ)
        main.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall BlueEvaProvider::qt_metacast(char const *)" (?qt_metacast@BlueEvaProvider@@UAEPAXPBD@Z)
        blueevaprovider.obj : error LNK2019: unresolved external symbol "public: virtual void * __thiscall BlueEvaProvider::qt_metacast(char const *)" (?qt_metacast@BlueEvaProvider@@UAEPAXPBD@Z) referenced in function "public: void __thiscall BlueEvaProvider::availablePorts(void)" (?availablePorts@BlueEvaProvider@@QAEXXZ)
        main.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall BlueEvaProvider::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@BlueEvaProvider@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
        blueevaprovider.obj : error LNK2019: unresolved external symbol "public: virtual int __thiscall BlueEvaProvider::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@BlueEvaProvider@@UAEHW4Call@QMetaObject@@HPAPAX@Z) referenced in function "public: void __thiscall BlueEvaProvider::availablePorts(void)" (?availablePorts@BlueEvaProvider@@QAEXXZ)
        main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const BlueEvaProvider::staticMetaObject" (?staticMetaObject@BlueEvaProvider@@2UQMetaObject@@B)
        blueevaprovider.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const BlueEvaProvider::staticMetaObject" (?staticMetaObject@BlueEvaProvider@@2UQMetaObject@@B)@

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Yes, all classes that derives from QObject and are using signals and slots must include the Q_OBJECT macro.

          You must re-run qmake when adding/removing that macro from a class

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ExorcistInc
            wrote on last edited by
            #5

            Oh, yes, it is really helped! Thanks a lot!

            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