[Qt-interest] QScript question

"Alexander Carôt" alexander_carot at gmx.net
Mon Jun 27 22:24:45 CEST 2011


Hi all,

after a break I revisited working on the QScript problem (see below). For now
I very much simplified the case just to provide basic functionality: I have a
HTML-Button, which calls a Java-Script function via the onClick-handler. This
function simply executes an "alert" and also is supposed to set a value in my
Qt-Application. However, this again fails with the result that the java script function is not executed at all. I attached the HTML-file, the script file and my main-function, where the script is accessed. So - do I have to avoid *any* HTML -- even if the script is pure java script ?

Any help appreciated,
thanks a lot in advance and regards
 
Alex
 
 
> Von:  Rohan Prabhu <rohan at rohanprabhu.com>
> Datum:  Sat, 14 May 2011 03:20:33 +0530
> An:  Alexander Carôt <Alexander_Carot at gmx.net>
> Betreff:  Re: [Qt-interest] QScript question
> 
>> A few questions come up here. Your current script is valid JavaScript,
>> however, it expects an HTML DOM in it's environment. How are you providing
>> the 'document' object? Till now, I was thinking of a very generic slider
>> implemented NOT in HTML. I have answered this query countless times now, so
>> I'll just link you to one of my emails in which I made the same point:
>> http://lists.qt.nokia.com/pipermail/qt-interest/2011-March/032000.html
>> 
>> On Fri, May 13, 2011 at 7:05 PM, Alexander Carôt <Alexander_Carot at gmx.net>
>> wrote:
>>> Hi Rohan,
>>> 
>>> allright, it seems that my problem is related to the actual script I am
>>> using. Please find attached the slider implementation. In the lowest
>>> function (mouse up) in line 104 and 105 I have implemented the call to my
>>> Qt-Slot just in order to see if the functionality is there. For some
>>> reason this does not work: It actually makes the whole mouse up handler
>>> fail and does not change the Qt-Slider either.
>>> 
>>> Do you know why this is the case ?
>>> 
>>> Thanks in advance
>>> 
>>> Alex
>>> 
>>> --
>>> Alexander Carôt
>>> Email : Alexander at Carot.de
>>> Tel.: +49 (0)177 5719797
>>> 
>>> 
>>> 
>>> 
>>> 
>>> Am 13.05.11 06:36 schrieb "Rohan Prabhu" unter <rohan at rohanprabhu.com>:
>>> 
>>>> >Hi,
>>>> >Firstly, somehow make the QSlider you want to move available to the
>>>> >scripting system:
>>>> >
>>>> >QScriptEngine* engine;
>>>> >QSlider* slider;
>>>> >QScriptValue someScriptObject;
>>>> >
>>>> >QScriptValue slider = engine->newQObject(slider,
>>>> >QScriptEngine::ScriptOwnersip);
>>>> >someScriptObject.setProperty("myslider", slider);
>>>> >
>>>> >Now let's say you get this value in your script:
>>>> >
>>>> >var slider = someScriptObject.myslider;
>>>> >
>>>> >Then, you can make a call as simple as:
>>>> >
>>>> >slider.setValue(200);
>>>> >
>>>> >Although you are not specific how the JavaScript slider is implemented,
>>>> >I am assuming the framework (or custom implementation) lets you override
>>>> >something similar to an 'onchange' event handler. Within the event
>>>> >handler, just compute the relative position on the QSlider and make a
>>>> >function call. This QScriptEngine::newQObject makes every slot a
>>>> >function property, and that is what we're using here.
>>>> >
>>>> >Also, you could have a function like:
>>>> >
>>>> >QScriptValue moveSlider(QScriptContext* ctx, QScriptEngine* eng) {
>>>> >     if(!ctx->argument(0).isUndefined() && ctx->argument(0)->isNumber()) {
>>>> >         someSlider->setValue(ctx->argument(0)->toNumber());
>>>> >     }
>>>> >}
>>>> >
>>>> >and export it:
>>>> >
>>>> >engine->setProperty("sliderSet", engine->newFunction(moveSlider));
>>>> >
>>>> >Now, in your javascript's callback function, just make a call:
>>>> >
>>>> >sliderSet(100);
>>>> >
>>>> >to set the value of the QSlider. Here your function must implement it's
>>>> >own logic to obtain the value of the 'someSlider' variable.
>>>> >
>>>> >Regards,
>>>> >rohan
>>>> >
>>>> >On 05/12/2011 04:34 PM, "Alexander Carôt" wrote:
>>>>> >> Hello everybody,
>>>>> >>
>>>>> >> I have a general question concerning QScript:
>>>>> >>
>>>>> >> I succeed connecting C++ Object Signals to Script functions and passing
>>>>> >>values in this direction (via qScriptConnect etc.). However, so far I
>>>>> >>didn't get how to do it vice versa: When a script function is executed I
>>>>> >>want to access the slot of a C++ Object.
>>>>> >>
>>>>> >> The actual application is this: I am moving a Java-Script-Slider and I
>>>>> >>want a C++-Qt-Slider to follow this movement.
>>>>> >>
>>>>> >> Is this possible at all ?
>>>>> >>
>>>>> >> Any hint appreciated,
>>>>> >> thanks in adavance
>>>>> >>
>>>>> >> Alex
>>>>> >>
>>>>> >>
>>>> >
>>> 
>> 



-- 
http://www.carot.de
http://www.triologue.de
Email : Alexander at Carot.de
Tel.: +49 (0)177 5719797



NEU: FreePhone - kostenlos mobil telefonieren!			
Jetzt informieren: http://www.gmx.net/de/go/freephone
-------------- next part --------------
<html> 
<head>
<title>Title</title>
<script
    language="JavaScript" src="./setVolume.js">
</script>
</head>

<body>
  <input type="button" name="setData" onclick="setVolume()" value="set data"></input>
</body>
</html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setVolume.js
Type: application/x-javascript
Size: 98 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110627/352af713/attachment.js 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: application/octet-stream
Size: 1770 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110627/352af713/attachment.obj 


More information about the Qt-interest-old mailing list