Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Qt Signal parameters to script slot?

    General and Desktop
    3
    7
    110
    Loading More Posts
    • 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.
    • SPlatten
      SPlatten last edited by SPlatten

      I have a signal emitted in C++:

      void jsonTextChanged(QJsonObject objJSON);
      

      Here is the connection code:

      cnSignal = QObject::connect(this
                                 ,&clsQtTextEdit::jsonTextChanged
                                 ,[pobjScriptEng, strCall, strFile, strScript]() {
                                    QString strScriptWithCall = static_cast<QString>(strScript)
                                                              + static_cast<QString>(strCall) + "();";
                                    pobjScriptEng->evaluate(strScriptWithCall);
                                });
      

      What I want to achieve or learn is how to declare and pass on the parameter from the signal to the scripted slot? As presently it doesn't appear to make it to the slot.

      Kind Regards,
      Sy

      jsulm 2 Replies Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @SPlatten last edited by

        @SPlatten said in Qt Signal parameters to script slot?:

        ,pobjScriptEng, strCall, strFile, strScript {

        I think it should be

        ,[pobjScriptEng, strCall, strFile, strScript](QJsonObject objJSON){
        

        since your signal has a parameter.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 2
        • jsulm
          jsulm Lifetime Qt Champion @SPlatten last edited by

          @SPlatten said in Qt Signal parameters to script slot?:

          jsonSelectionChanged

          Shouldn't it be jsonTextChanged?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 0
          • SPlatten
            SPlatten last edited by

            Sorry, I copied and pasted the wrong code the first time round, corrected now.

            Kind Regards,
            Sy

            jsulm JonB 2 Replies Last reply Reply Quote 0
            • jsulm
              jsulm Lifetime Qt Champion @SPlatten last edited by

              @SPlatten Can you show how you emit the signal? Are you sure you actually emit it?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply Reply Quote 1
              • JonB
                JonB @SPlatten last edited by

                @SPlatten
                After answering @jsulm, please also qDebug() << strScriptWithCall in your lambda, else we don't know what is actually being sent....

                1 Reply Last reply Reply Quote 0
                • SPlatten
                  SPlatten last edited by SPlatten

                  Here is the slot that emits the signal:

                  void clsQtTextEdit::textChangedRptr() {
                      const char cszSignal[] = "jsonTextChanged";
                      QJsonObject objJSON(makeJSONresponse(cszSignal));
                      objJSON.insert(clsXMLnode::mscszAttrText, toPlainText());
                      clsXMLnode::updateSubscribed(mpobjNode, cszSignal, &objJSON);
                      emit jsonTextChanged(objJSON);
                  }
                  

                  This slot is connected internally in the class to the textChanged signal:

                  cnSignal = QObject::connect(this, QOverload<>::of(&clsQtTextEdit::textChanged) ,this, &clsQtTextEdit::textChangedRptr);
                  

                  In the body, strScript contains:

                  function setWin2Title() {
                      console.info("-----serWin2Title()-----");
                  
                      if ( typeof arguments == "object" && typeof arguments.length == "number" ) {
                          console.info(arguments.length);
                  	
                          if ( arguments.length > 0 ) {
                              for( var x in arguments ) {
                                  console.info(x);
                                  console.info(arguments[x]);
                              }
                          }
                      }
                  }
                  

                  Kind Regards,
                  Sy

                  1 Reply Last reply Reply Quote 0
                  • jsulm
                    jsulm Lifetime Qt Champion @SPlatten last edited by

                    @SPlatten said in Qt Signal parameters to script slot?:

                    ,pobjScriptEng, strCall, strFile, strScript {

                    I think it should be

                    ,[pobjScriptEng, strCall, strFile, strScript](QJsonObject objJSON){
                    

                    since your signal has a parameter.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply Reply Quote 2
                    • First post
                      Last post