Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QMetaProperty::read: 'Unable to handle unregistered datatype' error
QtWS25 Last Chance

QMetaProperty::read: 'Unable to handle unregistered datatype' error

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 3 Posters 9.3k 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
    schwaer
    wrote on last edited by schwaer
    #1

    Whats the misstake? Whats missing?
    Actually we try to have a class with text we use in more projects so we have seperate translation .ts files for all of them. So we have to translate it just once.
    We add a "Translate" class. In this class we have for example a other class with some material names.
    Now we want to use them in cpp and qml.
    On execute the project we got the "Unable to handle unregistered datatype" error! But we don't no why!

    Here is a extract of our code!
    If someone has a hint, it would be very helpful

    Translate.h

    namespace translationids
    {
    class Translate : public QObject
    {
      Q_OBJECT
    
    public:
      static TranslateMaterial TranslateMaterials;
      Q_PROPERTY(TranslateMaterial *translateMaterials READ getTranslateMaterials() CONSTANT)
    
      //% "Menu"
      static constexpr const char *common_MainMenu = QT_TRID_NOOP("common.mainmenu");
    
      /** enables attached properties in QML */
      static Translate *qmlAttachedProperties(QObject *);
    
    private:
      /** Default constructor */
      Translate(QObject *parent = 0);
    
      /** destructor */
      virtual ~Translate() {}
    };
    
    } /* namespace translationids */
    
    QML_DECLARE_TYPEINFO(translationids::Translate, QML_HAS_ATTACHED_PROPERTIES)
    
    

    Translate.cpp

    #include "Translate.h"
    #include "TranslateMaterial.h"
    
    using namespace translationids;
    
    TranslateMaterial Translate::translateMaterials;
    
    Translate *Translate::qmlAttachedProperties(QObject *object)
    {
      return new Translate(object);
    }
    
    Translate::Translate(QObject *parent)
      : QObject(parent)
    {
    }
    
    TranslateMaterial* Translate::getTranslateMaterials()
    {
      return &translateMaterials;
    }
    

    TranslateMaterial.h

          namespace translationids
          {
            /** class Material Translations *********/
            class TranslateMaterial
            {
                Q_GADGET
    
              public:
                //% "User defined"
                static constexpr const char* material_UserDefined = QT_TRID_NOOP("material.userdefined");
                Q_PROPERTY(QString material_UserDefined MEMBER _Material_UserDefined CONSTANT)
                //% "Aluminium"
                static constexpr const char* material_Aluminium = QT_TRID_NOOP("material.aluminium");
                Q_PROPERTY(QString material_Aluminium MEMBER _Material_Aluminium CONSTANT)
                //% "Wood"
                static constexpr const char* material_Wood = QT_TRID_NOOP("material.wood");
                Q_PROPERTY(QString material_Wood MEMBER _Material_Wood CONSTANT)
    
               
                TranslateMaterial();
    
                ~TranslateMaterial() {}
    
            };
          } /* namespace translationids */
    
    Q_DECLARE_METATYPE(translationids::TranslateMaterial)
    

    TranslateMaterial.cpp

    using namespace translationids;
    
    TranslateMaterial::TranslateMaterial()
    {
    }
    

    Main.cpp

     qmlRegisterUncreatableType<translationids::Translate>("translationids.translate", 0, 1, "Translate", "translate only has attached properties! You can not create an instance.");
     qmlRegisterUncreatableType<translationids::TranslateMaterial>("translationids.translate", 0, 1, "TranslateMaterial", "TranslateMaterial is a Q_GADGET! You can not create an instance.");
    

    Using in cpp

    #include <translationIDs/Translate.h>
    
    std::vector<Material::MaterialStruct> Material::ms_vecMaterial =
    {
      // Material Name, String ID
      { "UserDefined", Translate::TranslateMaterials.material_UserDefined },
      { "Aluminium", Translate::TranslateMaterials.material_Aluminium },
      { "Wood", Translate::TranslateMaterials.material_Wood },
    }
    

    Using in qml

    import translationids.translate 0.1
         
         Text{
            id:headerText
            anchors.centerIn: parent
            height: parent.height
            width: parent.width
            text: qsTrId(Translate.translateMaterials.material_Aluminium) 
          }
    

    Thats are the Error Messages:
    QMetaProperty::read: Unable to handle unregistered datatype 'TranslateMaterial*' for property 'translationids::Translate::translateMaterials'
    MaterialTopDownMenu.qml:72 ((null)): MaterialTopDownMenu.qml:72: TypeError: Cannot read property 'material_Aluminium' of undefined

    What is missing?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Ray Gray
      wrote on last edited by
      #2

      It's difficult to answer if you don't provide compilable code (std::vectorQString::Material ???).

      1 Reply Last reply
      0
      • S Offline
        S Offline
        schwaer
        wrote on last edited by
        #3

        Sorry that was a misstake,

        std::vector<Material::MaterialStruct> Material::ms_vecMaterial =
        

        But it doesn't matter because the cpp works. I just got the problem with qml!

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ray Gray
          wrote on last edited by
          #4

          Where and how is Translate instantiated? (as I said, it would be much easier to answer if you should provide a complete example).

          1 Reply Last reply
          0
          • S Offline
            S Offline
            schwaer
            wrote on last edited by
            #5

            I'm sorry but it's hard to seperate this things from project!
            Maybe this helps you a litte bit more:

            If i write

             text: qsTrId(TlibTranslate.tlib_Common_MainMenu)
            

            it works!

            But

            text: qsTrId(TlibTranslate.tlibTranslateMaterials.tlib_Material_Aluminium)
            

            doesn't

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Since you are using your custom type in a property you should also take a look at the Custom Types chapter in Qt's documentation.

              Basically you are not making the type know to the Qt meta system. See Q_DECLARE_METATYPE and qRegisterMetaType.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                schwaer
                wrote on last edited by
                #7

                They are set!

                Translate.h

                QML_DECLARE_TYPEINFO(translationids::Translate, QML_HAS_ATTACHED_PROPERTIES)
                

                TranslateMaterial.h

                Q_DECLARE_METATYPE(translationids::TranslateMaterial)
                

                Main.cpp

                qmlRegisterUncreatableType<translationids::Translate>("translationids.translate", 0, 1, "Translate", "translate only has attached properties! You can not create an instance.");
                 qmlRegisterUncreatableType<translationids::TranslateMaterial>("translationids.translate", 0, 1, "TranslateMaterial", "TranslateMaterial is a Q_GADGET! You can not create an instance.");
                
                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  schwaer
                  wrote on last edited by
                  #8

                  Okay, ifound it out by myself!
                  Everything works well if i define the TranslateMaterial class as a Q_OBJECT, like the Translate class!

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    My bad, the code parts can be tricky to read when scrolling is involved.

                    Glad you found a solution hand thanks for sharing.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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