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. Is it possible to share complex polymorphic objects between processes (such as [IShape=>Circle]) using D-Bus interface?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to share complex polymorphic objects between processes (such as [IShape=>Circle]) using D-Bus interface?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 130 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.
  • C Offline
    C Offline
    caramel_fudge
    wrote on last edited by caramel_fudge
    #1

    Dear Qt community!

    Our use case is to pass complex polymorphic objects between two processes (for example a client and a server). D-bus seemed the perfect candidate to this scenario.

    Unfortunately we are struggling to achieve this.

    For this example just use Shape and derived classes such as Circle and Rectangle.

    #include <QDBus
    #include <memory>
    
    class Shape {
    public:
        virtual ~Shape() = default;
        virtual void draw() = 0;
    };
    
    Q_DECLARE_METADATA(Shape)
    
    // Implemented somewhere else
    
    class Circle : public Shape {
    public:
        virtual ~Circle() {}
        virtual void draw() {
            // do the drawing
        }
    };
    

    With qtcpp2xml we generate the xml, then the adaptors and proxies. I read somewhere in the documentation that you need also add Q_DECLARE_METADATA() also in order to pass objects. Unfortunately it is not that simple. For simplicity just leave it for now, and let's continue normally.

    #include <QObject>
    
    #include <memory>
    #include <vector>
    
    class DrawingBoard : public QObject {
        Q_OBJECT
       Q_CLASSINFO("D-Bus Interface", "org.geo.DrawingBoard")
    
    public:
        virtual ~DrawingBoard() {}
    
    public slots:
        void addShape(std::unique_ptr<Shape> shape) {
            shapes.emplace_back(std::move(shape));
        }
    
        void draw()
        {
            for (auto& shape : shapes) {
                shape->draw();
            }
        }
    
    private:
        std::vector<std::unique_ptr<Shape>> shapes;
    };
    

    Is it possible to use D-Bus like this? If it is possible, how? The code generator reports that cannot use pointers! If I change the corresponding line to reference, then the compilation will fail, because it cannot pass incomplete type!

    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