FPC and Qt: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: FPC and Qt
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Introduction | |
| 2 | + | ||
| 3 | + | There are a number of Qt bindings available: | |
| 4 | + | ||
| 5 | + | ### Qt3 | |
| 6 | + | ||
| 7 | + | [A QtC based binding by Theo](http://www.theo.ch/kylix/Qt3pas.zip) | |
| 8 | + | ||
| 9 | + | [Another QtC based binding by Andreas](http://andy.jgknet.de/oss/qt/qt3forFPC/) | |
| 10 | + | ||
| 11 | + | The first one aims on linux/unix users while the second one is for win32. | |
| 12 | + | ||
| 13 | + | ### Qt/Embedded | |
| 14 | + | ||
| 15 | + | The FPC arm port and this [Qt/E binding](http://users.pandora.be/Jan.Van.hijfte/qtforfpc/qtedemo.html) allow graphical programming on devices such as the Zaurus | |
| 16 | + | ||
| 17 | + | ### Qt4 | |
| 18 | + | ||
| 19 | + | More recently a small [Qt4 Binding](http://users.pandora.be/Jan.Van.hijfte/qtforfpc/fpcqt4.html) is available. It does not depend on the obsolete QtC library. The [[Qt4 binding]] page will provide more information on how the binding works and how to use it. | |
| 20 | + | ||
| 21 | + | ## How it works | |
| 22 | + | ||
| 23 | + | FPC still can't use C++ classes natively so these interface units use the same scheme as e.g. the official C interface to Qt does: there are wrapper procedures written which export an procedural interface. This procedural interface is wrapped by an object pascal interface again to make usage easier. | |
| 24 | + | ||
| 25 | + | This might sound like an huge overhead but these wrapper are mainly necessary to hide name mangling differences so there shouldn't be a noticable speed decrease in real world applications. | |
| 26 | + | ||
| 27 | + | ## Example | |
| 28 | + | ||
| 29 | + | This piece of code is taken from the second package mentioned above. | |
| 30 | + | ||
| 31 | + | ``` pascal | |
| 32 | + | var | |
| 33 | + | app: QApplicationH; | |
| 34 | + | btn: QPushButtonH; | |
| 35 | + | begin | |
| 36 | + | // create static ( interfaced handled ) QApplicationH | |
| 37 | + | app := NewQApplicationH(ArgCount, ArgValues).get; | |
| 38 | + | // due to a bug in fpc 1.9.5 the WideString helper methods with default parameter are disabled | |
| 39 | + | //btn := NewQPushButtonH('Quit', nil).get; | |
| 40 | + | btn := NewQPushButtonH(qs('Quit').get, nil, nil).get; | |
| 41 | + | btn.setGeometry(100, 100, 300, 300); | |
| 42 | + | btn.show; | |
| 43 | + | // override the virtual eventFilter method of btn | |
| 44 | + | btn.OverrideHook.eventFilter := @TTest.MyEventFilter; | |
| 45 | + | // and install the btn as it's own eventFilter | |
| 46 | + | btn.installEventFilter(btn); | |
| 47 | + | // connect Qt signal to Qt slot | |
| 48 | + | QObjectH.connect(btn, SIGNAL('clicked()'), app, SLOT('quit()')); | |
| 49 | + | ... | |
| 50 | + | ``` | |
| 51 | + | ||
| 52 | + | If you know how Qt is used in C++, you can see that there is not much difference. | |
| 53 | + | ||
| 54 | + | --- | |
| 55 | + | *From the Free Pascal wiki, page "FPC and Qt", as it stood on 2020-02-16 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
