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
(Change category "LanguageBindings::PySide::Shiboken::PySide Binding Generation Tutorial" -> "PySide")
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:LanguageBindings::PySide::Shiboken::PySide Binding Generation Tutorial]]<br />[toc align_right=&quot;yes&amp;quot; depth=&quot;3&amp;quot;]


'''English''' &quot;French&amp;quot;:http://qt-devnet.developpez.com/tutoriels/python/pyside/binding-shiboken/#LIII


* '''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
[[Category:PySide]]
 
 
'''English''' [http://qt-devnet.developpez.com/tutoriels/python/pyside/binding-shiboken/#LIII French]
 
* '''Note:''' this article is a member of the multipart [https://wiki.qt.io/PySide_Binding_Generation_Tutorial PySide Binding Generation Tutorial]


= Creating the foo library =
= Creating the foo library =
Line 11: Line 14:
== The Source Code ==
== The Source Code ==


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.
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.
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.
Line 17: Line 20:
=== libfoo/foo.h ===
=== libfoo/foo.h ===


<code><br />#ifndef FOO_H<br />#define FOO_H
<code>
#ifndef FOO_H
#define FOO_H


#include &lt;QtCore/QtCore&amp;gt;
#include <QtCore>


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>
class Math : public QObject
{
Q_OBJECT
public:
Math() {}
virtual ~Math() {}
int squared(int x);
};
#endif // FOO_H
</code>


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


<code><br />#include &quot;foo.h&amp;quot;
<code>
#include "foo.h"


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


=== libfoo/foo.pro ===
=== libfoo/foo.pro ===


<code><br />TEMPLATE = lib<br />TARGET = foo<br />DEPENDPATH ''= .<br />INCLUDEPATH''= .<br />HEADERS ''= foo.h<br />SOURCES''= foo.cpp<br /></code>
<code>
TEMPLATE = lib
TARGET = foo
DEPENDPATH += .
INCLUDEPATH+= .
HEADERS += foo.h
SOURCES+= foo.cpp
</code>


To build the lib:<br /><code><br />$ cd libfoo<br />$ qmake<br />$ make<br /></code>
To build the lib:
<code>
$ cd libfoo
$ qmake
$ make
</code>

Latest revision as of 05:06, 5 June 2016


English French

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

.pro

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

#ifndef FOO_H
#define FOO_H

#include <QtCore>

class Math : public QObject
{
 Q_OBJECT
public:
 Math() {}
 virtual ~Math() {}
 int squared(int x);
};
#endif // FOO_H

libfoo/foo.cpp

#include "foo.h"

int Math::squared(int x)
{
 return x * x;
}

libfoo/foo.pro

TEMPLATE = lib
TARGET = foo
DEPENDPATH += .
INCLUDEPATH+= .
HEADERS += foo.h
SOURCES+= foo.cpp

To build the lib:

$ cd libfoo
$ qmake
$ make