I have a STL codebase that need to be shared between a QtQuick 2.0 application (the graphical interface) and a purely STL application (the server). The interface can derive its classes from the shared STL codebase, so it can have Q_PROPERTYs, signals, slots, etc. but the shared data structures need to remain STL-only.
I'd like to avoid data duplication (std::string -> QString, etc.) so I tried to use std::string directly within the Q_PROPERTY system. Using Q_DECLARE_METATYPE(std::string) and qRegisterMetaType<std::string>(); and declaring properties like:
Q_PROPERTY(QString stldata READ stldata WRITE setSTLData NOTIFY stldataChanged)
makes my code compile, but QML still doesn't like std::strings.
Writing a text field with:
Text
{
text: myserviceinterface.stldata
}
produces a warning saying Unable to assign std::string to QString, while appending an existing QML string:
Text
{
text: "text: " + myserviceinterface.stldata
}
makes the Text control display a weird QVariant(std::string).
What am I doing wrong?