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. QQmlComponent initialization from C++
Forum Updated to NodeBB v4.3 + New Features

QQmlComponent initialization from C++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 4 Posters 440 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.
  • K Offline
    K Offline
    Kwan
    wrote on 16 Nov 2020, 09:45 last edited by
    #1

    i have an application which sets properties of Qml from C++, so far i was able to set property of any type. I am able to create QQmlComponent in C++ and set it to property.

    But first i need to initialize component with its properties. I can do that with create/beginCreate and set properties. But i cant change created QObject back to QQmlComponent, therefor i cant set it to givent Component type property.

    Is there some way how to conver QObject to QQmlComponent ? Or is there any other way to initialize QQmlComponent properties ?

    Example, of what i want to achiev in C++, how it looks in qml

    import QtQuick 2.3
    
    Loader {
        // property of type Component
        sourceComponent: Text {
        
            text: "property i want to intialize, this component can be in file"
        }
    }
    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mike Neuhaus
      wrote on 16 Nov 2020, 18:51 last edited by
      #2

      @Kwan said in QQmlComponent initialization from C++:

      QQmlComponent

      Not entirely sure if I understood you correctly, but take a look at subclassing QQmlParserStatus for your custom QObject (see: https://doc.qt.io/qt-5/qqmlparserstatus.html). You must implement both methods, but the one you are looking for should be "classBegin".

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fcarney
        wrote on 16 Nov 2020, 20:09 last edited by
        #3

        dynamic_cast

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GrecKo
          Qt Champions 2018
          wrote on 16 Nov 2020, 21:19 last edited by
          #4

          @Kwan said in QQmlComponent initialization from C++:

          i have an application which sets properties of Qml from C++

          That smells bad but ok.

          How are you creating your QQmlComponent? With urls/filename or bytearray data or in an other way?
          Anyway you could subclass QQmlComponent::beginCreate and set your properties there I believe.

          1 Reply Last reply
          0

          1/4

          16 Nov 2020, 09:45

          • 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