English (en) │
This interface is based on Qt 5 (Qt 5.6.2 is tested). For documentation, fixes and download, go to Qt Project (Installers at download 5.6.2). Lazarus with Qt5 interface (qt5-lcl) can be used on Windows 32/64, Linux x32/x64/arm, macOS x64 (Cocoa). Qt5 widgetsets have been available in Lazarus from 1.8 stable release.
Most current Linux distros have a suitable Qt5 in their standard repositories however, long term support releases have issues due to their age. Ubuntu 16.04 has QT5.5 that is too old and 18.04 ships a problematic version of libQt5Pas that needs to be replaced, see below.
There is a Q5Pas1.dll binary available.
no 64-bit version yet.
The build is based on MinGW, thus you want to use the MinGW Qt library (i.e. qt-opensource-windows-x86-mingw492-5.6.2.exe).
If you need to build cbindings project, you need MinGW. You can use MinGW from the Qt package (qt-opensource-windows-x86-mingw492-5.6.2.exe) - it's an optional component of Qt package installation.
Running and Deployment
The project needs to be deployed with Q5Pas1.dll.
For Qt5 .dlls that should be deployed, see Qt5 guides: https://doc.qt.io/qt-5/windows-deployment.html.
For MinGW based package the following set of DLLs would be required to run a single FORM project.
Those DLLs come with Qt5 package (can be found at C:\Qt\Qt5.6.2\5.6\mingw49_32\bin).
Builds based on MSVC rather than MinGW might have different set of (non Qt5) dlls required. Note that https://svn.freepascal.org/svn/lazarus/binaries/i386-win32/qt5/Qt5Pas1.dll is built against Qt5-5.6.2, but Qt5Pas1.dll can be used with any Qt5 > 5.6.2.
Lazarus "out of the box" on Linux uses and makes apps for GTK2. It is not marked as having a dependency on Qt5 so if you wish to make Qt5 apps or build a Qt5 version of Lazarus you probably will need to install libQt5Pas-dev, Using your distros repository:
- Fedora, Mageia - sudo dnf install qt5pas-devel <enter>
- Ubuntu, Debian - sudo apt install libqt5pas-dev <enter>
it will bring along the necessary Qt5 libraries as dependencies, typically about 50Meg on a system that has no existing Qt5 needs. If you wish to use a Qt5 version of Lazarus, build from source with a command like "make bigide LCL_PLATFORM=qt5 <enter>" but note the default GTK2 Lazarus is quite happy to build Qt5 apps for you.
From within Lazarus, to choose to build a Qt5 app, Projects->ProjectOptions->AdditionsandOverrides and click Set "LCLWidgetType", and select Qt5 for the current Build Mode. Better yet, add a special build mode for Qt5, maybe a release and debug.
Don't forget, when releasing your app, it should be marked as being dependent on libqt5pas1.
libqt5pas is a library that bridges between Qt5 and your Lazarus application. Newer distros (U20.04, Debian Buster etc) have working versions available in their repositories. Mark you application as dependent on libqt5pas1 and all will be OK. You, as a developer using Qt5 will also need libqt5pas-dev as mentioned above.
Using your distros repository -
- Fedora, Mageia - sudo dnf install qt5pas<enter>
- Ubuntu, Debian - sudo apt install libqt5pas1 <enter>
Note that some long term release distributions, ie Ubuntu 18.04 Debian Stretch and derivatives have an incompatible version of libqt5pas (even though it appears to have the same version number as later distros!). You will see an error message and a crash if your app uses TMemo. You should install the downloaded packages mentioned below or build your own new version of the library.
Qt5 on Ubuntu 18.4
As Ubuntu's LTS releases have a quite long support life you can run into problems with packages being just too old. Qt5 on Ubuntu 18.04 is a good example. It has a supported life into 2023 but the LibQt5Pas is too old to work with current Lazarus built Qt5 apps. You can build your own libQt5Pas following instructions in the Lazarus tree and here but an easier approach is to download a new ready built library as a deb ir rpm package from https://github.com/davidbannon/libqt5pas/releases/latest. You can install the library package 'over top' of the official Ubuntu one or instead in which case it will bring down the necessary official Qt5 packages as well. If you already have the official Ubuntu Qt5Pas-Dev package remove it first and install the equivalent -Dev package from the above repo (after installing the main libQt5Pas package).
Note 1 that these two deb packages are made for Ubuntu 18.04, they will not help at all on Ubuntu 16.04 as its main Qt5 libraries are too old. And the version of LibQt5Pas in the Ubuntu 19.10 and later repositories work fine as they are.
Note 2 Ubuntu will constantly overwrite this pair of updated packages via it's 'unattended update' tool. You must blacklist the packages to force the unattended update tool from undoing your good work.
If you wish to build your own library, what you need is in your Lazarus tree, bindings sources are located in lcl/interfaces/qt5/cbindings , to build it just follow README.txt. You will need the gcc development tools and a suitable Qt5 development environment. As you will probably have Qt4 installed as well, override it with (eg) qmake -qt=qt5; make <enter>. You should also probably edit Qt5Pas.pro to build a release version rather than debug,
- CONFIG += release
- CONFIG -= debug
The resulting library is about 3.5 Mbytes, the install process strips it down to 2.5 Mbytes.
Note that once built you can use that library in all (?) Qt5 installs (5.6 or greater) however, the libraries shipped with Ubuntu are not so portable.
Unfortunately, you cannot rely on the version number Ubuntu has stamped on their libQt5Pas to determine if it needs to be replaced or not. If you ship your application to Linux users, it is quite likely they are using one of the LTS Ubuntus and will strike this problem. Remember that U16.04 is supported by Ubuntu until 2021 but has an incompatible version of Qt5. U18.04 is supported for even longer but requires only the libqt5pas library fix as mentioned above. And some distros include the numeral '1' in the library's package name, some don't.
And, a further complication, as if we need that, if Ubuntu send you updated LibQt5* then you can expect it to break your libQt5Pas1 and libQt5Pas-dev.
Systems using Wayland
Some distributions us Wayland by default (eg the default Fedora with a GNOME desktop) and QT5 does not work with Wayland. You will receive a message like:
QSocketNotifier: Can only be used with threads started with QThread [FORMS.PP] ExceptionOccurred ....
Logout, from the login screen click the small gear symbol, select "GNOME on XOrg". Log back in again.
There is, apparently a Wayland plugin for Qt5, for the brave - https://wayland.freedesktop.org/qt5.html
On Linux, sometimes Qt5 apps will inherit the colours it uses from the Desktop/OS. However this does not always work and appears to be Distribution / Desktop dependent. With the current fad of Dark Themes, a more reliable approach is to use qt5ct.
Why Qt5 instead of GTK ?
Good question ! Most Linux Lazarus applications are built using the default GTK2. The various Linux distributions are delivering fewer and fewer GTK2 apps, generally 'upgrading' to GTK3. However, the Lazarus GTK3 interface still needs some work and its not ready for production systems yet. Until late 2019, this has not mattered much, GTK2 works fine. But Ubuntu19.10 does not have GTK2 libraries installed by default and Xfce has announced its next release will be GTK2 free, apparently many distributions are looking to drop GTK2 from their default kits. While you can still install GTK2, its pretty big....
Qt5 is an obvious solution, its already installed on disros like Fedora 30 plus, its a relatively lightweight addition to Ubuntu, only 48Meg compared with GTK2's 445Meg. If you mark your application dependent on libqt5pas then it will be installed at the same time, bringing along the other qt5 files if necessary. Manually installing libqt5pas with your package manager (as long as it resolves dependencies!) will also work.
Clearly, Qt based distributions, ones using Plasma or KDE as a desktop will require only libqt5pas.
The following steps have been tested with macOS 10.13.6 (High Sierra), Xcode command line tools 10.0.0 (no Xcode required), Lazarus 1.8.4 and minimum Qt 5.6.2 (Qt 5.12.xx works without problems too).
After installing Qt 5.6.2 (see above), open up a terminal window and run these commands (paths may vary):
export LazarusDir=/Developer/Lazarus export QtDir=~/Qt5.6.2 cd $LazarusDir/lcl/interfaces/qt5/cbindings export PATH=$QtDir/5.6/clang_64/bin:$PATH qmake
qmake fails with the following error:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
it does not mean that you have to install Xcode. See Qt without Xcode for a workaround and try running
qmake again. (The Xcode dependency seems to be fixed in Qt 5.9.4 or maybe earlier.)
Proceed the build process with the following commands:
make make install
It may be helpful to add symlinks to the Qt5Pas.framework and other *.framework files (so no modifications to the path are required):
cd /Library/Frameworks/ sudo ln -s $QtDir/5.6/clang_64/lib/*.framework .
Remember that Qt5 is 64 bit, so in Lazarus under Tools - Options - Environment, you need to change Compiler Executable from
/usr/local/bin/ppcx64 . With ppc386, you would later get the following errors when compiling your Lazarus projects:
Error: linker: Undefined symbols for architecture i386: Error: linker: "_QAbstractButton_click", referenced from: [...] ld: symbol(s) not found for architecture i386
Finally, create a new Lazarus project (or open an existing one), open Project - Project options - Compiler options - Additions and overrides, set
LCLWidgetType:=qt5 . You should now be able to compile your project with the Qt5 widget set.
See First Steps with Lazarus Qt5 interface for an example project for Win32, Win64, macOS (64 bit) and Linux (64 bit).
- Lazarus known issues (things that will never be fixed) - A list of interface compatibility issues
- Win32/64 Interface - The Windows API (formerly Win32 API) interface for Windows 95/98/Me/2000/XP/Vista/10, but not CE
- Windows CE Interface - For Pocket PC and Smartphones
- Carbon Interface - The Carbon 32 bit interface for macOS (deprecated; removed from macOS 10.15)
- Cocoa Interface - The Cocoa 64 bit interface for macOS
- Qt Interface - The Qt4 interface for Unixes, macOS, Windows, and Linux-based PDAs
- Qt5 Interface - The Qt5 interface for Unixes, macOS, Windows, and Linux-based PDAs
- GTK1 Interface - The gtk1 interface for Unixes, macOS (X11), Windows
- GTK2 Interface - The gtk2 interface for Unixes, macOS (X11), Windows
- GTK3 Interface - The gtk3 interface for Unixes, macOS (X11), Windows
- fpGUI Interface - Based on the fpGUI library, which is a cross-platform toolkit completely written in Object Pascal
- Custom Drawn Interface - A cross-platform LCL backend written completely in Object Pascal inside Lazarus. The Lazarus interface to Android.
Platform specific Tips
- Android Programming - For Android smartphones and tablets
- iPhone/iPod development - About using Objective Pascal to develop iOS applications
- FreeBSD Programming Tips - FreeBSD programming tips
- Linux Programming Tips - How to execute particular programming tasks in Linux
- macOS Programming Tips - Lazarus tips, useful tools, Unix commands, and more...
- WinCE Programming Tips - Using the telephone API, sending SMSes, and more...
- Windows Programming Tips - Desktop Windows programming tips
Interface Development Articles
- Carbon interface internals - If you want to help improving the Carbon interface
- Windows CE Development Notes - For Pocket PC and Smartphones
- Adding a new interface - How to add a new widget set interface
- LCL Defines - Choosing the right options to recompile LCL
- LCL Internals - Some info about the inner workings of the LCL
- Cocoa Internals - Some info about the inner workings of the Cocoa widgetset