Qt Signal parameters to script slot?
-
wrote on 15 Jun 2020, 08:05 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.
-
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.
@SPlatten said in Qt Signal parameters to script slot?:
I think it should be
,[pobjScriptEng, strCall, strFile, strScript](QJsonObject objJSON){
since your signal has a parameter.
-
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.
@SPlatten said in Qt Signal parameters to script slot?:
jsonSelectionChanged
Shouldn't it be jsonTextChanged?
-
wrote on 15 Jun 2020, 08:08 last edited by
Sorry, I copied and pasted the wrong code the first time round, corrected now.
-
@SPlatten Can you show how you emit the signal? Are you sure you actually emit it?
-
wrote on 15 Jun 2020, 08:11 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]); } } } }
-
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.
@SPlatten said in Qt Signal parameters to script slot?:
I think it should be
,[pobjScriptEng, strCall, strFile, strScript](QJsonObject objJSON){
since your signal has a parameter.
1/7