[Qt-interest] JavaScript persistent execution context?

sherzod_ sherzod.l at mail.ru
Sun Oct 10 16:18:24 CEST 2010


Thanks a lot No'am.

I'll try to examine.

noam.rosenthal at nokia.com wrote:

> Hi Sherzod
> 
> Sounds to me like what you are looking for is the concept of activation
> object and a global object. In Webkit, when you execute scripts in a
> script tag, they are executed in an activation object that is always
> available.
> 
> To make objects persist, they have to be somehow connected to the global
> object.
> 
> If you want to emulate the behavior of QWebFrame, you should do something
> like
> 
> c++:
> scriptEngine->globalObject().setProperty("myObj", pointerToMyObject)
> 
> js:
> function myAlert()  {}
> myObj.jingleJingle.connect(myAlert);
> 
> I hope this answers your question - if not, please read and experiment
> with QScriptContext::activationObject and QScriptEngine::globalObject.
> 
> No'am
> ________________________________________
> From: qt-interest-bounces at trolltech.com
> [qt-interest-bounces at trolltech.com] On Behalf Of ext sherzod_
> [sherzod.l at mail.ru] Sent: Sunday, October 10, 2010 1:37 PM To:
> qt-interest at trolltech.com Subject: Re: [Qt-interest] JavaScript persistent
> execution context?
> 
> Hello No'am.
> 
> Thank you for reply.
> 
> No I don't use QWebFrame. I just want to emulate it's behaviour. To say
> more precisely some of the properties of it's behaviour. To say yet more
> precisely the persistent nature of QWebFrame's JS engine context.
> 
> For example let's take any JS code that consists of several functions and
> some main function as an entry point. I just want to connect some c++
> signal to any of these functions, for example to someNiceAlert(msg),
> signal is async and i don't know when it'll be emitted. If we place the
> following code into a QWebFrame's <script> element - it's ok. I can emit
> my signal whenever i want and it'll work, i'll see my nice alert. But the
> issue is to make it without using QWebFrame.
> 
> Why i don't use just something like qScriptConnect or mediate functions.
> Because i don't need all the code to be executed. Let's assume it's a
> library and i just want to use a function from it.
> 
> // --------------- js code ------------------------
> 
> function someFunc1()
> {
>         DoSomething();
> }
> 
> function someNiceAlert(msg)
> {
>         showIncredibleAlert(msg);
> }
> 
> function someFunc2()
> {
>         DoSomethingElse();
> }
> 
> function SomeFunc3()
>         DoSomethingThird();
> }
> 
> function init() // entry point
> {
>         someFunc1();
>         someFunc2();
> 
>         return true;
> }
> 
> init();
> 
> // ----------- end of js code --------------------
> 
> noam.rosenthal at nokia.com wrote:
> 
>> Hello Sherzod
>>
>> Is this in QWebFrame or in QtScript? Do you actually have a web-page? How
>> do you currently initialize your context? Can you post some
>> initialization C++ code here?
>>
>> In general I'm guessing that the answer to your problem would be to add
>> those functions to a global object, e.g. in webkit: instead of
>>
>> function wakeUp() { ... }
>>
>> write
>>
>> window.wakeUp = function() { ... };
>>
>> But I'm not sure I'm answering the right question...
>>
>> No'am
>>
>> ________________________________________
>> From: qt-interest-bounces at trolltech.com
>> [qt-interest-bounces at trolltech.com] On Behalf Of ext sherzod_
>> [sherzod.l at mail.ru] Sent: Wednesday, October 06, 2010 9:11 AM To:
>> qt-interest at trolltech.com Subject: [Qt-interest] JavaScript persistent
>> execution context?
>>
>> Hello.
>>
>> How do I create persistent JavaScript execution context. For example I
>> connect a function defined in JS code to a qt c++ signal. I need this
>> function to be called even after running out the JS code.
>>
>> In other words i need a signal-slot connection created in a script to
>> stay alive after leaving script context, and surely clear this context
>> maybe manually later.
>>
>> // --------------------------------------------------
>>         c++
>> // --------------------------------------------------
>> ...
>>
>> SomeQtObject: public QObject
>> {
>>         ...
>>
>>         signals:
>>                 void jingleJingle();
>>
>>         ...
>> };
>>
>>
>> // --------------------------------------------------
>>         javascript
>> // --------------------------------------------------
>>
>> ...
>>
>> function wakeUp()
>> {
>>         alert("wake up!");
>> }
>>
>> function run()
>> {
>>         // SomeQtObject injected as myObj
>>
>>         myObj.jingleJingle.connect(wakeUp);
>>         // need this connection after quitting this code
>> }
>>
>> run();
>>
>> // --------------------------------------------------
>>
>> Thanks.
>>
>> ps. QWebFrame is the example of such behaviour. Web pages script context
>> is persistent during livetime of it.
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list