Hi, On 20/11/2010, at 2:41 AM, ext ext-ivailo.il...@nokia.com wrote:
> Yes I've read that, but the strange thing is that Component is just global > object for the JS - just like Qt. Why I can access Qt and cannot Components? The name "Component" is bound by the presence of an import statement, whereas the "Qt" global object is always available. Currently ".pragma library" JS files don't have access to any import statements (and consequently the name bindings that go along with them). We'll fix this in the future. For now you'll have to use hardcoded integers :( Cheers, Aaron > In general the concept is great - I just would like to know what I can and > what I cannot do and access from within it. I think that sharing a static > constant inside a library will not break the library concept, right? - this > is just integer 1 > > Best Regards, > Ivo > ________________________________________ > From: Hansen Rene.1 (EXT-ProDataConsult/Berlin) > Sent: Friday, November 19, 2010 5:40 PM > To: Iliev Ivailo (EXT-ProData/Berlin) > Cc: qt-qml@trolltech.com > Subject: Re: [Qt-qml] JavaScript with .pragma library cannot see Component > object > > This is because when you include .pragma, you are really indicating that > you want to create a stateless library. Here's an excerpt from the Docs > about integrating Javascript: > >>>> > Stateless JavaScript libraries > Some JavaScript files act more like libraries - they provide a set of > stateless helper functions that take input and compute output, but never > manipulate QML component instances directly. > > As it would be wasteful for each QML component instance to have a unique > copy of these libraries, the JavaScript programmer can indicate a > particular file is a stateless library through the use of a pragma, as > shown in the following example. > > // factorial.js > .pragma library > > function factorial(a) { > a = parseInt(a); > if (a <= 0) > return 1; > else > return a * factorial(a - 1); > } > > The pragma declaration must appear before any JavaScript code excluding > comments. > > As they are shared, stateless library files cannot access QML component > instance objects or properties directly, although QML values can be > passed as function parameters. > <<< > > Hope this helps. > > /René > > On Fri, 2010-11-19 at 16:17 +0000, ext ext-ivailo.il...@nokia.com wrote: >> Hi, >> >> I'm trying to create JS library with QML. As written in the documentation I >> write in the beginning of the JS file .pragra library >> everything is ok - now my library is not stuck to one QML file and I can >> everything is ok >> >> the problem is that I cannot see Component.Ready and Component - it's not >> null, but I have error directly when I want to access it : >> ReferenceError: Can't find variable: Component. >> >> if I remove the .pragma library then everything is ok - I can see Component >> and Comonent.Ready >> >> My question is: >> >> Is it done on purpose? Is there any reason why I cannot use / and see / >> those objects in the library is "object". Just a quick tip - Qt object is >> there - I can see it with or without marking my JS as library. >> >> For now I can just "wrap" the error - as Component.Ready is 1 - I will just >> replace it with 1, but it will be nice if I know what else I can and cannot >> do with libraries and not. >> >> Best Regards, >> Ivo >> _______________________________________________ >> Qt-qml mailing list >> Qt-qml@trolltech.com >> http://lists.trolltech.com/mailman/listinfo/qt-qml > > > > _______________________________________________ > Qt-qml mailing list > Qt-qml@trolltech.com > http://lists.trolltech.com/mailman/listinfo/qt-qml _______________________________________________ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml