I would like to use loads of custom objects with Qt5 remote objects. As I read they might not needed to be created as PODs in the .REP file. I have tried to do the following:
namespace my::api {
class Card {
Q_GADGET
Q_PROPERTY(QString type READ type WRITE setType)
[... removed property functions]
Q_PROPERTY(QString id READ id WRITE setId)
[... removed property functions]
public:
static void declareQML() {
qRegisterMetaType<my::api::Card>("Card");
}
};
inline QDataStream& operator<<(QDataStream& stream, const my::api::Card & value) {
stream << value.type() << value.id();
return stream;
}
inline QDataStream& operator>>(QDataStream& stream, quint::api::Card & value) {
QString tmp;
stream >> tmp;
value.setType(tmp);
stream >> tmp;
value.setId(tmp);
return stream;
}
class Result {
Q_GADGET
Q_PROPERTY(bool status READ status WRITE setStatus NOTIFY statusChanged)
public:
bool status() { return m_status; }
public slots:
void setStatus(bool p) { m_status = p; emit statusChanged(); }
private:
bool m_status;
public:
static void declareQML() {
qRegisterMetaType<my::api::Result>("Result");
}
Result() : m_code(false) {}
};
inline QDataStream& operator<<(QDataStream& stream, const my::api::Result & value) {
stream << value.status();
return stream;
}
inline QDataStream& operator>>(QDataStream& stream, my::api::Result & value) {
bool tmp;
stream >> tmp;
value.setStatus(tmp);
return stream;
}
}
Then do something like that in the .REP:
SLOT(checkCard(my::api::Card card));
SIGNAL(checkCardResponse(my::api::Result result));
However I get
Trying to construct an instance of an invalid type, type id: 1073676288
Trying to construct an instance of an invalid type, type id: 655615
Trying to construct an instance of an invalid type, type id: 1073676288
from the client, when I try to do a checkCard().
all the declareQML stuff is called right after starting the application (before the replica is created).
Can anyone post me a complete/working example how to use custom classes with QT5 Remote Objects without creating the custom classes as PODs in the REP file?