August 21, 2011

bunjee bunjee
Lab Rat
120 posts

Create a new QObject from QML scripts

 

Greetings,

I would like to do something like this from my QML script:

  1. onPressed: {
  2.     var item = new myQObject;
  3. }

I did the following in C++:
  1. qmlRegisterType<MyQObject>("Module", 1,0, "myQObject");

Have I missed something ?

4 replies

August 21, 2011

marcoB marcoB
Ant Farmer
167 posts

I think you should use something like:

  1. onPressed: {
  2.     Loader {
  3.        id: myLoader
  4.        MyQObject {
  5.            ...
  6.        }
  7. }

but of course use a capital letter for MyObject

August 21, 2011

marcoB marcoB
Ant Farmer
167 posts

I suggest you also to read this useful doc [developer.qt.nokia.com], it has been useful for me :)

August 22, 2011

mbrasser mbrasser
Ant Farmer
452 posts

Hi,

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

Regards,
Michael

August 29, 2011

bunjee bunjee
Lab Rat
120 posts

Thanks guys.

B.A.

 
  ‹‹ [SOLVED]How to add numbers inside a text element      Flicking one rectangle area should automatically flick another rectangle area, how ? ››

You must log in to post a reply. Not a member yet? Register here!