Boolean in Qt Script



  • Hellow, how can i add boolean to script engine, i try:
    @bool isDegrees;
    QScriptValue scriptIsDegrees = scriptEngine.newObject(&isDegrees);@
    But i get this error:

    bq. Error 1 error C2664: QScriptValue QScriptEngine:: newObject (QScriptClass *, const QScriptValue &): can not convert parameter 1 from 'bool *' in 'QScriptClass *' c: \ Users \ ruzik \ Documents \ Visual Studio 2008 \ Projects \ RizekMath \ RizekMath \ Widges \ RCalculatorWidget \ RCalculatorWidget.cpp 37

    In advance thank you for your help!

    [edit : fixed formatting, Eddy]



  • Take another look at the "QScriptEngine::newObject()":http://doc.qt.nokia.com/4.7/qscriptengine.html#newObject-2 signature.



  • I dont find any information to solve problem, but i find way how can i do it:
    @ QScriptValue scriptIsDegrees(&scriptEngine,false);
    scriptEngine.globalObject().setProperty("isDegrees", scriptIsDegrees);@
    But why was my first way wrong?
    Please explain me more


  • Moderators

    bq. QScriptValue QScriptEngine:: newObject (QScriptClass *, const QScriptValue &): can not convert parameter 1 from ‘bool *’ in ‘QScriptClass *

    Meaning :
    There is no function in the QScriptEngine class which takes as it's first parameter a pointer to a boolean. The compiler tries to convert it to one of the existing signatures, but doesn't succeed.



  • I undrestund it, i cant understund how can i do right



  • I need to add bool value to script



  • Hu Ruzik,

    your first post had the bug, that you used a function, that wanted a QScriptClass pointer as first parameter:

    @
    QScriptEngine::newObject ( QScriptClass * scriptClass, const QScriptValue & data = QScriptValue() )
    @



  • Why when i write this:
    @QScriptValue scriptIsDegrees(&scriptEngine,isDegrees);@
    It is all right, but i dont find this constructor in assist



  • Perhaps this constructor is not documented, but in the header file, it exists:

    @
    QScriptValue();
    ~QScriptValue();
    QScriptValue(const QScriptValue &other);
    QScriptValue(QScriptEngine *engine, SpecialValue val);
    QScriptValue(QScriptEngine *engine, bool val);
    QScriptValue(QScriptEngine *engine, int val);
    QScriptValue(QScriptEngine *engine, uint val);
    QScriptValue(QScriptEngine *engine, qsreal val);
    QScriptValue(QScriptEngine *engine, const QString &val);
    @

    EDIT: I looked at the docs, these constructors are obsolete...



  • If i do it:
    @QScriptValue(QScriptEngine *engine, bool val);@
    I am add in script only variable not value, how can i add value



  • I need to do something like this
    @QScriptValue(QScriptEngine *engine, &bool val);@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.