my Qt/QML program uses classes declared in C++ to structure information in QML and pass it as a bundle to C++ functions.
The structs are derived from QObject as required by QML. Example:
class ResultStorageOptionsStruct : public QObject {
Q_OBJECT
public:
explicit ResultStorageOptionsStruct(QObject * parent = nullptr) : QObject(parent) {}
~ResultStorageOptionsStruct() = default;
ResultStorageOptionsStruct(const ResultStorageOptionsStruct& blob) {
}
bool folderValid;
QString folderURL;
Q_PROPERTY(bool folderValid MEMBER folderValid)
Q_PROPERTY(QString folderURL MEMBER folderURL)
};
Q_DECLARE_METATYPE(ResultStorageOptionsStruct);
Using this method, passing information from QML to C++ works without a problem, but handling of that information on the C++ side is very bothersome due to the fact that you cannot copy/assign the class(derived of QObject).
I would like to copy/serialize/deserialize my classes for easy handling once they are on the c++ side. I do not need the features QObject gives me once we are on the c++ side as those classes are just containers for the information.
Is there some kind of trick or data structure to make this happen?
Qt.point(...)
). Maybe a cast operator is an option? This does duplicate the structs but sounds like you might like it – Amfasis