Custom types in QML with Android issue
-
Hello everyone!
I have faced with the following issue and have no idea how to fix it.I have decided to compile and deploy my desktop application to Android. In the application I have my custom types (Q_ENUM) that I register in QML and work with it. I have the following static function and it works well on desktop:
template<typename T> static void registerQML() { QString typeName = QString(typeid (T).name()).split(" ").last(); typeName = typeName.split(":").last(); qmlRegisterUncreatableType<T>("App.Enums", 1, 0, qPrintable(typeName), qPrintable(typeName)); qRegisterMetaType<typename T::Value>(qPrintable(QString("%1::Value").arg(typeName))); qRegisterMetaType<T*>(qPrintable(QString("%1Handler*").arg(typeName))); qmlRegisterSingletonType<T>("App.Enums", 1, 0, qPrintable(QString("%1Handler").arg(typeName)), [typeName](QQmlEngine* engine, QJSEngine* scriptEngine)->T* { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new T(); }); }
Code can be compiled well on Android but while running there are errors when using QML Components with the custom types:
W libTestApp_arm64-v8a.so: qrc:/QML/ConnectionModule/AbstractConnection.qml:15: ReferenceError: ConnectionTypeHandler is not defined W libTestApp_arm64-v8a.so: qrc:/QML/ConnectionModule/AbstractConnection.qml:60: ReferenceError: ConnectionType is not defined
I use build-tools with version 34.0.0 and Android SDK 27 (have tried several others with no success). What can be the reason for this issue and how to solve it?
-
After closer inspection, I have found that there are different types from
typeid (T).name()
So Android code should be slightly different to parse it correctly.
-
your reference to Android makes me wonder,
does this work Ok on desktop?
I do 99% of my development on desktop and only android specific stuff on device. This looks like something that isn't Android specific...
I'd guess you didn't call your register method before the engine was created...
-
your reference to Android makes me wonder,
does this work Ok on desktop?
I do 99% of my development on desktop and only android specific stuff on device. This looks like something that isn't Android specific...
I'd guess you didn't call your register method before the engine was created...
@TomZ As I said it works well on desktop, so that's why I have a question :) And yes, I register type before engine creation.
-
After closer inspection, I have found that there are different types from
typeid (T).name()
So Android code should be slightly different to parse it correctly.
-