Hi, I need to send a pointer to a custom class (a model derived from QSqlRelationalTableModel) over the DBus. What I already know:
- I can incapsulate an arbitrary object into a QVariant instance.
- I can incapsulate a pointer to an arbitrary object into a QVariant instance.
- I can save and restore this object if I implement << and >> operators (with QDataStream argument).
- I can incapsulate a QVariant into a QDBusVariant if I need to send it over the DBus.
- I can send an arbitrary object over the DBus if I implement << and >> operators (with QDBusArgument argument).
So, how can I do this?
My idea is:
1) Add Q_DECLARE_METATYPE(MyClass) and Q_DECLARE_METATYPE(MyClass*) at the end of MyClass declaration.
2) Implement QDataStream &operator<<(QDataStream &out, const MyClass &myObj) and QDataStream &operator>>(QDataStream &in, MyClass &myObj) operators.
3) Implement QDBusArgument &operator<<(QDBusArgument &out, const MyClass &myObj) and QDBusArgument &operator>>(QDBusArgument &in, MyClass &myObj) operators.
4) Implement MyClass(), MyClass(const MyClass& obj), ~MyClass() c/dtors.
5) Add qDBusRegisterMetaType<MyClass>() call into all ctors.
With these steps, can I write something like this (if we suppose remote and local objects are in the same process)?
Qt Code:
// Remote object class MyQDBusAdaptor { // ... MyClass* my_method(); } // Local object MyClass* ret = app->call("my_method");To copy to clipboard, switch view to plain text mode
Bookmarks