Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Custom types in QML with Android issue
QtWS25 Last Chance

Custom types in QML with Android issue

Scheduled Pinned Locked Moved Solved Mobile and Embedded
4 Posts 2 Posters 366 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    St.Stanislav
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      St.Stanislav
      wrote on last edited by
      #4

      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.

      1 Reply Last reply
      0
      • TomZT Offline
        TomZT Offline
        TomZ
        wrote on last edited by
        #2

        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...

        S 1 Reply Last reply
        0
        • TomZT TomZ

          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...

          S Offline
          S Offline
          St.Stanislav
          wrote on last edited by
          #3

          @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.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            St.Stanislav
            wrote on last edited by
            #4

            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.

            1 Reply Last reply
            0
            • S St.Stanislav has marked this topic as solved on

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved