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. Direct base 'QObject' is inaccessible due to ambiguity

Direct base 'QObject' is inaccessible due to ambiguity

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 2.0k 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.
  • F Offline
    F Offline
    fem_dev
    wrote on last edited by
    #1

    I'm developing a shared library (plugin) to my Qt C++ application.
    Following many tutorials (like this) in the internet, I found that:
    a) The plugin interface should inherit QObject class
    b) The plugin interface MUST HAVE the Q_OBJECT macro to enable to use the same signals and slots in all developed plugins.

    Here is my plugin interface: (No warnings)

    #ifndef PLUGIN_API_H
    #define PLUGIN_API_H
    
    #include <QtPlugin>
    #include <QString>
    
    class Plugin_API : public QObject
    {
        Q_OBJECT
    
    public:
        virtual ~Plugin_API() = default;
        virtual void showUI(void) = 0;
        virtual void test(void) = 0;
    
    signals:
        void sendString(QString string);
    };
    
    Q_DECLARE_INTERFACE(Plugin_API, "com.lamar.plugin")
    
    #endif // PLUGIN_API_H
    

    Here is my plugin class.

    #ifndef MYLIB_H
    #define MYLIB_H
    
    #include <QObject>
    #include <QString>
    
    #include "myLib_global.h"
    #include "plugin_api.h"
    
    class MYLIB_EXPORT MyLib : public QObject, public Plugin_API
    {
        Q_OBJECT
        Q_PLUGIN_METADATA(IID "com.lamar.plugin")
        Q_INTERFACES(Plugin_API)
    
    public:
        explicit MyLib(QObject* parent = nullptr);
    
        void test() override;
        void showUI() override;
    };
    
    #endif // MYLIB_H
    

    In my plugin class myLib I got this warning message:

    Direct base 'QObject' is inaccessible due to ambiguity
    

    If I remove the QObject inheritance, I can't use the Q_OBJECT macro.
    If I don't have both, I can't use MyLib(QObject* parent = nullptr);

    So, what is the right way to do that?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      You don't need to inherit QObject in MyLib because Plugin_API already has.
      So MyLib already inherits QObject even without that "public QObject".
      Just like when we subclass QWidget, we don't need to inherit QObject in our code, but the new class can use Q_OBJECT macro and signals/slots, because QWidget inherits QObject.

      1 Reply Last reply
      3

      • Login

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