Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtRO, How to make repc (.rep) customtype accessible in qml?
Forum Updated to NodeBB v4.3 + New Features

QtRO, How to make repc (.rep) customtype accessible in qml?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 202 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.
  • M Offline
    M Offline
    majorRonk
    wrote on last edited by majorRonk
    #1

    In my replica file (.rep) i want to use a customtype, which is defined outside of this replica,
    as a property of the interface and access its members and methods via qml.

    Current rep file looks like this:

    #include <CustomClass>
    
    class CustomInterface
    {
        PROP(QList<mynamespace::CustomClass> list SOURCEONLYSETTER)
    }
    

    Simulation works but, i cannot access "list" in qml. Calls on members or functions gives me always "undefined".
    (like: CustomInterfaceReplica.list.member or CustomInterfaceReplica.list.method)

    Unfortunately the official doc does not give a lot of information
    about how to use custom classes correctly with rep files.
    https://doc.qt.io/qt-6/qtremoteobjects-repc.html

    My current solution is to write all members of CustomClass to a qvariantmap and expose it to qml with QStandardItemModel.

    What i found out:

    • PROP(CustomClass*) does not build.
    • PROP(QList<CustomClass*>) does crash in application
    • PROP(QList<CustomClass>) cannot be accessed in qml
    • POD CustomType(QString name, CustomClass value) does not build.
    • CLASS(CustomClass) works, if CustomClass is also declared in the rep file.
    • CLASS(CustomClass) does not build, if CustomClass is not declared in a rep file.
    R 1 Reply Last reply
    0
    • M majorRonk

      In my replica file (.rep) i want to use a customtype, which is defined outside of this replica,
      as a property of the interface and access its members and methods via qml.

      Current rep file looks like this:

      #include <CustomClass>
      
      class CustomInterface
      {
          PROP(QList<mynamespace::CustomClass> list SOURCEONLYSETTER)
      }
      

      Simulation works but, i cannot access "list" in qml. Calls on members or functions gives me always "undefined".
      (like: CustomInterfaceReplica.list.member or CustomInterfaceReplica.list.method)

      Unfortunately the official doc does not give a lot of information
      about how to use custom classes correctly with rep files.
      https://doc.qt.io/qt-6/qtremoteobjects-repc.html

      My current solution is to write all members of CustomClass to a qvariantmap and expose it to qml with QStandardItemModel.

      What i found out:

      • PROP(CustomClass*) does not build.
      • PROP(QList<CustomClass*>) does crash in application
      • PROP(QList<CustomClass>) cannot be accessed in qml
      • POD CustomType(QString name, CustomClass value) does not build.
      • CLASS(CustomClass) works, if CustomClass is also declared in the rep file.
      • CLASS(CustomClass) does not build, if CustomClass is not declared in a rep file.
      R Offline
      R Offline
      Redman
      wrote on last edited by
      #2

      @majorRonk

      Custom types work. Needs #include for the appropriate header for your type, make sure your type is known to the metabject system, and make sure it supports Queued Connections (see Q_DECLARE_METATYPE and qRegisterMetaType
      

      Did you register your custom type with the metaobject system?

      M 1 Reply Last reply
      0
      • R Redman

        @majorRonk

        Custom types work. Needs #include for the appropriate header for your type, make sure your type is known to the metabject system, and make sure it supports Queued Connections (see Q_DECLARE_METATYPE and qRegisterMetaType
        

        Did you register your custom type with the metaobject system?

        M Offline
        M Offline
        majorRonk
        wrote on last edited by majorRonk
        #3

        @Redman said in QtRO, How to make repc (.rep) customtype accessible in qml?:

        Q_DECLARE_METATYPE

        I tried Q_DECLARE_METATYPE, qRegisterMetaType and qmlRegisterType with CustomType and QList<CustomType>. Does not help.

        When i do this in qml:

        Connections {
                   target: CustomInterfaceReplica
        
                   function onListChanged(list) {
                       tabButtonSplit.text = list[0].myProperty
                   }
               }
        

        text shows "undefined".
        when i call list[0].toString()
        it shows "QVariant(QList<mynamespace::CustomClass, )"

        1 Reply Last reply
        0

        • Login

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