aboutsummaryrefslogtreecommitdiffstats
path: root/doc/tutorial/libfoo.rst
blob: 217577a4f4ac7766875b5a1930e85e60082da8ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
.. highlight:: cpp

.. _gentut-libfoo:

Creating the foo library
=========================

In this section is the code and build instructions for a very simple Qt4 based
library which will serve as a 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 Trolltech's **qmake**.

Put the files below in a directory called **libfoo**. Be aware that this
directory will be refered 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