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. QScriptEngine and signal/slot processing
Forum Updated to NodeBB v4.3 + New Features

QScriptEngine and signal/slot processing

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 3.0k 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.
  • D Offline
    D Offline
    dvb0222
    wrote on 26 Feb 2014, 23:49 last edited by
    #1

    I have an application that processes long-running Qt scripts. The QScriptEngine runs in its own thread.

    The main thread in this application is an http REST server that processes remote status and control messages. The remote program may for example, download a new script, start or stop the script, etc.

    The script engine is extended by several QObjects added to the engine's global property.

    I have set a short event processing interval using QScriptEngine:: setProcessEventsInterval().

    A few things are not behaving as I would expect them to. I'm hoping to determine whether I have an incorrect understanding of how it should work or if I just have bugs in my code.

    One of the QObjects added to the engine context includes a QTcpServer. I have properties on the object which allow me to set the port and read the number of connections and bytes, and a slot that allows me to tell the server listen. The constructor of this object connects the newConnection signal to a slot on the same object, and in the new connection I set up a readyRead signal handler, typical QTcpSocket/QTcpServer stuff.

    I can set the properties and start the listener from a script as expected. The listener runs. I can telnet to the port and I get a connection. However it seems that the newConnection signal does not get serviced until the script stops. (I say this because I have a QDebug() statement in the new connection handler and the output appears when I stop the script.

    I guess the question I have is whether QScriptEngine has its own local event loop, enabling it to run correctly on a secondary thread. If not I suppose I can only have one interruptable scriptEngine in my application.

    Thanks in advance for any and all insights.I appreciate that the details of the ScriptEngine event processing is not exactly a mainstream Qt question.


    David Van Beveren
    Oak Park Technology Corp.
    Malibu, California
    vbdavid@gmail.com

    1 Reply Last reply
    0
    • C Offline
      C Offline
      code_fodder
      wrote on 27 Feb 2014, 09:16 last edited by
      #2

      It does sound like you have a "blocking" issue somewhere.
      I do not quite have a clear view of your code from your description, could you paste in some code snippets. It would help to see the following:

      Your thread generation (moveToThread, etc...) and startup.
      Your connections (slots and signals)

      Note: if you emit a signal to an object in another thread it will be queued by default, and it will not be actions until current "actions" in the pipe are finished - i.e. last in last out. So we have to be careful that the thread itself is not somehow blocking.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Pawan Pal
        wrote on 27 Feb 2014, 09:37 last edited by
        #3

        Hi
        Anyone have a Server Client project in GUI.

        Regards
        Pawan

        1 Reply Last reply
        0
        • C Offline
          C Offline
          code_fodder
          wrote on 27 Feb 2014, 11:45 last edited by
          #4

          @Pawan Pal ... umm, pretty sure that is not related to this question?? - make a new post (and maybe provide more details :o )

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dvb0222
            wrote on 27 Feb 2014, 18:27 last edited by
            #5

            Hi Code,

            Thanks for the reply.
            The thread creation and signal slot are all good. The question is whether the QScriptEngine has a real Qt event loop at its base (can run on any thread), or if it just process events on the main thread's event loop by calling the static processEvents() method periodically. It looks like the latter is the case.


            David Van Beveren
            Oak Park Technology Corp.
            Malibu, California
            vbdavid@gmail.com

            1 Reply Last reply
            0
            • C Offline
              C Offline
              code_fodder
              wrote on 3 Mar 2014, 09:27 last edited by
              #6

              Well, I have not used QScriptEngine specifically, but I see no reason that it can not run in its own thread just like all the other Qt objects (and therefore have its own event queue).

              Once you move the object containing / inheriting-from QScriptEngine into another thread then signals that are processed in this thread are seperated from the main thread... i.e. if the main thread is sleeping/blocked then the QScriptEngine thread can still be running.

              If you are not seeing this behavior, then there may be something wrong with the way that your object/thread is setup... (unless there is something different about QScriptEngine that I don't know about).

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Pawan Pal
                wrote on 5 Mar 2014, 06:27 last edited by
                #7

                how to take buffer to send the data in console

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  code_fodder
                  wrote on 5 Mar 2014, 07:17 last edited by
                  #8

                  Use the "signals and slots":http://qt-project.org/doc/qt-4.8/signalsandslots.html mechanism for passing data around :)

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Pawan Pal
                    wrote on 6 Mar 2014, 07:17 last edited by
                    #9

                    Hi

                    I am working serial port project.I want when i selected the text from combo box its not show the text editor, when i clicked the button the text are send to the console.

                    its possible.

                    Regards
                    Pawan

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      Pawan Pal
                      wrote on 10 Mar 2014, 10:04 last edited by
                      #10

                      how count the character in number and display.
                      this is my code. its not working.

                      void MainWindow::textcount()
                      {

                      string s;
                         cout << flush;
                         //ui->textEdit->toPlainText().count();
                         getline(cin,s);
                         const int size=s.length();
                         cout << text_count << size << endl;
                          text_count = ui->textEdit->toPlainText().length();
                         serial->write(text_count.data());
                      

                      }

                      Thanks
                      Pawan pal

                      1 Reply Last reply
                      0

                      1/10

                      26 Feb 2014, 23:49

                      • Login

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