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. Create new Element on demand

Create new Element on demand

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 1.6k 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.
  • S Offline
    S Offline
    Simplevolk
    wrote on last edited by
    #1

    Hello!
    Can i create new elements,such as Buttons,or element in List on demand? For example,if i receive a new data-i add new QML ListElement in my view?

    Thanks.

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

      Yes, you can use Loader element or instantiate QML objects from JS/ C++.

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Simplevolk
        wrote on last edited by
        #3

        Can you post some example? Or link to it?

        1 Reply Last reply
        0
        • U Offline
          U Offline
          utcenter
          wrote on last edited by
          #4

          From QML you can use the Qt.createQmlObject() method:

          @object Qt::createQmlObject(string qml, object parent, string filepath)@

          Like for example:

          @var newObject = Qt.createQmlObject('import QtQuick 2.0; Rectangle {color: "red"; width: 20; height: 20}', parentItem, "dynamicSnippet1");@

          From C++:

          @QQmlEngine *engine = new QQmlEngine;
          QQmlComponent component(engine, QUrl::fromLocalFile("main.qml"));
          QObject *myObject = component.create();@

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

            QML "Loader":http://qt-project.org/doc/qt-4.8/qml-loader.html element.

            "Dynamic object creation":http://qt-project.org/doc/qt-4.8/qml-qt.html#dynamic-object-creation in QML.

            (Z(:^

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Simplevolk
              wrote on last edited by
              #6

              Thanks for you answer!

              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