Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtPlugin: duplicate if-conditions in generated qt_metacast

QtPlugin: duplicate if-conditions in generated qt_metacast

Scheduled Pinned Locked Moved Solved General and Desktop
pluginmoccasting
6 Posts 2 Posters 1.4k Views
  • 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.
  • 0 Offline
    0 Offline
    0...-5
    wrote on 5 Nov 2018, 07:14 last edited by 0...-5 11 May 2018, 07:17
    #1

    My problem is the following: I have written a plugin that inherits several interfaces. My plugin definition is:

    class Info: public QObject, CoreInterface, DataInterface {
        Q_OBJECT
    #if QT_VERSION >= 0x050000
        Q_PLUGIN_METADATA(IID "Plugins.Info")
    #endif
        Q_INTERFACES(CoreInterface DataInterface)
    
    public:
        void setValue(const QString &role, QVariant value, QByteArray &codogram) const override;
        int protocol() const override;
        int type() const override;
        int size() const override;
        QVariant value(const QString &role, const QByteArray &codogram) const override;
        QByteArray create() const override;
        QStringList roles() const override;
    };
    

    where CoreInterface and DataInterafce are declared interfaces.
    I have checked my project with PVS and found that generated MOC files contains the following code:

    void *Info::qt_metacast(const char *_clname)
    {
        if (!_clname) return nullptr;
        if (!strcmp(_clname, qt_meta_stringdata_Info.stringdata0))
            return static_cast<void*>(this);
        if (!strcmp(_clname, "CoreInterface"))
            return static_cast< CoreInterface*>(this);
        if (!strcmp(_clname, "DataInterface"))
            return static_cast< DataInterface*>(this);
        if (!strcmp(_clname, "CoreInterface"))
            return static_cast< CoreInterface*>(this);
        if (!strcmp(_clname, "DataInterface"))
            return static_cast< DataInterface*>(this);
        return QObject::qt_metacast(_clname);
    }
    

    So each interface name is being checked twice for casting. What is the reason for this?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 Nov 2018, 07:18 last edited by
      #2

      Hi,

      Can you also provide your interfaces definition ?
      What version of Qt are you using ?

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

      0 1 Reply Last reply 5 Nov 2018, 07:23
      0
      • S SGaist
        5 Nov 2018, 07:18

        Hi,

        Can you also provide your interfaces definition ?
        What version of Qt are you using ?

        0 Offline
        0 Offline
        0...-5
        wrote on 5 Nov 2018, 07:23 last edited by
        #3

        @SGaist Sure I can
        I have checked it on Qt 5.11.1 and Qt 4.8.6

        class CoreInterface {
        public:
            virtual int protocol() const = 0;
        };
        Q_DECLARE_INTERFACE(CoreInterface, "CoreInterface")
        
        class DataInterface {
        public:
            virtual void setValue(const QString &role, QVariant value, QByteArray &codogram) const = 0;
            virtual int type() const = 0;
            virtual int size() const = 0;
            virtual QVariant value(const QString &role, const QByteArray &codogram) const = 0;
            virtual QByteArray create() const = 0;
            virtual QStringList roles() const = 0;
        };
        Q_DECLARE_INTERFACE(DataInterface, "DataInterface")
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 Nov 2018, 23:36 last edited by
          #4

          That's because you are not using Q_DECLARE_INTERFACE correctly. Therefor you are creating the duplicate entries.

          See the identifier format in the macro documentation.

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

          0 1 Reply Last reply 8 Nov 2018, 05:39
          2
          • S SGaist
            7 Nov 2018, 23:36

            That's because you are not using Q_DECLARE_INTERFACE correctly. Therefor you are creating the duplicate entries.

            See the identifier format in the macro documentation.

            0 Offline
            0 Offline
            0...-5
            wrote on 8 Nov 2018, 05:39 last edited by
            #5

            @SGaist Well, according to documentation the only thing I should keep in mind is that identifier must be unique, and I haven't broke it. There is nothing about identifier and classname should not match literaly, and that is the reason of my problem as far as I can see. Maybe there is a point to specify that in docs.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 8 Nov 2018, 07:08 last edited by
              #6

              Well, a class name is not a unique identifier since it's already used to name said 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

              4/6

              7 Nov 2018, 23:36

              • Login

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