Nominate our 2022 Qt Champions!

C++ signal connection to script function

  • based on this "documentation": 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.


  • 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