Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. was ist der Unterschied zwischen qmlRegisterType und qRegisterMetaType?

was ist der Unterschied zwischen qmlRegisterType und qRegisterMetaType?

Scheduled Pinned Locked Moved Unsolved German
5 Posts 2 Posters 1.5k 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.
  • G Offline
    G Offline
    Galilio
    wrote on last edited by
    #1

    Hallo Zusammen,

    Was ist der Unterschied zwischen qmlRegisterType und qRegisterMetaType und wann kann die benutzen?

    danke

    J.HilkJ 1 Reply Last reply
    0
    • G Galilio

      Hallo Zusammen,

      Was ist der Unterschied zwischen qmlRegisterType und qRegisterMetaType und wann kann die benutzen?

      danke

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Galilio
      qRegisterMetaType wird benutzt um einen Type für das QMetaObject System zu registrieren, damit es zum Beispiel via Signal/Slots über threads hinweg benutzt werden kann

      qmlRegisterType ist wie der name suggeriert dafür da, das der Type in QML verwendet werden kann, importiert und instanziert

      https://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType
      https://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterType


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • G Offline
        G Offline
        Galilio
        wrote on last edited by
        #3

        @J-Hilk
        Danke für die Antwort.
        Ich habe folgende:

          class Bar : public QObject
          {
              Q_OBJECT
              Q_PROPERTY(QString baz READ baz WRITE setBaz NOTIFY bazChanged)
        
          public:
              Bar() {}
        
              QString baz() const { return mBaz; }
        
              void setBaz(const QString &baz)
              {
                  if (baz == mBaz)
                      return;
        
                  mBaz = baz;
                  emit bazChanged();
              }
        
          signals:
              void bazChanged();
        
          private:
              QString mBaz;
          };
        
          class Foo : public QObject
          {
              Q_OBJECT
              Q_PROPERTY(Bar *bar READ bar CONSTANT FINAL)
        
          public:
              //Foo() {}
        	  Foo(std::shared_ptr<Bar> bar, QObject* aParent = nullptr )
        
              Bar *bar() { return &mBar; }
        
          private:
              Bar mBar;
          };
          
        

        Was ist dann falsch, wenn ich so schreibe?

         qmlRegisterType<Foo>("App", 1, 0, "Foo");
        

        Danke

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Galilio
          wrote on last edited by
          #4

          Ich bekomme folgende Fehlermeldung:

          -5.12.3/include/QtQml/qqmlprivate.h:98:11: note: ‘QQmlPrivate::QQmlElement<Foo >::QQmlElement()’ is implicitly deleted because the default definition would be ill-formed:
               class QQmlElement final : public T
          
          1 Reply Last reply
          0
          • J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            Tja, ein wenig obscure diese Fehlermeldung.

            Ich würde mal darauf tippen, dass Bar nicht als QML Property dienen kann.
            Versuche es als QVariant mit der QVariant::fromValue(mBar) als return Wert der getter Funktion


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            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