Difference between revisions of "Qt5 Interface"

From Free Pascal wiki
Jump to navigationJump to search
m (→‎Qt5 Colours: comment on qt5ct package on Debian)
(39 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 +
{{Qt5 Interface}}
 
{{Platform only|Qt|Qt|Qt5 widgetset}}
 
{{Platform only|Qt|Qt|Qt5 widgetset}}
  
 
== Introduction ==
 
== Introduction ==
This interface is based on Qt 5 (Qt 5.6.2 is tested). For documentation, fixes and download, go to [http://qt-project.org/ Qt Project] (Installers at [http://download.qt.io/archive/qt/5.6 download 5.6.2]). Lazarus with Qt5 interface (qt5-lcl) can be used on Windows 32/64, Linux x32/x64/arm, MacOSX x64(Cocoa). Qt5 widgetset is available from lazarus trunk 1.7 rev. 53806 and will be available in lazarus 1.8 stable release. There's no support for 32bit Qt5 binary versions from Digia, so if you need 32bit Qt5 on linux you must build complete Qt5 on your own, including libQt5Pas.
+
This interface is based on Qt 5 (Qt 5.6.2 is tested). For documentation, fixes and download, go to [http://qt-project.org/ Qt Project] (Installers at [https://download.qt.io/new_archive/qt/5.6/5.6.2/ 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 release versions such as Ubuntu 16.04 and Unbuntu 18.04 have an issue with their own libQt5Pas, wee below.
+
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.
  
 
==Windows==
 
==Windows==
There is Q5Pas1.dll binary available.
+
There is a ''Q5Pas1.dll'' binary available.  
*x86: https://svn.freepascal.org/svn/lazarus/binaries/i386-win32/qt5/Qt5Pas1.dll
+
 
 +
*x86: https://gitlab.com/freepascal.org/lazarus/binaries/-/raw/main/i386-win32/qt5/Qt5Pas1.dll?inline=false
 
no 64-bit version yet.
 
no 64-bit version yet.
  
The build is based on mingw, thus you want to use mingw Qt library (i.e. qt-opensource-windows-x86-mingw492-5.6.2.exe).
+
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 Qt package (qt-opensource-windows-x86-mingw492-5.6.2.exe) - it's an optional component of Qt package installation.
+
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===
 
===Running and Deployment===
The project needs to be deployed with '''Q5Pas1.dll'''.
+
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 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.
+
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 i.e. at C:\Qt\Qt5.6.2\5.6\mingw49_32\bin).
+
Those DLLs come with Qt5 package (can be found at C:\Qt\Qt5.6.2\5.6\mingw49_32\bin).
 
:Qt5Core.dll
 
:Qt5Core.dll
 
:Qt5PrintSupport.dll
 
:Qt5PrintSupport.dll
Line 32: Line 34:
 
:libgcc_s_dw2-1.dll
 
:libgcc_s_dw2-1.dll
  
Builds made base on MSVC rather than MingW might have different set of (non Qt5) dlls required.
+
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
+
Note that [https://gitlab.com/freepascal.org/lazarus/binaries/-/raw/main/i386-win32/qt5/Qt5Pas1.dll?inline=false Qt5Pas1.dll] is built against Qt5-5.6.2, but
 
Qt5Pas1.dll can be used with any Qt5 > 5.6.2.
 
Qt5Pas1.dll can be used with any Qt5 > 5.6.2.
  
 
==Linux==
 
==Linux==
 
===Lazarus===
 
===Lazarus===
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 may need to install Qt5 and will almost certainly need to install libQt5Pas-dev. If you wish to use a Qt5 version of Lazarus, build from source with a command like "make bigide LCL_PLATFORM=qt5 <enter>"
+
[[File:SelectQt5.png|200px|thumb|right|Image of Qt5 selected]]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.
 +
 
 +
{{Note | that if you install Lazarus using you distribution's version of Lazarus, you may need to specifically ask for the Qt5 LCL components. If installing from source, you will get the lot right from the start.}}
  
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.  
+
Don't forget, when releasing your app, it should be marked as being dependent on libqt5pas1.
  
 
===libqt5pas===
 
===libqt5pas===
A library that bridges between Qt5 and your Lazarus application. Newer distros have working versions available in their repositories.  
+
''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. 
 +
 
 +
{{Note | if you are using a version of Lazarus later than 2.2.0 you (and your end users) will need libQt5Pas greater or equal to 1.2.10. It will take some time for the distributions to update the version they distribute, so either build your own or use the unofficial https://github.com/davidbannon/libqt5pas/releases/latest debs and rpms as mentioned below. Remember, your end users need 1.2.10 too !}} 
  
 
Using your distros repository -
 
Using your distros repository -
Line 49: Line 61:
 
* Ubuntu, Debian - sudo apt install  libqt5pas1 <enter>
 
* Ubuntu, Debian - sudo apt install  libqt5pas1 <enter>
  
Note that some long term release distributions, such as Ubuntu 16.04 and 18.04 have an incompatible version of libqt5pas (even though it appears to have the same version number as later distros!). You should build a new version of the library, everything you need is in your Lazarus tree, bindings sources are located in lcl/interfaces/qt5/cbindings , to build it just follow README.txt. 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, its quite likely they are using one of the LTR Ubuntus and will strike this problem.
+
==== Do I have a problem with the version ? ====
[[File:SelectQt5.png]]
+
The version of libQt5Pas will cause concern to the following people, remember this affects you as a developer AND your end users.
 +
* Very Old Linux distribution users, such as Ubuntu 16.04 - sorry, no solution, do not use Qt5 if you need support such Operating Systems.
 +
* Old Linux Distributions such as U18.04, still officially supported until 2023 but uses an inadequate libQt5Pas. You will see a crash if your application uses TMemo. Replace the existing libQt5Pas.
 +
* Current LTS distributions like 20.04 (and, possibly 22.04, Debian Bullseye etc) will have libQt5Pas earlier than 1.2.10 and thats a problem if you use a Lazarus version later than 2.2.0. Again, you can replace the existing libQt5Pas
 +
 
 +
'''Replace your libQt5Pas ?'''
 +
 
 +
Two options, use a deb or rpm from https://github.com/davidbannon/libqt5pas/releases/latest - you might need to ensure your Package Manager does not object or, even, replace your bright shiny new one with its preferred distro one. Shout out on the Forum if you need something other than just the 64bit debs and RPMs there (Signing, 32bit, Pacman etc). Install with, eg, sudo apt install ./libqt5pas1_2.10-0_amd64.deb <enter>. As a developer, you will also need the -dev package, remove an existing one if present.
 +
 
 +
Secondly, the Lazarus source has the code to build your own, you will need gcc and a few other things, documented in the README.txt. Then copy the new library over top of your existing libQt5Pas1 (as root of course)
 +
 
 +
Note 1 that these two deb packages are made for Ubuntu 18.04 (or later), they will not help at all on Ubuntu 16.04 as its main Qt5 libraries are too old.
 +
 
 +
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.
 +
 
 +
===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:
 +
 
 +
<pre>
 +
QSocketNotifier: Can only be used with threads started with QThread
 +
[FORMS.PP] ExceptionOccurred
 +
....
 +
</pre>
 +
 
 +
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
 +
 
 +
===Qt5 Colours===
 +
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. qt5ct appears to be in most distribution's repository and is a quick and easy install. When you run it, it opens on the "Appearance" tab, for a Dark Theme, choose Palette = Custom, Color Scheme = Darker. Click "Apply" and "OK" to close the app.
 +
 
 +
[[File:qt5ct_dark.png]]
 +
 
 +
Did you note the message across the top, "The application is not configured correctly" ?  What it is worried about is that you have not added the environment variable setting that will tell your app to use the colours you just set.  You can set it for just one application by setting it in the application's command line :
 +
 
 +
<pre>QT_QPA_PLATFORMTHEME=qt5ct myapplication</pre>
 +
 
 +
That may be added to the app's Desktop file or maybe you edit the menu entry.  The alternative is to add it /etc/environment (obviously without the application's name) so it is automatically set for all apps, you need to logout and back in again. Adding an entry into your own .bashrc is not quite appropriate in that GUI apps started from the menu for example will not be told about it. Note: On Debian installing qt5ct automatically add QT_QPA_PLATFORMTHEME to environment variables.
  
 
===Why Qt5 instead of GTK ?===
 
===Why Qt5 instead of GTK ?===
Good question !  Most Linux Lazarus applications are built using the default GTK2. The various Linux distributions are delivering less and less 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....
+
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.
+
Qt5 is an obvious solution, its already installed on distros 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.
+
Clearly, Qt based distributions, ones using Plasma or KDE as a desktop will require only ''libqt5pas''.
  
 
==macOS (64-bit)==
 
==macOS (64-bit)==
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 minumum Qt 5.6.2 (Qt 5.12.xx works without problems too).
+
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):
 
After installing Qt 5.6.2 (see above), open up a terminal window and run these commands (paths may vary):
  
 
<pre>
 
<pre>
LazarusDir=/Developer/Lazarus
+
export LazarusDir=/Developer/Lazarus
QtDir=~/Qt5.6.2
+
export QtDir=~/Qt5.6.2
 
cd $LazarusDir/lcl/interfaces/qt5/cbindings
 
cd $LazarusDir/lcl/interfaces/qt5/cbindings
PATH=$QtDir/5.6/clang_64/bin:$PATH
+
export PATH=$QtDir/5.6/clang_64/bin:$PATH
 
qmake
 
qmake
 
</pre>
 
</pre>
Line 96: Line 144:
 
</pre>
 
</pre>
  
Remember that Qt5 is 64bit, so in Lazarus under Tools - Options - Environment, you need to change Compiler Executable from <code>/usr/local/bin/ppc386</code> to <code>/usr/local/bin/ppcx64</code> . With ppc386, you would later get the following errors when compiling your Lazarus projects:
+
Remember that Qt5 is 64 bit, so in Lazarus under Tools - Options - Environment, you need to change Compiler Executable from <code>/usr/local/bin/ppc386</code> to <code>/usr/local/bin/ppcx64</code> . With ppc386, you would later get the following errors when compiling your Lazarus projects:
  
 
<pre>
 
<pre>
Line 107: Line 155:
 
Finally, create a new Lazarus project (or open an existing one), open Project - Project options - Compiler options - Additions and overrides, set <code>LCLWidgetType:=qt5</code> . You should now be able to compile your project with the Qt5 widget set.
 
Finally, create a new Lazarus project (or open an existing one), open Project - Project options - Compiler options - Additions and overrides, set <code>LCLWidgetType:=qt5</code> . You should now be able to compile your project with the Qt5 widget set.
  
See [https://tondrej.blogspot.com/2018/04/first-steps-with-lazarus-qt5-interface.html] for an example project.
+
== Example Project ==
 +
 
 +
See [https://tondrej.blogspot.com/2018/04/first-steps-with-lazarus-qt5-interface.html First Steps with Lazarus Qt5 interface] for an example project for Win32, Win64, macOS (64 bit) and Linux (64 bit).
  
 
{{Other Interfaces}}
 
{{Other Interfaces}}
 
 
[[Category:Qt5]]
 
[[Category:Qt]]
 
[[Category:Widgetsets]]
 

Revision as of 16:55, 26 May 2022

English (en) русский (ru)

Qt logo 2013.svg

This article applies to Qt5 widgetset only.

See also: Multiplatform Programming Guide

Introduction

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.

Windows

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).

Qt5Core.dll
Qt5PrintSupport.dll
Qt5Widgets.dll
Qt5Gui.dll
Qt5Network.dll
libstdc++-6.dll
libwinpthread-1.dll
libgcc_s_dw2-1.dll

Builds based on MSVC rather than MinGW might have different set of (non Qt5) dlls required. Note that Qt5Pas1.dll is built against Qt5-5.6.2, but Qt5Pas1.dll can be used with any Qt5 > 5.6.2.

Linux

Lazarus

Image of Qt5 selected

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.

Light bulb  Note: that if you install Lazarus using you distribution's version of Lazarus, you may need to specifically ask for the Qt5 LCL components. If installing from source, you will get the lot right from the start.

Don't forget, when releasing your app, it should be marked as being dependent on libqt5pas1.

libqt5pas

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.

Light bulb  Note: if you are using a version of Lazarus later than 2.2.0 you (and your end users) will need libQt5Pas greater or equal to 1.2.10. It will take some time for the distributions to update the version they distribute, so either build your own or use the unofficial https://github.com/davidbannon/libqt5pas/releases/latest debs and rpms as mentioned below. Remember, your end users need 1.2.10 too !

Using your distros repository -

  • Fedora, Mageia - sudo dnf install qt5pas<enter>
  • Ubuntu, Debian - sudo apt install libqt5pas1 <enter>


Do I have a problem with the version ?

The version of libQt5Pas will cause concern to the following people, remember this affects you as a developer AND your end users.

  • Very Old Linux distribution users, such as Ubuntu 16.04 - sorry, no solution, do not use Qt5 if you need support such Operating Systems.
  • Old Linux Distributions such as U18.04, still officially supported until 2023 but uses an inadequate libQt5Pas. You will see a crash if your application uses TMemo. Replace the existing libQt5Pas.
  • Current LTS distributions like 20.04 (and, possibly 22.04, Debian Bullseye etc) will have libQt5Pas earlier than 1.2.10 and thats a problem if you use a Lazarus version later than 2.2.0. Again, you can replace the existing libQt5Pas

Replace your libQt5Pas ?

Two options, use a deb or rpm from https://github.com/davidbannon/libqt5pas/releases/latest - you might need to ensure your Package Manager does not object or, even, replace your bright shiny new one with its preferred distro one. Shout out on the Forum if you need something other than just the 64bit debs and RPMs there (Signing, 32bit, Pacman etc). Install with, eg, sudo apt install ./libqt5pas1_2.10-0_amd64.deb <enter>. As a developer, you will also need the -dev package, remove an existing one if present.

Secondly, the Lazarus source has the code to build your own, you will need gcc and a few other things, documented in the README.txt. Then copy the new library over top of your existing libQt5Pas1 (as root of course)

Note 1 that these two deb packages are made for Ubuntu 18.04 (or later), they will not help at all on Ubuntu 16.04 as its main Qt5 libraries are too old.

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.

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

Qt5 Colours

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. qt5ct appears to be in most distribution's repository and is a quick and easy install. When you run it, it opens on the "Appearance" tab, for a Dark Theme, choose Palette = Custom, Color Scheme = Darker. Click "Apply" and "OK" to close the app.

qt5ct dark.png

Did you note the message across the top, "The application is not configured correctly" ? What it is worried about is that you have not added the environment variable setting that will tell your app to use the colours you just set. You can set it for just one application by setting it in the application's command line :

QT_QPA_PLATFORMTHEME=qt5ct myapplication

That may be added to the app's Desktop file or maybe you edit the menu entry. The alternative is to add it /etc/environment (obviously without the application's name) so it is automatically set for all apps, you need to logout and back in again. Adding an entry into your own .bashrc is not quite appropriate in that GUI apps started from the menu for example will not be told about it. Note: On Debian installing qt5ct automatically add QT_QPA_PLATFORMTHEME to environment variables.

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 distros 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.

macOS (64-bit)

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

If 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/ppc386 to /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.

Example Project

See First Steps with Lazarus Qt5 interface for an example project for Win32, Win64, macOS (64 bit) and Linux (64 bit).

Other Interfaces

Platform specific Tips

Interface Development Articles