QtPlugin: duplicate if-conditions in generated qt_metacast
-
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?
-
Hi,
Can you also provide your interfaces definition ?
What version of Qt are you using ? -
@SGaist Sure I can
I have checked it on Qt 5.11.1 and Qt 4.8.6class 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")
-
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.
-
@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.
-
Well, a class name is not a unique identifier since it's already used to name said class.