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. Unable to assign [Type] to [Type] in QML
Forum Updated to NodeBB v4.3 + New Features

Unable to assign [Type] to [Type] in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 749 Views 2 Watching
  • 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.
  • Y Offline
    Y Offline
    yeehaw
    wrote on last edited by
    #1

    Hello,

    I have a QObject derived class MainViewModel. I register this class as follows Q_DECLARE_METATYPE(MainViewModel*);, inside a namespace named ViewModel.
    I also register the type so I can use it explicitily in QML:
    qmlRegisterUncreatableType<MainViewModel>(PROJECT_NAME, MAJOR_VERSION, MINOR_VERSION, "MainViewModel", UNCREATABLE_REASON);.

    In QML:
    readonly property MainViewModel model: _model // where _model is the propery passed to the QQmlEngineApplication.

    In the QML output, I get a warning:
    Unable to assign ViewModel::MainViewModel to ViewModel::MainViewModel.

    When I change the assign type to var such as:
    readonly property var model: _model

    Everything works as intended.

    Any idea on what's missing ?

    thanks

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Which Qt version? I think this should work in 5.15+

      (Z(:^

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yeehaw
        wrote on last edited by
        #3

        I'm using QT 5.15.2

        1 Reply Last reply
        0
        • R Offline
          R Offline
          riodoro
          wrote on last edited by
          #4
          This post is deleted!
          sierdzioS 1 Reply Last reply
          0
          • R riodoro

            This post is deleted!

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            @riodoro said in Unable to assign [Type] to [Type] in QML:

            hi,
            you can use only basic types in qml object properties.

            That's wrong. I'm using custom types since ages. As long as a type inherits from QObject, it can be used as property in QML.

            (Z(:^

            1 Reply Last reply
            2

            • Login

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