Announcing a new project on Trolltech Labs: Qt Script Generator. It’s a tool that generates Qt bindings for Qt Script. Finally your scripts can go “new QPoint()” without you having to manually bind the world first! You not only get the Qt API, but also the possibility to “subclass” in script code, e.g.:
var w = new QWidget();
w.keyPressEvent = function(e) { print(e.key()); }
w.paintEvent = function(e) { ... }
To use the bindings in your own app, you just compile the bindings plugins, put them in your library path and then go like this:
QScriptEngine eng;
eng.importExtension("qt.core");
eng.importExtension("qt.gui");
// also available: qt.sql, qt.xml, qt.svg, qt.network, qt.opengl
Have a look at the examples to get an idea of what you can do. More examples to come.
The generator itself is essentially the Qt Jambi generator with a Qt Script backend. (Great job, Jambi guys!)
Although this project is still very young, we’re interested in hearing about any issues (functionality / performance / whatever) you have with the bindings. Have fun!
No related posts.
19 comments
compile error on amd64
cd qtscript_core/ && /usr/local/qt-4.4/bin/qmake qtscript_core.pro -unix -o Makefile
cd qtscript_core/ && make -f Makefile
make[1]: Entering directory `/root/work/testqt/generator/qtbindings/qtscript_core’
make -f Makefile.Release
make[2]: Entering directory `/root/work/testqt/generator/qtbindings/qtscript_core’
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_SCRIPT_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/qt-4.4/mkspecs/linux-g++-64 -I. -I/usr/local/qt-4.4/include/QtCore -I/usr/local/qt-4.4/include/QtCore -I/usr/local/qt-4.4/include/QtGui -I/usr/local/qt-4.4/include/QtGui -I/usr/local/qt-4.4/include/QtScript -I/usr/local/qt-4.4/include/QtScript -I/usr/local/qt-4.4/include -I. -Irelease -I. -o release/main.o ../../generated_cpp/com_trolltech_qt_core/main.cpp
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_SCRIPT_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/qt-4.4/mkspecs/linux-g++-64 -I. -I/usr/local/qt-4.4/include/QtCore -I/usr/local/qt-4.4/include/QtCore -I/usr/local/qt-4.4/include/QtGui -I/usr/local/qt-4.4/include/QtGui -I/usr/local/qt-4.4/include/QtScript -I/usr/local/qt-4.4/include/QtScript -I/usr/local/qt-4.4/include -I. -Irelease -I. -o release/qtscript_QBitArray.o ../../generated_cpp/com_trolltech_qt_core/qtscript_QBitArray.cpp
../../generated_cpp/com_trolltech_qt_core/qtscript_QBitArray.cpp: In function ‘QScriptValue qtscript_QBitArray_toString(QScriptContext*, QScriptEngine*)’:
../../generated_cpp/com_trolltech_qt_core/qtscript_QBitArray.cpp:79: error: cast from ‘QBitArray*’ to ‘int’ loses precision
make[2]: *** [release/qtscript_QBitArray.o] Error 1
make[2]: Leaving directory `/root/work/testqt/generator/qtbindings/qtscript_core’
make[1]: *** [release] Error 2
make[1]: Leaving directory `/root/work/testqt/generator/qtbindings/qtscript_core’
make: *** [sub-qtscript_core-make_default] Error 2
Cool, so this would allow a completely self contained JS Qt project right?
Just import all of Qt and then start the script and there is no more need for C++.
Is there any provision for sandboxing, say if we have an app that runs scripts from remote sources, but doesn’t want the scripts to be able to access e.g. the file system?
taipan: Thanks for the report, should be fixed now.
Leo S: Yes.
Anon: Nothing yet. However, you’re free to remove e.g. the QFile and QDir constructors from the script engine after importing the bindings. We’re playing with offering more flexible/fine-grained ways of configuring the bindings though, will keep this in mind.
Why generator/qtbindings/qs_eval/main.cpp is null-size?
LestorN: It should be fine now.
Thanks, Kent. But I have more complex question. There is no QUiLoader mapping. May you add this or give simple howto. I try implement that this night in any case.
@LestorN you can fine a binding plugin that supports QUiLoader here http://websvn.kde.org/trunk/playground/bindings/qtscript/qtscriptplugins/uiutils/ hope that helps!
Since a JavaScript backend is possible, how hard would it be to create a backend for other languages, such as C#, PERL, Haskell, LISP, etc? Some of the lesser known of these languages could use a decent toolkit.
Hi, build or rather link problem on GCC 3.4.6 AMD64 with the svn revision 529:
make[1]: Entering directory `/home/mpalomas/prog/qt/generator/generator’
g++ -m64 -Wl,-rpath,/usr/local/src/qt-x11-commercial-src-4.3.4/lib -o generator release/ast.o release/lexer.o release/list.o release/parser.o release/smallobject.o release/control.o release/visitor.o release/default_visitor.o release/dumptree.o release/tokens.o release/binder.o release/codemodel.o release/type_compiler.o release/name_compiler.o release/declarator_compiler.o release/class_compiler.o release/codemodel_finder.o release/compiler_utils.o release/preprocessor.o release/generator.o release/main.o release/reporthandler.o release/typeparser.o release/typesystem.o release/asttoxml.o release/fileout.o release/generatorset.o release/metajava.o release/customtypes.o release/abstractmetabuilder.o release/abstractmetalang.o release/prigenerator.o release/generatorsetqtscript.o release/metaqtscriptbuilder.o release/metaqtscript.o release/classgenerator.o release/shellgenerator.o release/shellimplgenerator.o release/shellheadergenerator.o release/setupgenerator.o release/docgenerator.o release/moc_generator.o release/moc_fileout.o release/moc_generatorset.o release/moc_prigenerator.o release/moc_generatorsetqtscript.o release/moc_classgenerator.o release/moc_shellgenerator.o release/moc_shellimplgenerator.o release/moc_shellheadergenerator.o release/moc_setupgenerator.o release/qrc_generator.o -L/usr/local/src/qt-x11-commercial-src-4.3.4/lib -lQtXml -L/usr/local/src/qt-x11-commercial-src-4.3.4/lib -pthread -pthread -lQtCore -lz -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
`.gnu.linkonce.t._ZN3rpp24pp_skip_comment_or_divopclIPKcEET_S4_S4_’ referenced in section `.rodata’ of release/main.o: defined in discarded section `.gnu.linkonce.t._ZN3rpp24pp_skip_comment_or_divopclIPKcEET_S4_S4_’ of release/main.o
`.gnu.linkonce.t._ZN3rpp2pp4skipIPKcEET_S4_S4_’ referenced in section `.rodata’ of release/main.o: defined in discarded section `.gnu.linkonce.t._ZN3rpp2pp4skipIPKcEET_S4_S4_’ of release/main.o
Followed by a lot of similar errors. These seem to be link errors, maybe it happens only with GCC 3.4 64 bits, i have not tried to build the project in 32 bits or with GCC 4
I’m using KDE’s qt-copy from their SVN (http://websvn.kde.org/trunk/qt-copy/), and am getting this error at stage 3:
cd qtscript_core/ && make -f Makefile
make[1]: Entering directory `/storage/tmp/kde4dev/qtscript-bindings-generator/qtbindings/qtscript_core’
make -f Makefile.Debug
make[2]: Entering directory `/storage/tmp/kde4dev/qtscript-bindings-generator/qtbindings/qtscript_core’
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_SCRIPT_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../qt-unstable/mkspecs/linux-g++ -I. -I../../../qt-unstable/include/QtCore -I../../../qt-unstable/include/QtCore -I../../../qt-unstable/include/QtGui -I../../../qt-unstable/include/QtGui -I../../../qt-unstable/include/QtScript -I../../../qt-unstable/include/QtScript -I../../../qt-unstable/include -I. -Idebug -I. -o debug/qtscript_QThreadPool.o ../../generated_cpp/com_trolltech_qt_core/qtscript_QThreadPool.cpp
../../../qt-unstable/include/QtCore/qobject.h: In member function ‘void QObject::qt_check_for_QOBJECT_macro(const T&) const [with T = QThreadPool]’:
../../../qt-unstable/include/QtCore/qobject.h:434: instantiated from ‘T qobject_cast(QObject*) [with T = QThreadPool*]’
../../generated_cpp/com_trolltech_qt_core/qtscript_QThreadPool.cpp:180: instantiated from here
../../../qt-unstable/include/QtCore/qobject.h:117: error: void value not ignored as it ought to be
make[2]: *** [debug/qtscript_QThreadPool.o] Error 1
make[2]: Leaving directory `/storage/tmp/kde4dev/qtscript-bindings-generator/qtbindings/qtscript_core’
make[1]: *** [debug] Error 2
make[1]: Leaving directory `/storage/tmp/kde4dev/qtscript-bindings-generator/qtbindings/qtscript_core’
make: *** [sub-qtscript_core-make_default] Error 2
Any clue?
Palmic: those are gcc 3.4 incompatibilities with binutils. Upgrade one or downgrade the other. Not Qt problems — please talk to your distribution.
Anon: qt-copy is 4.4.0 beta 1 as long as you have not applied patches. If you have, please revert them and try again.
If the problem persists, please use a mailing list. Blogs aren’t support.
LestorN: The QUiLoader binding is present now.
Mike: Creating backends for other languages is certainly a possibility; I’d say it gets easier as we go along (first Java, then JavaScript, …), since we’re facing a lot of the same issues (with same/similar solutions) for each language we target.
I am using Qt 4.4 snapshot as of 17.3.2008 (from openSUSE BuildService; x86-64) and I encouter some issues: After I build the generator executable, it fails to generate the desired output, giving errors like
“type ‘QFrame’ is specified in typesystem, but not defined. This could potentially lead to compilation errors.”, although the INSTALL says something like “Run the generator executable without arguments”.
It may be that the real issue is the one with my /dev/hands, though, because I could not find similar problems.
Any idea what might be the cause here?
Dmitrij, I got similar errors and had to run it with an include-paths argument, like this:
./generator –include-paths=/usr/local/Trolltech/Qt-4.4.0-snapshot-20080308/include/
This is a great stuff! Keep developing…
Many warnings during generation (./generator) and after that the building phase of bindings fails:
../../../../qt-x11-opensource-src-4.4.0-beta1/include/QtCore/../../src/corelib/kernel/qobject.h: In member function ‘void QObject::qt_check_for_QOBJECT_macro(const T&) const [with T = QThreadPool]’:
../../../../qt-x11-opensource-src-4.4.0-beta1/include/QtCore/../../src/corelib/kernel/qobject.h:434: instantiated from ‘T qobject_cast(QObject*) [with T = QThreadPool*]’
../../generated_cpp/com_trolltech_qt_core/qtscript_QThreadPool.cpp:189: instantiated from here
../../../../qt-x11-opensource-src-4.4.0-beta1/include/QtCore/../../src/corelib/kernel/qobject.h:117: error: void value not ignored as it ought to be
make[2]: *** [release/qtscript_QThreadPool.o] Error 1
I have tried with QT 4.4 Beta and the latest snapshots so far, is there only certain snapshot which works or should I check my environment once again?
Thanks!
Comments on this entry are closed.