C++ signal connection to script function



  • based on this "documentation":http://doc.qt.nokia.com/4.7-snapshot/scripting.html#using-signals-and-slots I'm trying to make an idea of how things work, however I found that when I want to connect a signal to a script function in C++ is not working. here is my code:

    @ QScriptEngine engine;
    QScriptValue handler = engine.evaluate("(function(text) { print('text was changed to', text); })");
    qScriptConnect(ui->lineEdit, SIGNAL(textChanged(const QString &)), QScriptValue(), handler);@

    I don't receive any error, it just doesn't work. I'm using Qt 4.7.3

    Can someone confirm that this is an error or not, so I can submit a bug.

    Thanks



  • You have to use a pointer for the QScriptEngine here, or the engine object will be destroyed at the end of the function where you put your code.



  • Thanks alexisdm. That works. Maybe they should update their documentation.



  • [quote author="2beers" date="1312706251"]Thanks alexisdm. That works. Maybe they should update their documentation.[/quote]
    Not really. Most of their examples are meant to be pasted into the main() function between QApplication app (argc, argv); and return app.exec ();.
    It's up to you to adapt them when you use them elsewhere.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.