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. [SOLVED] Define Object Types using QML from C++?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Define Object Types using QML from C++?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 1.4k 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.
  • J Offline
    J Offline
    JohnAC
    wrote on last edited by
    #1

    How can I register/define an object type from a string of QML in C++ not from JavaScript?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevenceuppens
      wrote on last edited by
      #2

      Hi John,

      Can you make your question more clear?

      Steven CEUPPENS
      Developer / Architect
      Mobile: +32 479 65 93 10

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JohnAC
        wrote on last edited by
        #3

        I have a QML document as a string in C++. I'd like to make this QML document available to other QML documents being drawn to the display in a similar fashion to the Button examples in the documentation here http://qt-project.org/doc/qt-5/qtqml-documents-definetypes.html.

        Instead of a SquareButton.qml I have the QML markup stored in a string.

        Edit: My current thinking is to use rcc at runtime to generate a .rcc file that can be loaded with QResource at runtime.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xander84
          wrote on last edited by
          #4

          In QML you can use "Qt.createQmlObject":http://qt-project.org/doc/qt-5/qtqml-javascript-dynamicobjectcreation.html#creating-an-object-from-a-string-of-qml
          if you want to use c++ there might be a c++ counterpart of that function?
          maybe you can simply use "QJSEngine::evaluate":http://qt-project.org/doc/qt-5/qjsengine.html#evaluate or check the code what Qt.createQmlObject does under the hood. A simple solution you can just send the string to QML and use Qt.createQmlObject, but that might not be the best way if you already have the string in c++ :D

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

            @
            QQmlEngine engine;
            QQmlComponent component(&engine);
            component.setData("import QtQuick 2.0\nText { text: "Hello world!" }", QUrl());
            QQuickItem *item = qobject_cast<QQuickItem *>(component.create());

            //add item to view, etc
            ...
            @

            Steven CEUPPENS
            Developer &#x2F; Architect
            Mobile: +32 479 65 93 10

            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