PySide Binding Generation Tutorial: Module 1 Creating the foo library

From Qt Wiki
Revision as of 09:42, 24 February 2015 by Maintenance script (talk | contribs)
Jump to navigation Jump to search


[toc align_right="yes" depth="3"]

English "French":http://qt-devnet.developpez.com/tutoriels/python/pyside/binding-shiboken/#LIII

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&gt;.pro&lt;/code&gt; 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 &lt;QtCore/QtCore&amp;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 &quot;foo.h&amp;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 />