Default Conversion from Qt Script to C++

Parent Previous Next

Default Conversion from Qt Script to C++

http://doc.qt.nokia.com/4.4/qtscript.html#default-conversion-from-qt-script-to-c


C++ Type

Default Conversion

bool

QScriptValue::toBoolean()

int

QScriptValue::toInt32()

uint

QScriptValue::toUInt32()

float

float(QScriptValue::toNumber())

double

QScriptValue::toNumber()

short

short(QScriptValue::toInt32())

ushort

QScriptValue::toUInt16()

char

char(QScriptValue::toInt32())

uchar

unsigned char(QScriptValue::toInt32())

qlonglong

qlonglong(QScriptValue::toInteger())

qulonglong

qulonglong(QScriptValue::toInteger())

QString

QScriptValue::toString()

QDateTime

QScriptValue::toDateTime()

QDate

QScriptValue::toDateTime().date()

QRegExp

QScriptValue::toRegExp()

QObject*

QScriptValue::toQObject()

QWidget*

QScriptValue::toQObject()

QVariant

QScriptValue::toVariant()

QChar

If the QScriptValue is a string, the result is the first character of the string, or a null QChar if the string is empty; otherwise, the result is a QCharconstructed from the unicode obtained by converting the QScriptValue to a ushort.

QStringList

If the QScriptValue is an array, the result is a QStringList constructed from the result of QScriptValue::toString() for each array element; otherwise, the result is an empty QStringList.

QVariantList

If the QScriptValue is an array, the result is a QVariantList constructed from the result of QScriptValue::toVariant() for each array element; otherwise, the result is an empty QVariantList.

QVariantMap

If the QScriptValue is an object, the result is a QVariantMap with a (key, value) pair of the form (propertyName, propertyValue.toVariant()) for each property, using QScriptValueIterator to iterate over the object's properties.

QObjectList

If the QScriptValue is an array, the result is a QObjectList constructed from the result of QScriptValue::toQObject() for each array element; otherwise, the result is an empty QObjectList.

QList<int>

If the QScriptValue is an array, the result is a QList<int> constructed from the result of QScriptValue::toInt32() for each array element; otherwise, the result is an empty QList<int>.

Additionally, QtScript will handle the following cases:

Default Conversion from C++ to Qt Script

The following table describes the default behavior when a QScriptValue is constructed from a C++ type:

C++ Type

Default Construction

void

QScriptEngine::undefinedValue()

bool

QScriptValue(engine, value)

int

QScriptValue(engine, value)

uint

QScriptValue(engine, value)

float

QScriptValue(engine, value)

double

QScriptValue(engine, value)

short

QScriptValue(engine, value)

ushort

QScriptValue(engine, value)

char

QScriptValue(engine, value)

uchar

QScriptValue(engine, value)

QString

QScriptValue(engine, value)

qlonglong

QScriptValue(engine, qsreal(value)). Note that the conversion may lead to loss of precision, since not all 64-bit integers can be represented using the qsreal type.

qulonglong

QScriptValue(engine, qsreal(value)). Note that the conversion may lead to loss of precision, since not all 64-bit unsigned integers can be represented using the qsreal type.

QChar

QScriptValue(this, value.unicode())

QDateTime

QScriptEngine::newDate(value)

QDate

QScriptEngine::newDate(value)

QRegExp

QScriptEngine::newRegExp(value)

QObject*

QScriptEngine::newQObject(value)

QWidget*

QScriptEngine::newQObject(value)

QVariant

QScriptEngine::newVariant(value)

QStringList

A new script array (created with QScriptEngine::newArray()), whose elements are created using the QScriptValue(QScriptEngine *, QString) constructor for each element of the list.

QVariantList

A new script array (created with QScriptEngine::newArray()), whose elements are created using QScriptEngine::newVariant() for each element of the list.

QVariantMap

A new script object (created with QScriptEngine::newObject()), whose properties are initialized according to the (key, value) pairs of the map.

QObjectList

A new script array (created with QScriptEngine::newArray()), whose elements are created using QScriptEngine::newQObject() for each element of the list.

QList<int>

A new script array (created with QScriptEngine::newArray()), whose elements are created using the QScriptValue(QScriptEngine *, int) constructor for each element of the list.

Other types (including custom types) will be wrapped using QScriptEngine::newVariant(). For null pointers of any type, the result is QScriptEngine::nullValue().


Created with the Personal Edition of HelpNDoc: Easily create iPhone documentation