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. qmlRegisterType of class with no default constructor
Forum Updated to NodeBB v4.3 + New Features

qmlRegisterType of class with no default constructor

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 1.6k Views 1 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.
  • B Offline
    B Offline
    Babs
    wrote on 1 Jul 2019, 08:13 last edited by
    #1

    Hello. I'm working on a QML application. I try to expose my Class to QML, but at compilation i get errors linked to qmlRegisterType use.
    Here is my class constructor:

        explicit PowerSupplyControl(CanOpenNodeId nodeId,QObject *parent = nullptr);
    
    

    and the way i register it in my main:

        qmlRegisterType<PowerSupplyControl>("com.device",1,0,"CanDevice");
    

    My class inherit another custom one.
    Anyone can help?

    K 1 Reply Last reply 1 Jul 2019, 08:44
    0
    • G Offline
      G Offline
      GrecKo
      Qt Champions 2018
      wrote on 1 Jul 2019, 08:25 last edited by
      #2

      From Overview - QML and C++ Integration :

      Choosing the Correct Integration Method Between C++ and QML

      I guess what you need is one of the two at the bottom.

      1 Reply Last reply
      3
      • B Babs
        1 Jul 2019, 08:13

        Hello. I'm working on a QML application. I try to expose my Class to QML, but at compilation i get errors linked to qmlRegisterType use.
        Here is my class constructor:

            explicit PowerSupplyControl(CanOpenNodeId nodeId,QObject *parent = nullptr);
        
        

        and the way i register it in my main:

            qmlRegisterType<PowerSupplyControl>("com.device",1,0,"CanDevice");
        

        My class inherit another custom one.
        Anyone can help?

        K Offline
        K Offline
        KroMignon
        wrote on 1 Jul 2019, 08:44 last edited by
        #3

        @Babs As far as I known, to register a type with qmlRegisterType(), the class must:

        • be a subclass from QObject
        • have a default constructor, to enable QML engine to create an instance

        If you only want QML to be aware from class, for example to have access to enumeration, you can use qmlRegisterUncreatableType().

        Take a look at https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html fro more details.

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        B 1 Reply Last reply 1 Jul 2019, 10:26
        2
        • K KroMignon
          1 Jul 2019, 08:44

          @Babs As far as I known, to register a type with qmlRegisterType(), the class must:

          • be a subclass from QObject
          • have a default constructor, to enable QML engine to create an instance

          If you only want QML to be aware from class, for example to have access to enumeration, you can use qmlRegisterUncreatableType().

          Take a look at https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html fro more details.

          B Offline
          B Offline
          Babs
          wrote on 1 Jul 2019, 10:26 last edited by
          #4

          @KroMignon thank you. I did it successfully.

          1 Reply Last reply
          0

          1/4

          1 Jul 2019, 08:13

          • Login

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