[Qt-interest] QScript Newbie Question
"Alexander Carôt"
alexander_carot at gmx.net
Mon Feb 8 12:59:38 CET 2010
Hello Kent,
thanks for the reply ! However, my problem is possibly more "newby" than it appears: I am still on 4.5.3, where the "bracket"-problem doesn't exist. I simply wonder why my code actually does nothing:
I am connecting a line-edit-signal to the a script-slot as follows:
QScriptEngine engine;
QLineEdit *edit = new QLineEdit("",this);
edit->setGeometry(0,0,50,23);
edit->show();
QScriptValue handler = engine.evaluate("function (text){print('text was changed to',text);}");
qScriptConnect(edit, SIGNAL(textChanged(const QString &)), QScriptValue(), handler);
qDebug() << handler.toString();
but whenever I type anything into the edit field nothing happens. I am expecting the script to print the changed text into the terminal but neither a text output nor an error message appears. Nevertheless, the last qDebug-call plots the following into the terminal:
"function(text) {
print("text was changed to", text);
}"
Since these are my first steps with QScript I am still unsure how to verify this in order to achieve the desired script-print-action. Hence, any help appreciated of course.
Thanks a lot in advance
-- A l e x
-------- Original-Nachricht --------
> Datum: Mon, 08 Feb 2010 11:51:48 +0100
> Von: Kent Hansen <khansen at trolltech.com>
> An: qt-interest at trolltech.com
> Betreff: Re: [Qt-interest] QScript Newbie Question
> Alexander Carôt skrev:
> > Hi all,
> >
> > I just started using QScript and currently work with the sample code of
> the documentation. In that context I have a little problem with the
> following code:
> >
> > QScriptEngine eng;
> > QLineEdit *edit = new QLineEdit("",this);
> > QScriptValue handler = eng.evaluate("function(text) { print('text was
> changed to', text); }");
> > qScriptConnect(edit, SIGNAL(textChanged(const QString &)),
> QScriptValue(), handler);
> >
> > It compiles fine but whenever I change the text of the edit field
> nothing happens. So, my question is how I can verify the functionality that the
> signal reaches the script-slot ? So far I expected to have the terminal
> message "text was changed to ..." or am I mistaken ?
> >
> > Thanks in advance,
> > best
>
> Hi,
> This is due to a regression in 4.6 of the treatment of anonymous
> functions; http://bugreports.qt.nokia.com/browse/QTBUG-5757
> Adding parentheses around your function expression will make the parser
> understand it.
>
> Regards,
> Kent
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
--
Dr.-Ing. Alexander Carôt
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