summaryrefslogtreecommitdiffstats
path: root/examples/script/customclass
diff options
context:
space:
mode:
authorJason Barron <jbarron@trolltech.com>2009-08-04 08:33:52 (GMT)
committerJason Barron <jbarron@trolltech.com>2009-08-04 09:02:17 (GMT)
commit4aafbd6222e7aeafd59a4a4356ba8c53b2bfa1d1 (patch)
treeb34985c5716d98f01b9f36fd4a98f2ac9710099f /examples/script/customclass
parenta0df97c03f26a38af17a42fb44ad6910536c8857 (diff)
parent2076f150995e541308b1d8da936b3e12ab68b886 (diff)
downloadQt-4aafbd6222e7aeafd59a4a4356ba8c53b2bfa1d1.zip
Qt-4aafbd6222e7aeafd59a4a4356ba8c53b2bfa1d1.tar.gz
Qt-4aafbd6222e7aeafd59a4a4356ba8c53b2bfa1d1.tar.bz2
Merge commit 'qt/master-stable'
Conflicts: config.tests/unix/openssl/openssl.pri demos/embedded/embedded.pro examples/itemviews/chart/chart.pro examples/network/network.pro examples/painting/painterpaths/painterpaths.pro examples/threads/mandelbrot/mandelbrot.pro qmake/project.cpp src/3rdparty/libtiff/libtiff/tif_config.h src/corelib/arch/arch.pri src/corelib/global/qglobal.cpp src/corelib/kernel/kernel.pri src/corelib/kernel/qcore_unix_p.h src/corelib/kernel/qobject.cpp src/corelib/thread/qthread_unix.cpp src/corelib/tools/qsharedpointer_impl.h src/corelib/tools/tools.pri src/gui/kernel/qaction.h src/gui/kernel/qapplication.cpp src/gui/painting/qregion.h src/gui/widgets/qlineedit.cpp src/gui/widgets/qlineedit_p.h src/network/socket/qnativesocketengine_unix.cpp tests/auto/qdir/tst_qdir.cpp tests/auto/qdiriterator/tst_qdiriterator.cpp tests/auto/qhttp/qhttp.pro tests/auto/qline/qline.pro tests/auto/qnetworkreply/tst_qnetworkreply.cpp tests/auto/qresourceengine/qresourceengine.pro tests/auto/qsharedpointer/qsharedpointer.pro tests/auto/qstring/qstring.pro tests/auto/qtcpsocket/qtcpsocket.pro tests/auto/qtcpsocket/tst_qtcpsocket.cpp
Diffstat (limited to 'examples/script/customclass')
-rw-r--r--examples/script/customclass/bytearrayclass.cpp9
-rw-r--r--examples/script/customclass/main.cpp4
2 files changed, 10 insertions, 3 deletions
diff --git a/examples/script/customclass/bytearrayclass.cpp b/examples/script/customclass/bytearrayclass.cpp
index 81a0b8a..2044a16 100644
--- a/examples/script/customclass/bytearrayclass.cpp
+++ b/examples/script/customclass/bytearrayclass.cpp
@@ -100,7 +100,7 @@ ByteArrayClass::ByteArrayClass(QScriptEngine *engine)
QScriptValue global = engine->globalObject();
proto.setPrototype(global.property("Object").property("prototype"));
- ctor = engine->newFunction(construct);
+ ctor = engine->newFunction(construct, proto);
ctor.setData(qScriptValueFromValue(engine, this));
}
//! [0]
@@ -224,7 +224,10 @@ QScriptValue ByteArrayClass::construct(QScriptContext *ctx, QScriptEngine *)
ByteArrayClass *cls = qscriptvalue_cast<ByteArrayClass*>(ctx->callee().data());
if (!cls)
return QScriptValue();
- int size = ctx->argument(0).toInt32();
+ QScriptValue arg = ctx->argument(0);
+ if (arg.instanceOf(ctx->callee()))
+ return cls->newInstance(qscriptvalue_cast<QByteArray>(arg));
+ int size = arg.toInt32();
return cls->newInstance(size);
}
//! [2]
@@ -240,7 +243,7 @@ QScriptValue ByteArrayClass::toScriptValue(QScriptEngine *eng, const QByteArray
void ByteArrayClass::fromScriptValue(const QScriptValue &obj, QByteArray &ba)
{
- ba = qscriptvalue_cast<QByteArray>(obj.data());
+ ba = qvariant_cast<QByteArray>(obj.data().toVariant());
}
diff --git a/examples/script/customclass/main.cpp b/examples/script/customclass/main.cpp
index 05aefd5..3b98f5c 100644
--- a/examples/script/customclass/main.cpp
+++ b/examples/script/customclass/main.cpp
@@ -52,6 +52,7 @@ int main(int argc, char **argv)
eng.globalObject().setProperty("ByteArray", baClass->constructor());
qDebug() << "ba = new ByteArray(4):" << eng.evaluate("ba = new ByteArray(4)").toString();
+ qDebug() << "ba instanceof ByteArray:" << eng.evaluate("ba instanceof ByteArray").toBool();
qDebug() << "ba.length:" << eng.evaluate("ba.length").toNumber();
qDebug() << "ba[1] = 123; ba[1]:" << eng.evaluate("ba[1] = 123; ba[1]").toNumber();
qDebug() << "ba[7] = 224; ba.length:" << eng.evaluate("ba[7] = 224; ba.length").toNumber();
@@ -65,6 +66,9 @@ int main(int argc, char **argv)
qDebug() << "ba.toBase64().toLatin1String():" << eng.evaluate("b64.toLatin1String()").toString();
qDebug() << "ba.valueOf():" << eng.evaluate("ba.valueOf()").toString();
qDebug() << "ba.chop(2); ba.length:" << eng.evaluate("ba.chop(2); ba.length").toNumber();
+ qDebug() << "ba2 = new ByteArray(ba):" << eng.evaluate("ba2 = new ByteArray(ba)").toString();
+ qDebug() << "ba2.equals(ba):" << eng.evaluate("ba2.equals(ba)").toBool();
+ qDebug() << "ba2.equals(new ByteArray()):" << eng.evaluate("ba2.equals(new ByteArray())").toBool();
return 0;
}