English French [qt-devnet.developpez.com]

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

  1. #ifndef FOO_H
  2. #define FOO_H
  3.  
  4. #include <QtCore/QtCore>
  5.  
  6. class Math : public QObject
  7. {
  8.     Q_OBJECT
  9. public:
  10.     Math() {}
  11.     virtual ~Math() {}
  12.     int squared(int x);
  13. };
  14. #endif // FOO_H

libfoo/foo.cpp

  1. #include "foo.h"
  2.  
  3. int Math::squared(int x)
  4. {
  5.   return x * x;
  6. }

libfoo/foo.pro

  1. TEMPLATE = lib
  2. TARGET = foo
  3. DEPENDPATH += .
  4. INCLUDEPATH += .
  5. HEADERS += foo.h
  6. SOURCES += foo.cpp

To build the lib:

  1. $ cd libfoo
  2. $ qmake
  3. $ make

Categories:

  • PySide_Binding_Generation_Tutorial
  •