[Qt-interest] basic QScript question

"Alexander Carôt" alexander_carot at gmx.net
Thu Jul 1 12:14:30 CEST 2010


> Because your "handler" object gets destroyed when sliderC class
> constructor finishes its work (before the application enters the event loop)?

Thanks for the guess but if that was true it would imply that any other object is destroyed after having passed the constructor - which is obviously not the case.

However, in the meantime I could figure where the problem was: When my custom class inherited from QScriptEngine it actually worked out. The question "why" still remains though.

Best

-- A l e x






 
> 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 at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest

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



GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01



More information about the Qt-interest-old mailing list