Difference between revisions of "Qt5 Interface"

From Lazarus wiki
(macOS (64-bit))
(Windows)
Line 30: Line 30:
 
: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 made base 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.
  
 
==Linux==
 
==Linux==

Revision as of 09:33, 11 November 2019

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

Windows

There is Q5Pas1.dll binary available.

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

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.

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 i.e. 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 made base 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.

Linux

libqt5pas

A library that bridges between Qt5 and your Lazarus application. Newer distros have working versions available in their repositories. However, some, such as the long term release Ubuntu 18.04 may require an update to its Qt5 libraries and possibly a custom built libqt5pas. All you need to build that library is in your Lazarus tree, bindings sources are located in lcl/interfaces/qt5/cbindings , to build it just follow README.txt.

Using your distros repository -

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


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

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

After installing Qt 5.6.2 (see above), open up a terminal window and run these commands (paths may vary):

LazarusDir=/Developer/Lazarus
QtDir=~/Qt5.6.2
cd $LazarusDir/lcl/interfaces/qt5/cbindings
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 64bit, 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.

See [1] for an example project.

Other Interfaces

Platform specific Tips

Interface Development Articles