Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. C++ signal connection to script function
Forum Updated to NodeBB v4.3 + New Features

C++ signal connection to script function

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 2 Offline
    2 Offline
    2beers
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexisdm
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • 2 Offline
        2 Offline
        2beers
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alexisdm
          wrote on last edited by
          #4

          [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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved