qt-interest@trolltech.com
[Top] [All Lists]

Re: [Qt-interest] basic QScript question

Subject: Re: [Qt-interest] basic QScript question
From: Constantin Makshin
Date: Thu, 1 Jul 2010 00:24:38 +0400
Because your "handler" object gets destroyed when sliderC class constructor 
finishes its work (before the application enters the event loop)?

On Wednesday 30 June 2010 22:54:28 Alexander Carôt wrote:
> Hello all,
> 
> I have basic understanding problem regarding QScript: In a simple example I 
> am dragging a QSlider, which in turn calls a QScript that plots the 
> respective fader position into the terminal.
> 
> The script looks like this:
> 
> (function give( value ){
>   print('Slider has value and returns:', value );
>   return value;
> })
> 
> and the respective main function looks like this:
> 
> ************
> int main( int argc, char* argv[] ){
>   QApplication app( argc, argv );
>   QWidget *GUI = new QWidget(); 
>   QSlider *slider = new QSlider();
>   QScriptEngine engine;
>   QString fileName = "translator.qs";
>   QFile scriptFile(fileName);
>   scriptFile.open(QIODevice::ReadOnly);
>   QTextStream stream(&scriptFile);
>   QString contents = stream.readAll();
>   scriptFile.close();
>   QScriptValue handler = engine.evaluate(contents,fileName);
>   qScriptConnect( slider, SIGNAL( valueChanged(int) ), QScriptValue(), 
> handler);
> }
> ***********
> 
> This works fine, however, when replacing the code from the main function into 
> a separated class the script is not called anymore:
> 
> 
> **********
> #include "sliderC.h"
> int main( int argc, char* argv[] ){
>   QApplication app( argc, argv );
> 
>   sliderC myScriptExample;
>  
>   return app.exec();
> }
> 
> #include "sliderC.h"
> sliderC::sliderC(){
>   QWidget *GUI = new QWidget(); 
>   QSlider *slider = new QSlider();
>   QScriptEngine engine;
>   QString fileName = "translator.qs";
>   QFile scriptFile(fileName);
>   scriptFile.open(QIODevice::ReadOnly);
>   QTextStream stream(&scriptFile);
>   QString contents = stream.readAll();
>   scriptFile.close();
>   QScriptValue handler = engine.evaluate(contents,fileName);
>   qScriptConnect( slider, SIGNAL( valueChanged(int) ), QScriptValue(), 
> handler);
> }
> ***********
> 
> Can anyone explain me why this is the case ? 
> 
> Thanks a lot in advance
> 
> -- A l e x
_______________________________________________
Qt-interest mailing list
Qt-interest@xxxxxxxxxxxxx
http://lists.trolltech.com/mailman/listinfo/qt-interest

<Prev in Thread] Current Thread [Next in Thread>