asvil
29th July 2010, 20:39
Qt Script template is a CMake project to create your classes 'scriptable'. If you have library with some QObject or non-QObject based classes, it's the fatest way to create QtScript bindings.
First of all you need QtScriptGenerator (hereinafter QSG) from my repository:
git clone git://gitorious.org/~asvil/qt-labs/asvils-qtscriptgenerator.git qtscriptgenerator
cd qtscriptgenerator
Than make QSG:
cd generator
qmake
make
Optionally
Create Qt Modules bindings.
Execute QSG without parameters, than make plugin projects:
./generator
cd ../qtbindings
qmake && make
If you don't have all Qt modules, make subdirs particularly:
cd ../qtbindings/qtscript_core
qmake && make
#etc
After this manipulation, download qtscriptemplate:
git clone git://gitorious.org/qtscripttemplate/qtscripttemplate.git qtscripttemplate
cd qtscripttemplate
mkdir include
mkdir lib
Place your include files into 'include', your libraries into 'lib'.
Edit three files in 'buildplugin' subdirectory:
CMakeLists.txt
plugin_build.txt.in
plugin_typesystem.xml.in
In CMakeLists.txt replace uncomment two strings and print your plugin project names:
# Plugin file name
set (PROJECT YOUR_SCRIPT_PLUGIN_NAME)
# Extension name for method QScriptEngine::importExtension().
set (QS_PACKAGE_NAME YOUR_PACKAGE_NAME)
Add Qt Modules your library using in CMake project, for example:
set(QT_USE_QTNETWORK TRUE)
In plugin_build.txt.in uncomment Qt modules your library using.
Edit plugin_typesystem.xml.in (read more here (http://doc.qt.nokia.com/qtjambi-4.4/html/com/trolltech/qt/qtjambi-typesystem.html)):
For namecpaces add tag: <namespace-type name="YourNamespace"/>
For enums:
<enum-type name="Namespace::SomeEnum"/>
or
<enum-type name="SomeClass::SomeEnum"/>
For QObject based classes with Q_OBJECT macro:
<object-type name="QObjectSubclass"/>
For non-QObject based classes, haves copy constructor and assignment operator
<value-type name="NonQObjectClass"/>
Than make buildplugin/CMakeLists.txt with this commands, cmake called QSG to generate bindings for your classes:
cmake buildplugin -DCMAKE_BUILD_TYPE=Release
make
'plugins/script' is the output directory for plugin.
For some libraries created appropriate branch: log4qt, ncreport252, qserialdevice. By switching to these branches need only to copy the headers and the library itself.
Example:
git branch --track origin/qserialdevice
mkdir lib
mkdir include
.....................
# Copy qserialdevice library and headers
.....................
cmake biuldplugin -DCMAKE_BUILD_TYPE=Release
make
git branch --track origin/ncreport252
mkdir lib
mkdir include
.....................
# Copy ncreport >= 2.5.2 library and headers
.....................
cmake biuldplugin -DCMAKE_BUILD_TYPE=Release
make
First of all you need QtScriptGenerator (hereinafter QSG) from my repository:
git clone git://gitorious.org/~asvil/qt-labs/asvils-qtscriptgenerator.git qtscriptgenerator
cd qtscriptgenerator
Than make QSG:
cd generator
qmake
make
Optionally
Create Qt Modules bindings.
Execute QSG without parameters, than make plugin projects:
./generator
cd ../qtbindings
qmake && make
If you don't have all Qt modules, make subdirs particularly:
cd ../qtbindings/qtscript_core
qmake && make
#etc
After this manipulation, download qtscriptemplate:
git clone git://gitorious.org/qtscripttemplate/qtscripttemplate.git qtscripttemplate
cd qtscripttemplate
mkdir include
mkdir lib
Place your include files into 'include', your libraries into 'lib'.
Edit three files in 'buildplugin' subdirectory:
CMakeLists.txt
plugin_build.txt.in
plugin_typesystem.xml.in
In CMakeLists.txt replace uncomment two strings and print your plugin project names:
# Plugin file name
set (PROJECT YOUR_SCRIPT_PLUGIN_NAME)
# Extension name for method QScriptEngine::importExtension().
set (QS_PACKAGE_NAME YOUR_PACKAGE_NAME)
Add Qt Modules your library using in CMake project, for example:
set(QT_USE_QTNETWORK TRUE)
In plugin_build.txt.in uncomment Qt modules your library using.
Edit plugin_typesystem.xml.in (read more here (http://doc.qt.nokia.com/qtjambi-4.4/html/com/trolltech/qt/qtjambi-typesystem.html)):
For namecpaces add tag: <namespace-type name="YourNamespace"/>
For enums:
<enum-type name="Namespace::SomeEnum"/>
or
<enum-type name="SomeClass::SomeEnum"/>
For QObject based classes with Q_OBJECT macro:
<object-type name="QObjectSubclass"/>
For non-QObject based classes, haves copy constructor and assignment operator
<value-type name="NonQObjectClass"/>
Than make buildplugin/CMakeLists.txt with this commands, cmake called QSG to generate bindings for your classes:
cmake buildplugin -DCMAKE_BUILD_TYPE=Release
make
'plugins/script' is the output directory for plugin.
For some libraries created appropriate branch: log4qt, ncreport252, qserialdevice. By switching to these branches need only to copy the headers and the library itself.
Example:
git branch --track origin/qserialdevice
mkdir lib
mkdir include
.....................
# Copy qserialdevice library and headers
.....................
cmake biuldplugin -DCMAKE_BUILD_TYPE=Release
make
git branch --track origin/ncreport252
mkdir lib
mkdir include
.....................
# Copy ncreport >= 2.5.2 library and headers
.....................
cmake biuldplugin -DCMAKE_BUILD_TYPE=Release
make