[Qt-interest] QtScript, passing a var as a QString to a slot

Alexandre Beraud aberaud at infflux.com
Fri Mar 6 12:48:06 CET 2009


Hi,

Your function could return a QScriptValue being defined as an array:
    myReturnValue = myScriptEngine->newArray();
Then set whatever you want in the value as properties:
    myReturnValue.setProperty("return_message", "blah blah");
And then use it directly in the script:
/    var worked = a.MatrixAdd("b","d");
/The message being available through: worked["return_message"]

Best regards,

Alex



Jaco Naude a écrit :
> Hi there
>
> I hope that someone can point me in the right direction here. I'm new 
> to scripting with QtScript and I'm having some problems. I have the 
> following two slots:
>
> /Q_INVOKABLE bool MatrixAdd(const QString& variable_to_add, const 
> QString& new_name);/
> /Q_INVOKABLE bool MatrixSubtract(const QString& variable_to_subtract, 
> const QString& new_name, QString& result_string);/
>
> I execute the following script and it works fine:
> /var worked = a.MatrixAdd("b","d");/
>
> But I want to return information about what went wrong if the function 
> returned false. Thus I execute the following:
>
> /var result_string; /
>
> /var worked = a.MatrixSubtract("b","c", result_string);/
>
>
> and I get the following:
>
> /Script Error: TypeError: cannot call MatrixSubtract(): argument 3 has 
> unknown type `QString&' (register the type with 
> qScriptRegisterMetaType()) /
>
> /1, TypeError: cannot call MatrixSubtract(): argument 3 has unknown 
> type `QString&' (register the type with qScriptRegisterMetaType())/
>
>
> Should I rather make the result_string type a QScriptValue and convert 
> this to a string in my function? Or is there a way that I can leave 
> the slot as is and do something different in the code.
>
>
> Thanks in advance,
>
> Jaco
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>   


-- 
BERAUD Alexandre
Ingénieur Développement

Infflux - Informatique & Flux
Tel: 01 49 57 92 00 - Fax : 01 49 57 92 01
Mail: aberaud at infflux.com
Visitez notre site :  www.infflux.com





More information about the Qt-interest-old mailing list