PySide Binding Generation Tutorial: Module 1 Creating the foo library: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
'''English''' [http://qt-devnet.developpez.com/tutoriels/python/pyside/binding-shiboken/#LIII French] ''[qt-devnet.developpez.com]''
[[Category:LanguageBindings::PySide::Shiboken::PySide Binding Generation Tutorial]]<br />[toc align_right=&quot;yes&amp;quot; depth=&quot;3&amp;quot;]


* '''Note:''' this article is a member of the multipart [http://developer.qt.nokia.com/wiki/Category:LanguageBindings::PySide::Shiboken::PySide_Binding_Generation_Tutorial PySide Binding Generation Tutorial] ''[developer.qt.nokia.com]''
'''English''' &quot;French&amp;quot;:http://qt-devnet.developpez.com/tutoriels/python/pyside/binding-shiboken/#LIII


=Creating the foo library=
* '''Note:''' this article is a member of the multipart &quot;PySide Binding Generation Tutorial&amp;quot;: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.
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==
== 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.
There is only one class in this '''foo''' library plus a &lt;code&amp;gt;.pro&amp;lt;/code&amp;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.
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===
=== libfoo/foo.h ===
 
<code><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 /></code>


===libfoo/foo.cpp===
=== libfoo/foo.cpp ===


===libfoo/foo.pro===
<code><br />#include &quot;foo.h&amp;quot;


To build the lib:<br />
int Math::squared(int x)<br />{<br /> return x * x;<br />}<br /></code>


===Categories:===
=== libfoo/foo.pro ===


* [[:Category:LanguageBindings|LanguageBindings]]
<code><br />TEMPLATE = lib<br />TARGET = foo<br />DEPENDPATH ''= .<br />INCLUDEPATH''= .<br />HEADERS ''= foo.h<br />SOURCES''= foo.cpp<br /></code>
** [[:Category:LanguageBindings::PySide|PySide]]
* [[:Category:LanguageBindings::PySide::Shiboken|Shiboken]]


* [[:Category:LanguageBindings::PySide::Shiboken::PySide Binding Generation Tutorial|PySide_Binding_Generation_Tutorial]]
To build the lib:<br /><code><br />$ cd libfoo<br />$ qmake<br />$ make<br /></code>

Revision as of 09:42, 24 February 2015


[toc align_right="yes&quot; depth="3&quot;]

English "French&quot;: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 />