I'm still looking for help on how to use QObject slots in JS, not as singleton. I'm still getting that parse error.
Are there any examples of QObjects being used in JS files (NOT QML! -- .import vs import )
Sent: Sunday, November 29, 2015 at 12:39 AM
From: "Jason H" <jh...@gmx.com>
To: "Jason H" <jh...@gmx.com>
Cc: "Jérôme Godbout" <jer...@bodycad.com>, interest <interest@qt-project.org>
Subject: Re: [Interest] Import C++ types to _javascript_
From: "Jason H" <jh...@gmx.com>
To: "Jason H" <jh...@gmx.com>
Cc: "Jérôme Godbout" <jer...@bodycad.com>, interest <interest@qt-project.org>
Subject: Re: [Interest] Import C++ types to _javascript_
Also note that I'm talking about _javascript_, not QML.
I'm not sure if it matters, but this is me trying to use a C++ class in a JS file, which is then imported into QML.
Sent: Sunday, November 29, 2015 at 12:33 AM
From: "Jason H" <jh...@gmx.com>
To: "Jason H" <jh...@gmx.com>
Cc: "Jérôme Godbout" <jer...@bodycad.com>, interest <interest@qt-project.org>
Subject: Re: [Interest] Import C++ types to _javascript_
From: "Jason H" <jh...@gmx.com>
To: "Jason H" <jh...@gmx.com>
Cc: "Jérôme Godbout" <jer...@bodycad.com>, interest <interest@qt-project.org>
Subject: Re: [Interest] Import C++ types to _javascript_
To add to that: I am currently doing:
var hash = new MyLib.Hash(); // Parse Error: TypeError: Type error
var result = hash.sha1('...')
Which should work as I understand it, without a singleton. But I get the error above.
Many thanks.
Sent: Saturday, November 28, 2015 at 11:58 PM
From: "Jason H" <jh...@gmx.com>
To: "Jérôme Godbout" <jer...@bodycad.com>
Cc: interest <interest@qt-project.org>
Subject: Re: [Interest] Import C++ types to _javascript_
From: "Jason H" <jh...@gmx.com>
To: "Jérôme Godbout" <jer...@bodycad.com>
Cc: interest <interest@qt-project.org>
Subject: Re: [Interest] Import C++ types to _javascript_
Thanks I;ll give that a shot, but what about a non-singleton? I think my code should be working now, and I doon't know why it isn't. How to I make an instance?
Sent: Saturday, November 28, 2015 at 7:03 PM
From: "Jérôme Godbout" <jer...@bodycad.com>
To: jh...@gmx.com
Cc: interest <interest@qt-project.org>
Subject: Re: [Interest] Import C++ types to _javascript_
From: "Jérôme Godbout" <jer...@bodycad.com>
To: jh...@gmx.com
Cc: interest <interest@qt-project.org>
Subject: Re: [Interest] Import C++ types to _javascript_
For cpp you can use http://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterSingletonType
put your function with Q_INVOKABLE or make it a slot.
Add your class to qml module.
Then you can call the singleton class function by importing your module.
MysingletonClass.myQInvokablefct()
This is new territory for me. Could you tell me what i need to do for both? In this case I can make a singleton, but in the future maybe I can't.
Many thanks.
-----Original message-----
Sent: Saturday, 28 November 2015 at 02:21:06
From: "Jérôme Godbout" <jer...@bodycad.com>
To: "Jason H" <jh...@gmx.com>
Subject: Re: [Interest] Import C++ types to _javascript_
If your object is not a singleton you will need to create an instance to call the function on that object. I suggestion you keep your staticfunction call into a singleton. So you don't need an instance.
On Nov 27, 2015, at 8:11 PM, Jason H <jh...@gmx.com> wrote:I just checked, it is a slot. I just feel like I'm missing something. Do I need to make a instance?var instance = new MyLib.Hash() ?var hash = instance.sha1("data")Sent: Friday, November 27, 2015 at 7:50 PMFrom: "Jérôme Godbout" <jer...@bodycad.com>To: "Jason H" <jh...@gmx.com>Cc: interest <interest@qt-project.org>Subject: Re: [Interest] Import C++ types to _javascript_Make sure your function is Q_INVOKABLE or is a slot. also take care .pragme library is not possible with _javascript_ and object from c++ accessOn Nov 27, 2015, at 7:43 PM, Jason H <jh...@gmx.com> wrote:Per http://doc.qt.io/qt-5/qtqml-_javascript_-imports.htmlI am trying to in a JS file, import a class I made and exposed to QML viahash.h:class Hash :public QObject {Q_OBJECT...QString sha1(QString str);}main():qmlRegisterType<Hash>("MyLib", 1, 0, "Hash");myfile.js:.import MyLib 1.0 as MyLibfunction myFunc(obj) {return MyLib.Hash.sha1(JSON.stringify(obj));}but what I get when I call it is:qml: Parse Error: TypeError: Property 'sha1' of object [object Object] is not a functionWhat am I doing wrong?JSON.Stringify-ing the MyLib or MyLib.Hash returns {}_______________________________________________Interest mailing listInterest@qt-project.orghttp://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest