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. Help with timer and JavaScript slot.

Help with timer and JavaScript slot.

Scheduled Pinned Locked Moved Solved General and Desktop
43 Posts 4 Posters 5.3k Views
  • 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.
  • K kshegunov
    30 Dec 2021, 08:38

    @SPlatten said in Help with timer and JavaScript slot.:

    I have a breakpoint in the lambda function, first line, it doesn't get triggered.

    I don't expect it to get trigerred, but again, this is not what I wrote. Here's a reminder:

    Put a breakpoint in clsMainWnd::ptmrGetTimer and confirm it gets triggered (the breakpoint).

    Additionally provide its source, and finally add this to the very beginning of the mentioned function:
    [snip]

    S Offline
    S Offline
    SPlatten
    wrote on 30 Dec 2021, 08:40 last edited by
    #20

    @kshegunov , here is there requested source to the function:

    /**
     * @brief clsMainWnd::ptmrGetTimer
     * @param crstrID : Constant reference to ID to look-up timer
     * @return A pointer to the timer or nullptr if not found
     */
    QTimer* clsMainWnd::ptmrGetTimer(const QString& crstrID) {
        mpTimers::iterator itTimer(mmpTimers.find(crstrID));
        QTimer* pTimer(nullptr);
        if ( itTimer != mmpTimers.end() ) {
            pTimer = itTimer->second;
        }
        return pTimer;
    }
    

    I put breakpoint on first line of this, it does what I expected, nullptr is returned because on the first call the timer hasn't been registered.

    Kind Regards,
    Sy

    S 1 Reply Last reply 30 Dec 2021, 08:51
    0
    • K kshegunov
      30 Dec 2021, 08:38

      @SPlatten said in Help with timer and JavaScript slot.:

      I have a breakpoint in the lambda function, first line, it doesn't get triggered.

      I don't expect it to get trigerred, but again, this is not what I wrote. Here's a reminder:

      Put a breakpoint in clsMainWnd::ptmrGetTimer and confirm it gets triggered (the breakpoint).

      Additionally provide its source, and finally add this to the very beginning of the mentioned function:
      [snip]

      S Offline
      S Offline
      SPlatten
      wrote on 30 Dec 2021, 08:45 last edited by
      #21

      @kshegunov , this is the modified source:

                  QThread* pobjCurrThread(QThread::currentThread());
          //Create new timer
      qdbg() << "Before Timer creation: " << pobjCurrThread;
                  ptmrScript = new QTimer(pobjCurrThread);
          //Register the new timer using the supplied ID
                  pAppInstance->registerTimer(ptmrScript, crstrID);
          //Add any globals to the script
                  clsScriptHelper::pobjGetInstance()->addGlobals(pobjScriptEng);
          //Build up script function call
                  QString strFile(slstScript[SFF_FILE_IDX])
                         ,strCall(slstScript[SSF_FUNCTION_IDX])
                         ,strScriptWithCall(strScript)
                         ,strFunc(strCall
                                + QString(clsDebugService::msccBrktOpen)
                                + QString(clsDebugService::msccBrktClose)
                                + QString(clsXMLnode::msccScriptFunctionTerminator));
                   if ( strScriptWithCall.endsWith(clsXMLnode::msccScriptFunctionTerminator) != true ) {
                       strScriptWithCall += clsXMLnode::msccScriptFunctionTerminator;
                   }
                   strScriptWithCall += strFunc;
          //Create connection to timer and script
      qdbg() << "Before QObject::connect: " << QThread::currentThread();
      

      And the resulting output in debug:

      Before Timer creation: QThread(0x60000026c140)
      S000000000029E000000010940T08:43:44.084W:QObject: Cannot create children for a parent that is in a different thread.
      (Parent is QThread(0x60000026c140), parent's thread is QThread(0x600000004180), current thread is QThread(0x60000026c140)
      S000000000030E000000010940T08:43:44.084DL00000661F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
      Before QObject::connect: QThread(0x60000026c140)
      

      Kind Regards,
      Sy

      1 Reply Last reply
      0
      • S SPlatten
        30 Dec 2021, 08:40

        @kshegunov , here is there requested source to the function:

        /**
         * @brief clsMainWnd::ptmrGetTimer
         * @param crstrID : Constant reference to ID to look-up timer
         * @return A pointer to the timer or nullptr if not found
         */
        QTimer* clsMainWnd::ptmrGetTimer(const QString& crstrID) {
            mpTimers::iterator itTimer(mmpTimers.find(crstrID));
            QTimer* pTimer(nullptr);
            if ( itTimer != mmpTimers.end() ) {
                pTimer = itTimer->second;
            }
            return pTimer;
        }
        

        I put breakpoint on first line of this, it does what I expected, nullptr is returned because on the first call the timer hasn't been registered.

        S Offline
        S Offline
        SPlatten
        wrote on 30 Dec 2021, 08:51 last edited by
        #22

        @SPlatten , I've reduced the source to just:

                    QJSEngine* pobjScriptEng(clsJSON::pobjGetScriptEng());
                    QThread* pobjCurrThread(QThread::currentThread());
            //Create new timer
        qdbg() << "Before Timer creation: " << pobjCurrThread;
                    ptmrScript = new QTimer(pobjCurrThread);
            //Create connection to timer and script
        qdbg() << "Before QObject::connect: " << QThread::currentThread();
        
        

        And the output is still:

        Before Timer creation: QThread(0x600000264a00)
        S000000000029E000000000768T08:50:01.847W:QObject: Cannot create children for a parent that is in a different thread.
        (Parent is QThread(0x600000264a00), parent's thread is QThread(0x6000000042c0), current thread is QThread(0x600000264a00)
        S000000000030E000000000768T08:50:01.847DL00000661F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
        Before QObject::connect: QThread(0x600000264a00)
        

        Kind Regards,
        Sy

        K 1 Reply Last reply 30 Dec 2021, 08:59
        0
        • K kshegunov
          30 Dec 2021, 08:38

          @SPlatten said in Help with timer and JavaScript slot.:

          I have a breakpoint in the lambda function, first line, it doesn't get triggered.

          I don't expect it to get trigerred, but again, this is not what I wrote. Here's a reminder:

          Put a breakpoint in clsMainWnd::ptmrGetTimer and confirm it gets triggered (the breakpoint).

          Additionally provide its source, and finally add this to the very beginning of the mentioned function:
          [snip]

          S Offline
          S Offline
          SPlatten
          wrote on 30 Dec 2021, 08:53 last edited by SPlatten
          #23

          @kshegunov , another attempt:

                      QThread* pobjCurrThread(QThread::currentThread());
              //Create new timer
          qdbg() << "Before Timer creation: " << pobjCurrThread;
                      ptmrScript = new QTimer;
                      ptmrScript->moveToThread(pobjCurrThread);
              //Create connection to timer and script
          qdbg() << "Before QObject::connect: " << QThread::currentThread();
          

          Output:

          Before Timer creation: QThread(0x600000264d00)
          S000000000029E000000000717T08:52:29.017DL00000662F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
          Before QObject::connect: QThread(0x600000264d00)
          

          Not seeing any errors in the debug, but execution isn't stopping in lambda either.

          Kind Regards,
          Sy

          1 Reply Last reply
          0
          • S SPlatten
            30 Dec 2021, 08:51

            @SPlatten , I've reduced the source to just:

                        QJSEngine* pobjScriptEng(clsJSON::pobjGetScriptEng());
                        QThread* pobjCurrThread(QThread::currentThread());
                //Create new timer
            qdbg() << "Before Timer creation: " << pobjCurrThread;
                        ptmrScript = new QTimer(pobjCurrThread);
                //Create connection to timer and script
            qdbg() << "Before QObject::connect: " << QThread::currentThread();
            
            

            And the output is still:

            Before Timer creation: QThread(0x600000264a00)
            S000000000029E000000000768T08:50:01.847W:QObject: Cannot create children for a parent that is in a different thread.
            (Parent is QThread(0x600000264a00), parent's thread is QThread(0x6000000042c0), current thread is QThread(0x600000264a00)
            S000000000030E000000000768T08:50:01.847DL00000661F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
            Before QObject::connect: QThread(0x600000264a00)
            
            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 30 Dec 2021, 08:59 last edited by
            #24

            Hold your horses! You have managed to confuse me about what's modified and what goes in which function. In any case in the last piece of code; after this:

            //Create new timer
            qdbg() << "Before Timer creation: " << pobjCurrThread;
                        ptmrScript = new QTimer(pobjCurrThread);
                //Register the new timer using the supplied ID
            

            adding

            Q_ASSERT(clsJSON::pobjGetScriptEng()->currentThread() == QThread::currentThread());
            

            should get tripped.

            PS.
            This does nothing:

            ptmrScript = new QTimer;
            ptmrScript->moveToThread(pobjCurrThread);
            

            Read and abide by the Qt Code of Conduct

            S 1 Reply Last reply 30 Dec 2021, 09:02
            1
            • K kshegunov
              30 Dec 2021, 08:59

              Hold your horses! You have managed to confuse me about what's modified and what goes in which function. In any case in the last piece of code; after this:

              //Create new timer
              qdbg() << "Before Timer creation: " << pobjCurrThread;
                          ptmrScript = new QTimer(pobjCurrThread);
                  //Register the new timer using the supplied ID
              

              adding

              Q_ASSERT(clsJSON::pobjGetScriptEng()->currentThread() == QThread::currentThread());
              

              should get tripped.

              PS.
              This does nothing:

              ptmrScript = new QTimer;
              ptmrScript->moveToThread(pobjCurrThread);
              
              S Offline
              S Offline
              SPlatten
              wrote on 30 Dec 2021, 09:02 last edited by
              #25

              @kshegunov said in Help with timer and JavaScript slot.:

              Q_ASSERT(clsJSON::pobjGetScriptEng()->currentThread() == QThread::currentThread());

              I cannot call currentThread() from pobjGetScriptEng(), it returns a pointer to QJSEngine.

              Kind Regards,
              Sy

              K 1 Reply Last reply 30 Dec 2021, 09:03
              0
              • S SPlatten
                30 Dec 2021, 09:02

                @kshegunov said in Help with timer and JavaScript slot.:

                Q_ASSERT(clsJSON::pobjGetScriptEng()->currentThread() == QThread::currentThread());

                I cannot call currentThread() from pobjGetScriptEng(), it returns a pointer to QJSEngine.

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 30 Dec 2021, 09:03 last edited by
                #26

                @SPlatten said in Help with timer and JavaScript slot.:

                I cannot call currentThread() from pobjGetScriptEng(), it returns a pointer to QJSEngine.

                Correct. I meant to write:

                Q_ASSERT(clsJSON::pobjGetScriptEng()->thread() == QThread::currentThread());
                

                Read and abide by the Qt Code of Conduct

                S 2 Replies Last reply 30 Dec 2021, 09:04
                0
                • K kshegunov
                  30 Dec 2021, 09:03

                  @SPlatten said in Help with timer and JavaScript slot.:

                  I cannot call currentThread() from pobjGetScriptEng(), it returns a pointer to QJSEngine.

                  Correct. I meant to write:

                  Q_ASSERT(clsJSON::pobjGetScriptEng()->thread() == QThread::currentThread());
                  
                  S Offline
                  S Offline
                  SPlatten
                  wrote on 30 Dec 2021, 09:04 last edited by
                  #27

                  @kshegunov , realised that after posting, modified output to:

                  qdbg() << "Script Eng Thread: " << pobjScriptEng->thread();
                  qdbg() << "Before Timer creation: " << pobjCurrThread;
                  

                  Result is:

                  S000000000028E000000000784T09:03:45.243DL00000642F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
                  Script Eng Thread: QThread(0x60000000c0d0)
                  S000000000029E000000000784T09:03:45.243DL00000643F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
                  Before Timer creation: QThread(0x60000026f260)
                  S000000000030E000000000784T09:03:45.243W:QObject: Cannot create children for a parent that is in a different thread.
                  (Parent is clsScriptHelper(0x600000208d80), parent's thread is QThread(0x60000000c0d0), current thread is QThread(0x60000026f260)
                  S000000000031E000000000784T09:03:45.244DL00000664F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
                  Before QObject::connect: QThread(0x60000026f260)
                  

                  Kind Regards,
                  Sy

                  K 1 Reply Last reply 30 Dec 2021, 09:13
                  0
                  • K kshegunov
                    30 Dec 2021, 09:03

                    @SPlatten said in Help with timer and JavaScript slot.:

                    I cannot call currentThread() from pobjGetScriptEng(), it returns a pointer to QJSEngine.

                    Correct. I meant to write:

                    Q_ASSERT(clsJSON::pobjGetScriptEng()->thread() == QThread::currentThread());
                    
                    S Offline
                    S Offline
                    SPlatten
                    wrote on 30 Dec 2021, 09:07 last edited by
                    #28

                    @kshegunov , have now changed code to:

                    ptmrScript = new QTimer(this);
                    ptmrScript->moveToThread(pobjScriptEngThread);
                    ptmrScript->setInterval(cuintInterval);
                    

                    Output is now different:

                    setupForm() !!!!
                    S000000000028E000000000716T09:06:20.132W:QObject: Cannot create children for a parent that is in a different thread.
                    (Parent is clsScriptHelper(0x600000202820), parent's thread is QThread(0x600000004150), current thread is QThread(0x60000025e1c0)
                    S000000000029E000000000716T09:06:20.132W:QObject::startTimer: Timers cannot be started from another thread
                    S000000000030E000000000716T09:06:20.132DL00000688F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
                    Is timer active: true
                    S000000000031E000000000716T09:06:20.132DL00000207Fsimon2.js[void clsScriptHelper::log]
                    setupForm() !!!!
                    

                    I will add another API function to allow the script to start the timer.

                    Kind Regards,
                    Sy

                    J 1 Reply Last reply 30 Dec 2021, 09:12
                    0
                    • S SPlatten
                      30 Dec 2021, 09:07

                      @kshegunov , have now changed code to:

                      ptmrScript = new QTimer(this);
                      ptmrScript->moveToThread(pobjScriptEngThread);
                      ptmrScript->setInterval(cuintInterval);
                      

                      Output is now different:

                      setupForm() !!!!
                      S000000000028E000000000716T09:06:20.132W:QObject: Cannot create children for a parent that is in a different thread.
                      (Parent is clsScriptHelper(0x600000202820), parent's thread is QThread(0x600000004150), current thread is QThread(0x60000025e1c0)
                      S000000000029E000000000716T09:06:20.132W:QObject::startTimer: Timers cannot be started from another thread
                      S000000000030E000000000716T09:06:20.132DL00000688F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
                      Is timer active: true
                      S000000000031E000000000716T09:06:20.132DL00000207Fsimon2.js[void clsScriptHelper::log]
                      setupForm() !!!!
                      

                      I will add another API function to allow the script to start the timer.

                      J Offline
                      J Offline
                      JonB
                      wrote on 30 Dec 2021, 09:12 last edited by JonB
                      #29

                      @SPlatten said in Help with timer and JavaScript slot.:

                      Cannot create children for a parent that is in a different thread.

                      You still have this. Excuse my complete guesswork, but do you need to go new QTimer(); rather than new QTimer(this); to move to another thread? (I have never been sure which statement causes the error message, which you can discover by stepping over or putting in qDebug() markers.)

                      But if all this is beyond me and being solved by @kshegunov please ignore me --- I'm just watching the discussion :)

                      1 Reply Last reply
                      0
                      • S SPlatten
                        30 Dec 2021, 09:04

                        @kshegunov , realised that after posting, modified output to:

                        qdbg() << "Script Eng Thread: " << pobjScriptEng->thread();
                        qdbg() << "Before Timer creation: " << pobjCurrThread;
                        

                        Result is:

                        S000000000028E000000000784T09:03:45.243DL00000642F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
                        Script Eng Thread: QThread(0x60000000c0d0)
                        S000000000029E000000000784T09:03:45.243DL00000643F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
                        Before Timer creation: QThread(0x60000026f260)
                        S000000000030E000000000784T09:03:45.243W:QObject: Cannot create children for a parent that is in a different thread.
                        (Parent is clsScriptHelper(0x600000208d80), parent's thread is QThread(0x60000000c0d0), current thread is QThread(0x60000026f260)
                        S000000000031E000000000784T09:03:45.244DL00000664F../clsScriptHelper.cpp[void clsScriptHelper::createTimer]
                        Before QObject::connect: QThread(0x60000026f260)
                        
                        K Offline
                        K Offline
                        kshegunov
                        Moderators
                        wrote on 30 Dec 2021, 09:13 last edited by kshegunov
                        #30

                        Right, so now comes the million bucks question(s):

                        Why is clsScriptHelper::createTimer called from thread different from the one pobjScriptEng has affinity for?
                        Why do you need to use threads to begin with?

                        As for the "solution":

                        QMetaObject::Connection cn = QObject::connect(ptmrScript
                                                                                 ,&QTimer::timeout
                        

                        Shall provide a context object for the execution. Looking at the body, I'd say it should be something like:

                        QMetaObject::Connection cn = QObject::connect(ptmrScript , &QTimer::timeout, pobjScriptEng
                                                                                 ,[pobjScriptEng
                                                                                  ,ptmrScript
                                                                                  ,strFile
                                                                                  ,strFunc
                                                                                  ,strScriptWithCall]() {
                        

                        Also the timer should be created with the correct affinity, I assume:

                        ptmrScript = new QTimer(pobjScriptEng);
                        

                        The original questions stand notwithstanding

                        PS: You have race conditions all over the place ...

                        Read and abide by the Qt Code of Conduct

                        S 2 Replies Last reply 30 Dec 2021, 09:15
                        0
                        • K kshegunov
                          30 Dec 2021, 09:13

                          Right, so now comes the million bucks question(s):

                          Why is clsScriptHelper::createTimer called from thread different from the one pobjScriptEng has affinity for?
                          Why do you need to use threads to begin with?

                          As for the "solution":

                          QMetaObject::Connection cn = QObject::connect(ptmrScript
                                                                                   ,&QTimer::timeout
                          

                          Shall provide a context object for the execution. Looking at the body, I'd say it should be something like:

                          QMetaObject::Connection cn = QObject::connect(ptmrScript , &QTimer::timeout, pobjScriptEng
                                                                                   ,[pobjScriptEng
                                                                                    ,ptmrScript
                                                                                    ,strFile
                                                                                    ,strFunc
                                                                                    ,strScriptWithCall]() {
                          

                          Also the timer should be created with the correct affinity, I assume:

                          ptmrScript = new QTimer(pobjScriptEng);
                          

                          The original questions stand notwithstanding

                          PS: You have race conditions all over the place ...

                          S Offline
                          S Offline
                          SPlatten
                          wrote on 30 Dec 2021, 09:15 last edited by
                          #31

                          @kshegunov , createTimer is called by JavaScript:

                          function setupForm() {
                          	//Query all people	  
                          	xmleng.log(0, "setupForm() !!!!", cstrThis, 202);
                          	//Create request counter property
                          	xmleng.setProperty(cstrFormTest, cstrStageCtr, "0");
                          	//Create timer to issue SQL requests
                          	xmleng.createTimer("t1", 50, "simon2.js@testTimer");
                          	xmleng.log(0, "setupForm() !!!!", cstrThis, 207);
                          	xmleng.startTimer("t1");
                          };
                          
                          

                          Kind Regards,
                          Sy

                          1 Reply Last reply
                          0
                          • K kshegunov
                            30 Dec 2021, 09:13

                            Right, so now comes the million bucks question(s):

                            Why is clsScriptHelper::createTimer called from thread different from the one pobjScriptEng has affinity for?
                            Why do you need to use threads to begin with?

                            As for the "solution":

                            QMetaObject::Connection cn = QObject::connect(ptmrScript
                                                                                     ,&QTimer::timeout
                            

                            Shall provide a context object for the execution. Looking at the body, I'd say it should be something like:

                            QMetaObject::Connection cn = QObject::connect(ptmrScript , &QTimer::timeout, pobjScriptEng
                                                                                     ,[pobjScriptEng
                                                                                      ,ptmrScript
                                                                                      ,strFile
                                                                                      ,strFunc
                                                                                      ,strScriptWithCall]() {
                            

                            Also the timer should be created with the correct affinity, I assume:

                            ptmrScript = new QTimer(pobjScriptEng);
                            

                            The original questions stand notwithstanding

                            PS: You have race conditions all over the place ...

                            S Offline
                            S Offline
                            SPlatten
                            wrote on 30 Dec 2021, 09:19 last edited by
                            #32

                            @kshegunov , I've modified my source to:

                             QMetaObject::Connection cn = QObject::connect(ptmrScript
                                                                          ,&QTimer::timeout
                                                                          ,pobjScriptEng
                                                                          ,[pobjScriptEng
                                                                           ,ptmrScript
                                                                           ,strFile
                                                                           ,strFunc
                                                                           ,strScriptWithCall]() {
                            

                            still getting:

                            S000000000027E000000000747T09:17:30.915DL00000202Fsimon2.js[void clsScriptHelper::log]
                            setupForm() !!!!
                            S000000000028E000000000747T09:17:30.915DL00000207Fsimon2.js[void clsScriptHelper::log]
                            setupForm() !!!!
                            S000000000029E000000000747T09:17:30.915W:QObject::startTimer: Timers cannot be started from another thread
                            

                            Kind Regards,
                            Sy

                            K 1 Reply Last reply 30 Dec 2021, 09:20
                            0
                            • S SPlatten
                              30 Dec 2021, 09:19

                              @kshegunov , I've modified my source to:

                               QMetaObject::Connection cn = QObject::connect(ptmrScript
                                                                            ,&QTimer::timeout
                                                                            ,pobjScriptEng
                                                                            ,[pobjScriptEng
                                                                             ,ptmrScript
                                                                             ,strFile
                                                                             ,strFunc
                                                                             ,strScriptWithCall]() {
                              

                              still getting:

                              S000000000027E000000000747T09:17:30.915DL00000202Fsimon2.js[void clsScriptHelper::log]
                              setupForm() !!!!
                              S000000000028E000000000747T09:17:30.915DL00000207Fsimon2.js[void clsScriptHelper::log]
                              setupForm() !!!!
                              S000000000029E000000000747T09:17:30.915W:QObject::startTimer: Timers cannot be started from another thread
                              
                              K Offline
                              K Offline
                              kshegunov
                              Moderators
                              wrote on 30 Dec 2021, 09:20 last edited by
                              #33

                              @SPlatten said in Help with timer and JavaScript slot.:

                              still getting

                              Did you also parent the timer to the QJSEngine?

                              Read and abide by the Qt Code of Conduct

                              S 1 Reply Last reply 30 Dec 2021, 09:21
                              0
                              • K kshegunov
                                30 Dec 2021, 09:20

                                @SPlatten said in Help with timer and JavaScript slot.:

                                still getting

                                Did you also parent the timer to the QJSEngine?

                                S Offline
                                S Offline
                                SPlatten
                                wrote on 30 Dec 2021, 09:21 last edited by SPlatten
                                #34

                                @kshegunov, this is how it is now:

                                QJSEngine* pobjScriptEng(clsJSON::pobjGetScriptEng());
                                QThread* pobjScriptEngThread(pobjScriptEng->thread());
                                //Create new timer
                                ptmrScript = new QTimer();
                                ptmrScript->moveToThread(pobjScriptEngThread);
                                ptmrScript->setInterval(cuintInterval);
                                

                                Have just modified to:

                                QJSEngine* pobjScriptEng(clsJSON::pobjGetScriptEng());
                                QThread* pobjScriptEngThread(pobjScriptEng->thread());
                                //Create new timer
                                ptmrScript = new QTimer();
                                ptmrScript->setParent(pobjScriptEng);
                                ptmrScript->moveToThread(pobjScriptEngThread);
                                ptmrScript->setInterval(cuintInterval);
                                

                                Output is still:

                                S000000000027E000000000743T09:24:17.520DL00000202Fsimon2.js[void clsScriptHelper::log]
                                setupForm() !!!!
                                S000000000028E000000000743T09:24:17.520W:QObject::setParent: Cannot set parent, new parent is in a different thread
                                S000000000029E000000000743T09:24:17.520DL00000207Fsimon2.js[void clsScriptHelper::log]
                                setupForm() !!!!
                                

                                Kind Regards,
                                Sy

                                J K KroMignonK 3 Replies Last reply 30 Dec 2021, 09:24
                                0
                                • S SPlatten
                                  30 Dec 2021, 09:21

                                  @kshegunov, this is how it is now:

                                  QJSEngine* pobjScriptEng(clsJSON::pobjGetScriptEng());
                                  QThread* pobjScriptEngThread(pobjScriptEng->thread());
                                  //Create new timer
                                  ptmrScript = new QTimer();
                                  ptmrScript->moveToThread(pobjScriptEngThread);
                                  ptmrScript->setInterval(cuintInterval);
                                  

                                  Have just modified to:

                                  QJSEngine* pobjScriptEng(clsJSON::pobjGetScriptEng());
                                  QThread* pobjScriptEngThread(pobjScriptEng->thread());
                                  //Create new timer
                                  ptmrScript = new QTimer();
                                  ptmrScript->setParent(pobjScriptEng);
                                  ptmrScript->moveToThread(pobjScriptEngThread);
                                  ptmrScript->setInterval(cuintInterval);
                                  

                                  Output is still:

                                  S000000000027E000000000743T09:24:17.520DL00000202Fsimon2.js[void clsScriptHelper::log]
                                  setupForm() !!!!
                                  S000000000028E000000000743T09:24:17.520W:QObject::setParent: Cannot set parent, new parent is in a different thread
                                  S000000000029E000000000743T09:24:17.520DL00000207Fsimon2.js[void clsScriptHelper::log]
                                  setupForm() !!!!
                                  
                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 30 Dec 2021, 09:24 last edited by
                                  #35

                                  @SPlatten
                                  Perhaps not relevant, but how can you go

                                              ptmrScript->moveToThread(pobjScriptEngThread);
                                              ptmrScript->setInterval(cuintInterval);
                                  

                                  Once moved to other thread, are you still allowed to set its interval from this (different) thread?

                                  1 Reply Last reply
                                  0
                                  • S SPlatten
                                    30 Dec 2021, 09:21

                                    @kshegunov, this is how it is now:

                                    QJSEngine* pobjScriptEng(clsJSON::pobjGetScriptEng());
                                    QThread* pobjScriptEngThread(pobjScriptEng->thread());
                                    //Create new timer
                                    ptmrScript = new QTimer();
                                    ptmrScript->moveToThread(pobjScriptEngThread);
                                    ptmrScript->setInterval(cuintInterval);
                                    

                                    Have just modified to:

                                    QJSEngine* pobjScriptEng(clsJSON::pobjGetScriptEng());
                                    QThread* pobjScriptEngThread(pobjScriptEng->thread());
                                    //Create new timer
                                    ptmrScript = new QTimer();
                                    ptmrScript->setParent(pobjScriptEng);
                                    ptmrScript->moveToThread(pobjScriptEngThread);
                                    ptmrScript->setInterval(cuintInterval);
                                    

                                    Output is still:

                                    S000000000027E000000000743T09:24:17.520DL00000202Fsimon2.js[void clsScriptHelper::log]
                                    setupForm() !!!!
                                    S000000000028E000000000743T09:24:17.520W:QObject::setParent: Cannot set parent, new parent is in a different thread
                                    S000000000029E000000000743T09:24:17.520DL00000207Fsimon2.js[void clsScriptHelper::log]
                                    setupForm() !!!!
                                    
                                    K Offline
                                    K Offline
                                    kshegunov
                                    Moderators
                                    wrote on 30 Dec 2021, 09:26 last edited by
                                    #36

                                    Okay, I'm getting really tangled. Where is QTimer::start called? In createTimer? If so, then:

                                    QTimer timer = new QTimer();
                                    ...
                                    // Connect the lambda with a context object, as mentioned!
                                    ...
                                    timer->start();
                                    

                                    Read and abide by the Qt Code of Conduct

                                    S 1 Reply Last reply 30 Dec 2021, 09:27
                                    0
                                    • K kshegunov
                                      30 Dec 2021, 09:26

                                      Okay, I'm getting really tangled. Where is QTimer::start called? In createTimer? If so, then:

                                      QTimer timer = new QTimer();
                                      ...
                                      // Connect the lambda with a context object, as mentioned!
                                      ...
                                      timer->start();
                                      
                                      S Offline
                                      S Offline
                                      SPlatten
                                      wrote on 30 Dec 2021, 09:27 last edited by
                                      #37

                                      @kshegunov , I'm trying lots of things without taking the time to think about it.

                                      Kind Regards,
                                      Sy

                                      K 1 Reply Last reply 30 Dec 2021, 09:30
                                      0
                                      • S SPlatten
                                        30 Dec 2021, 09:27

                                        @kshegunov , I'm trying lots of things without taking the time to think about it.

                                        K Offline
                                        K Offline
                                        kshegunov
                                        Moderators
                                        wrote on 30 Dec 2021, 09:30 last edited by
                                        #38

                                        @SPlatten said in Help with timer and JavaScript slot.:

                                        I'm trying lots of things without taking the time to think about it.

                                        Yes, do so. Which is the whole reason I requested the call stack. How am I supposed to guess what calls what ...

                                        Read and abide by the Qt Code of Conduct

                                        S 1 Reply Last reply 30 Dec 2021, 09:31
                                        0
                                        • K kshegunov
                                          30 Dec 2021, 09:30

                                          @SPlatten said in Help with timer and JavaScript slot.:

                                          I'm trying lots of things without taking the time to think about it.

                                          Yes, do so. Which is the whole reason I requested the call stack. How am I supposed to guess what calls what ...

                                          S Offline
                                          S Offline
                                          SPlatten
                                          wrote on 30 Dec 2021, 09:31 last edited by
                                          #39

                                          @kshegunov I would provide the call stack, but execution doesn't halt, so where would you like me to break to then get the stack?

                                          Kind Regards,
                                          Sy

                                          K 1 Reply Last reply 30 Dec 2021, 09:34
                                          0

                                          29/43

                                          30 Dec 2021, 09:12

                                          • Login

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