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?

Qt Signal parameters to script slot?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 470 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on 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

    jsulmJ 2 Replies Last reply
    0
    • SPlattenS 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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      • SPlattenS 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.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on 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
        • SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #3

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

          Kind Regards,
          Sy

          jsulmJ JonBJ 2 Replies Last reply
          0
          • SPlattenS SPlatten

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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on 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
            • SPlattenS SPlatten

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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on 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
              • SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on 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
                • SPlattenS 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.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 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

                  • Login

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