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. Qt Signal parameters to script slot?
Forum Update on Monday, May 27th 2025

Qt Signal parameters to script slot?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 480 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.
  • S Offline
    S Offline
    SPlatten
    wrote on 15 Jun 2020, 08:05 last edited by SPlatten
    #1

    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

    J 2 Replies Last reply 15 Jun 2020, 08:07
    0
    • S SPlatten
      15 Jun 2020, 08:05

      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.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 15 Jun 2020, 08:13 last edited by
      #7

      @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
      2
      • S SPlatten
        15 Jun 2020, 08:05

        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.

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 15 Jun 2020, 08:07 last edited by
        #2

        @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
        0
        • S Offline
          S Offline
          SPlatten
          wrote on 15 Jun 2020, 08:08 last edited by
          #3

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

          Kind Regards,
          Sy

          J J 2 Replies Last reply 15 Jun 2020, 08:09
          0
          • S SPlatten
            15 Jun 2020, 08:08

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

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 15 Jun 2020, 08:09 last edited by
            #4

            @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
            1
            • S SPlatten
              15 Jun 2020, 08:08

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

              J Online
              J Online
              JonB
              wrote on 15 Jun 2020, 08:11 last edited by
              #5

              @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
              0
              • S Offline
                S Offline
                SPlatten
                wrote on 15 Jun 2020, 08:11 last edited by SPlatten
                #6

                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
                0
                • S SPlatten
                  15 Jun 2020, 08:05

                  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.

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 15 Jun 2020, 08:13 last edited by
                  #7

                  @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
                  2

                  1/7

                  15 Jun 2020, 08:05

                  • Login

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