Is it possible to share complex polymorphic objects between processes (such as [IShape=>Circle]) using D-Bus interface?
-
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!