diff options
Diffstat (limited to 'doc/tutorial/libfoo.rst')
-rw-r--r-- | doc/tutorial/libfoo.rst | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/doc/tutorial/libfoo.rst b/doc/tutorial/libfoo.rst new file mode 100644 index 000000000..bad6b014a --- /dev/null +++ b/doc/tutorial/libfoo.rst @@ -0,0 +1,69 @@ +.. highlight:: cpp + +.. _gentut-libfoo: + +Creating the foo library +========================= + +In this section it will be presented the code and the build instructions for a +very simple Qt4 based library. It will be used as the subject for this tutorial. + +The Source Code +--------------- + +There is only one class on this foo library plus a ``.pro`` file which means +that the build system used will be `qmake <http://doc.qt.nokia.com/4.6/qmake-manual.html>`_ +based. + +Put the files below in a directory called **libfoo**. Be aware that this +directory will be referred by the binding Makefile presented in a next section +of this tutorial. If you want to use other names or paths change the binding +Makefile accordingly. Blind copy'n'paste shortens your life. + +**libfoo/foo.h** +:: + + #ifndef FOO_H + #define FOO_H + + #include <QtCore/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 |