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 a new QObject from QML scripts

Create a new QObject from QML scripts

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 4.9k 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
    bunjee
    wrote on last edited by
    #1

    Greetings,

    I would like to do something like this from my QML script:
    @onPressed: {
    var item = new myQObject;
    }@
    I did the following in C++:
    @qmlRegisterType<MyQObject>("Module", 1,0, "myQObject");@
    Have I missed something ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      deimos
      wrote on last edited by
      #2

      I think you should use something like:

      @onPressed: {
      Loader {
      id: myLoader
      MyQObject {
      ...
      }
      }@

      but of course use a capital letter for MyObject

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deimos
        wrote on last edited by
        #3

        I suggest you also to read this useful "doc":http://developer.qt.nokia.com/doc/qt-4.7/qtbinding.html, it has been useful for me :)

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          Hi,

          The syntax you've shown isn't currently supported, but there are a few different ways to deal with dynamic objects in QML -- http://doc.qt.nokia.com/4.7-snapshot/qdeclarativedynamicobjects.html provides an overview.

          Regards,
          Michael

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bunjee
            wrote on last edited by
            #5

            Thanks guys.

            B.A.

            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