PySide Binding Generation Tutorial: Module 1 Creating the foo library
[toc align_right="yes" depth="3"]
English "French":http://qt-devnet.developpez.com/tutoriels/python/pyside/binding-shiboken/#LIII
- Note: this article is a member of the multipart "PySide Binding Generation Tutorial":http://developer.qt.nokia.com/wiki/Category:LanguageBindings::PySide::Shiboken::PySide_Binding_Generation_Tutorial
Creating the foo library
This section presents the code and the build instructions for a very simple Qt-based library. The library will be used as the subject for this tutorial.
The Source Code
There is only one class in this foo library plus a <code>.pro</code> file which means that the build system used will be qmake based.
Save the files below in a directory called libfoo. Be aware that this directory will be referenced by the binding Makefile presented in a later section of this tutorial. If you want to use other names or paths, remember to change the binding Makefile accordingly. Blind copy’n’paste shortens your life.
libfoo/foo.h
<br />#ifndef FOO_H<br />#define FOO_H
#include <QtCore/QtCore&gt;
class Math : public QObject<br />{<br /> Q_OBJECT<br />public:<br /> Math() {}<br /> virtual ~Math() {}<br /> int squared(int x);<br />};<br />#endif // FOO_H<br />
libfoo/foo.cpp
<br />#include "foo.h&quot;
int Math::squared(int x)<br />{<br /> return x * x;<br />}<br />
libfoo/foo.pro
<br />TEMPLATE = lib<br />TARGET = foo<br />DEPENDPATH ''= .<br />INCLUDEPATH''= .<br />HEADERS ''= foo.h<br />SOURCES''= foo.cpp<br />
To build the lib:
<br />$ cd libfoo<br />$ qmake<br />$ make<br />