Difference between revisions of "Qt Interface"

From Lazarus wiki
Jump to navigationJump to search
(Updated important note to warning; fixed typos + wiki syntax)
 
(100 intermediate revisions by 24 users not shown)
Line 1: Line 1:
==Introduction==
+
{{Platform only|Qt|Qt|Qt widgetset}}
 +
{{Qt Interface}}
  
The Qt 4 widgetset is in an early stage of development.
+
{{Warning|This page deals with Qt4 and very old versions of Lazarus. It is most likely you would find the [[Qt5 Interface]] page more helpful.}}
  
This interface is based on Qt 4.1.1 and it's corresponding documentation [http://doc.trolltech.com/4.1/ here].
+
== Introduction ==
 +
This interface is based on Qt 4 (Qt 4.8.4 is tested). For documentation, fixes and download, go to [http://qt-project.org/ Qt Project] (Installers at [http://download.qt.io/archive/qt/4.8/ download 4.8]). Lazarus with Qt interface (qt-lcl) can be used on Windows, Linux x32/x64/arm, FreeBSD, macOS 32 bit (Carbon)/ 64 bit (Cocoa).
  
===Quick start guide for Linux===
+
== Quick start guide for Linux ==
 +
'''As of lazarus 0.9.29 svn rev. 23858 2.1 bindings are needed, also bindings name is changed from libqt4intf to libQt4Pas ! ''' <br>
 +
'''IMPORTANT NOTE: for qt >= 4.7.XX libQt4Pas is compiled with -mstackrealign to avoid crashes, so download proper version from bindings page (binary bindings for 4.7 are marked) if your Qt version is 4.7 or higher.  ''' <br>
 +
The first thing to do is go to the [http://users.pandora.be/Jan.Van.hijfte/qtforfpc/fpcqt4.html official website] of the bindings and download the binary Qt bindings.
 +
Copy the file libQt4Pas.so.5.2.1 + its symlinks libQt4Pas.so.5.2 libQt4Pas.so.5 libQt4Pas.so to the directory /usr/lib/ or /usr/local/lib
 +
Now run "ldconfig" to update the linker cache.
 +
You can verify its success by running:
  
The first thing to do is go to the [http://users.pandora.be/Jan.Van.hijfte/qtforfpc/fpcqt4.html official website] of the bindings and download the binary Qt bindings. Copy the file libqt4intf.so to the directory /usr/lib/
+
ldconfig -p | grep libQt4Pas.so.5.2.1
  
Now compile the LCL for Qt. First open your normal gtk compiled Lazarus. Then go on the menu "Tools" --> "Configure Build Lazarus". Set LCL to "clean+build" and everything else to "None". Now select "Qt" and click on the "Ok" button. Next go to the menu "Tools" --> "Build Lazarus". Now the LCL is compiled for Qt.
+
It must say something like:
  
To compile a project for Qt just select it as the target widgetset on the Compiler Options dialog.
+
        libQt4Pas.so (libc6) => /usr/local/lib/libQt4Pas.so
 +
 
 +
If it didn't work, you have to check the config files in /etc/ld.so.conf.d/ or the config file /etc/ld.so.conf, depending on your distro - it must include the path where you copied the libQt4Pas.so* files.
  
At this moment the Lazarus IDE cannot be compiled for Qt because it uses features missing on this widgetset.
+
Hint: If you use a Debian based distribution, you can add the following repositories to your sources.list <nowiki>
 +
deb http://ppa.launchpad.net/ximion/ppa/ubuntu karmic main
 +
deb-src http://ppa.launchpad.net/ximion/ppa/ubuntu karmic main
 +
The repositories contain libQt4Pas.
 +
</nowiki>
  
===Quick start guide for Mac OS X===
+
To let your package management system trust the keys in the PPA mentioned above use something like:
 +
<syntaxhighlight lang="bash">
 +
gpg --recv-keys 4BF17E057EC6E8C3 --keyserver http://wwwkeys.eu.pgp.net
 +
gpg --armor --export 4BF17E057EC6E8C3 | apt-key add - #may need to use sudo here
 +
</syntaxhighlight> 
  
please write me
 
  
===Quick start guide for PDAs and Smartphones===
+
===For Lazarus 0.9.30 and below===
 +
Now compile the LCL for Qt. First open your normal gtk2 compiled Lazarus. Then go on the menu "Tools" --> "Configure Build Lazarus". Set LCL to "clean+build" and everything else to "None". Now select "Qt" and click on the "Ok" button. Next go to the menu "Tools" --> "Build Lazarus". Now the LCL is compiled for Qt.
  
please write me
+
To compile a project for Qt just select it as the target widgetset on the Compiler Options dialog.
  
==Qt 4 Bindings==
+
===For Lazarus 0.9.31===
 +
To compile the IDE for qt, first create a backup of the ''lazarus'' executable for the case something goes wrong. Then open ''Tools / Configure Build Lazarus'' and set '''LCL Widget Type''' to '''qt'''. Then click ''Build''. After a restart you will get the qt IDE. All projects are now compiled by default with qt.
  
This interface utilizes Qt 4 bindings created by Den Jean. The bindings are a c++ library which exports the methods of the Qt objects as procedures. The library has 800kb in linux, consists of a single .so file that needs to be distributed with your LCL program.
+
If you use a gtk2 IDE and want to compile a project for qt, open the Project / Project Options / Build Modes. Go to ''Set Macro Values''. Choose macro name '''LCLWidgetType''' and choose macro value to '''qt'''. Close the dialog with Ok and compile. All packages needed by your project will be automatically updated.
  
You can find more information about those bindings on the official [http://users.pandora.be/Jan.Van.hijfte/qtforfpc/fpcqt4.html website] and on [[fpc:Qt4 binding]].
 
  
Is is being reported that it may be possible to link to Qt 4 directly, using some tricks. Many think it is not. This is yet to be tested. It is expected that any such binding will be compatible with the currently utilized one, so the interface code won´t have to be changed.
+
'''Installing Qt 4'''
  
===Compiling the bindings===
+
Most distributions now have packages for Qt 4. If your distribution is RPM-based you can search for a qt4 package here: http://rpm.pbone.net/index.php3/stat/2/simple/2 <br>
 +
'''The supported Qt version is 4.5.0 or superior'''
  
It is not necessary to compile the bindings yourself if you plan to release a GPL software. GPL Binaries are available on Den Jean website. If you want to release non-GPL code, then you must compile the bindings yourself using the Commercial Edition of Qt.
+
'''Known problems on linux'''
 +
* glibc < 2.4 (older distros eg. FC3) users must compile qt-x11 with -no-sse or you have immediate segfaults.
 +
* <s>'''Qt-4.4.1''' if x11 < 7.0 & glibc < 2.4 (older distros) QPalette doesn't return good results for some palettes eg. QToolTip_palette().</s>
  
'''Step 1''' - To start with download all the files needed to compile the bindings.
+
== Quick start guide for macOS ==
 +
Instructions on the [[Qt Interface Mac]] wiki page.
  
* Download the source code of the bindings. Go to the offical website of the bindings. Link above.
+
== Quick start guide for PDAs and Smartphones ==
 +
please write me
  
* Also Download Qt 4.1.1 source code for the desired platform. This is the download page: [http://www.trolltech.com/download/opensource.html]
+
== Quick start guide for Windows ==
 +
There's nothing special to say for Windows, it works like on Linux and seems less buggy than the Win32 interface with some controls (TListView). Not needed to rebuild IDE, just set Qt in current project:
  
'''Step 2''' - Unpack all the files you downloaded. Enter the directory where you downloaded Qt 4.1.1 source code and use this command:
+
* open "Project / Project Options / Build Modes"
 +
* go to "Set Macro Values"
 +
* choose macro name LCLWidgetType and set macro value to "qt"
  
<pre>
+
''' Version '''
./configure
 
</pre>
 
  
'''Step 3''' - Go to the directory where you downloaded and extracted qt4pas sources and edit the file compile_lib.bash. Change the path for the Qt 4.1.1 source code.
+
It seems Qt 4.8.6 doesn't work with current Qt4Pas5.dll. Better use 4.8.4 or maybe 4.8.5.
  
'''Step 4''' - Run the script called compile_lib.bash. Now you should have a file called libqt4intf.so
+
''' Installation '''
  
==Road map for the Qt 4 interface==
+
* Download Qt4 opensource edition for MinGW, from [http://qt-project.org/downloads official website], from [http://download.qt.io/archive/qt/ this archive folder]
 +
* Download Qt4Pas5.dll from [http://users.telenet.be/Jan.Van.hijfte/qtforfpc/fpcqt4.html FPC Qt4 Binding]
 +
* Download MinGW installer, from installer add MinGW C++ compiler and DLLs
 +
* Add to system PATH: a) Qt4 "bin" folder, b) folder of Qt4Pas5.dll, c) folder of MinGW DLLs
 +
* Alternative to prev step: copy all DLLs into app folder
  
===currently implemented components with their status===
+
== Qt 4 Bindings ==
 +
This interface utilizes Qt 4 bindings created by Den Jean. The bindings are a c++ library which exports the methods of the Qt objects as procedures. The library (around 800kb in Linux) consists of a single .so file that needs to be distributed with your LCL program.
  
Moved here: [[Road_To_1.0#Widgetset_dependent_components]]
+
You can find more information about those bindings on the official [http://users.pandora.be/Jan.Van.hijfte/qtforfpc/fpcqt4.html website] and on [[Qt4 binding|FreePascal Qt4 binding]].
  
===components scheduled to be implemented===
+
It is being reported that it may be possible to link to Qt 4 directly, using some tricks. Many think it is not. This is yet to be tested. It is expected that any such binding will be compatible with the currently utilized one, so the interface code won´t have to be changed.
  
* TPopUpMenu
+
=== Compiling the bindings ===
* TBitmap - Needs a description of the internal format used by Qt
+
* Qt-4.5 and higher are now available under the LGPL license. This means that you can distribute qt Pascal bindings with your program, GPL or non-GPL.
* TPixmap
+
* Lower Qt versions:
* TIcon
+
** If you plan to release GPL-licensed software: it is not necessary to compile the bindings yourself. GPL Binaries are available on Den Jean's website.
 +
** If you want to release non-GPL code, then you must compile the bindings yourself using the Commercial Edition of Qt.
  
===currently implemented Windows API functions by group and with status===
+
{{Note|If you plan to compile the bindings make sure to compile Qt with OpenSSL support. In debian for example, installing the libssl-dev package should do it}}
  
'''Mouse functions'''
+
'''Step 1''' - To start with download all the files needed to compile the bindings.
  
SetCursorPos, GetCursorPos for TMouse - <span style="color:green">Fully working</span>
+
* Download the source code of the bindings. Go to the official website of the bindings. Link above.
  
'''GDI functions'''
+
* Also Download Qt 4.5.2(3) or Qt 4.6.2(3) source code for the desired platform. This is the download page: [http://www.trolltech.com/download/opensource.html]
  
BeginPaint, GetDC, EndPaint, ReleaseDC, Rectangle for TCanvas and OnPaint event- <span style="color:green">Fully working</span>
+
'''Step 2''' - Unpack all the files you downloaded. Enter the directory where you downloaded Qt 4.5(6).2(3) source code and use this command:
  
===Coments===
+
<pre>
 +
run qmake -query to inspect your Qt installation
 +
qmake (creates Makefiles)
 +
make
 +
make install
 +
use make clean to clean sources directory when switching qt versions
 +
</pre>
  
It's really interesting.<br><br>
+
'''Step 3''' - <s>Go to the directory where you downloaded and extracted qt4pas sources and edit the file compile_lib.bash. Change the path for the Qt 4.5.2(3) source code.</s> needed for old bindings.
Buy if will works also on Win32 OS?<br>
 
  
: It will work for win32. It's just a question of recompiling the bindings. The code on the widgetset is completely platform independent, so the limiting factors are the bindings and Qt. However, there is little use for this on win32. There already exists a win32 native widgetset, you should use that one on Windows. The same code can be recompiled with any of the existing widgetsets on Lazarus. A more interresting place where this will work is: Linux powered PDAs.
+
'''Step 4''' - <s>Run the script called compile_lib.bash. Now you should have a file called libqt4intf.so.5.XXXX where XXXX is version of qt bindings, and its symbolic links libqt4intf.so.5 and libqt4intf.so</s> needed for old bindings.With new bindings you'll get libQt4Pas.so.5.2.1 and symlinks libQt4Pas.so.5.2 libQt4Pas.so.5 libQt4Pas.so which must be in your library path (eg. copy it into /usr/lib).
  
When do you think to can see the Lazarus IDE run full on QT4 Lib?<br>
+
== Road map for the Qt 4 interface ==
 +
Moved here: [[Roadmap#Widgetset_dependent_components]]
  
: No idea. If only I work on this, maybe 6 months. If others help, sooner.
+
== Conditional defines accepted by the Qt Interface ==
 +
Moved here: [[LCL_Defines#Qt_defines]]
  
When do you think will be possible create full GUI applications using QT4?<br>
+
== Screenshots ==
 +
[[Image:Much_qt_progress.png]]<br>
  
: No idea. If only I work on this, maybe 6 months. If others help, sooner.
+
'''More screenshots'''<br>
 +
[http://wiki.lazarus.freepascal.org/Image:Linuxqtide.png Qt Lazarus IDE running under linux (kernel 2.6.12, XOrg-6.8.2, KDE-3.4.0)]<br>
 +
[http://wiki.lazarus.freepascal.org/Image:macosxqt.png Qt Lazarus IDE running under Tiger 10.4.10]
  
 
== Contributing ==
 
== Contributing ==
  
 
=== How to add a new control ===
 
=== How to add a new control ===
 
 
For example TButton.
 
For example TButton.
  
Line 116: Line 155:
  
 
Also notice that DestroyHandle should be implemented to clean up memory utilized by the control.
 
Also notice that DestroyHandle should be implemented to clean up memory utilized by the control.
 +
 +
== Mailling List ==
 +
There is a Lazarus - Qt mailling list for support and talk about the development of this interface here: http://lists.lazarus.freepascal.org/mailman/listinfo/qt
 +
 +
{{Other Interfaces}}
 +
 +
[[Category:Qt]]

Latest revision as of 08:03, 25 February 2021

Qt logo 2013.svg

This article applies to Qt widgetset only.

See also: Multiplatform Programming Guide

English (en) español (es) 日本語 (ja)

Warning-icon.png

Warning: This page deals with Qt4 and very old versions of Lazarus. It is most likely you would find the Qt5 Interface page more helpful.

Introduction

This interface is based on Qt 4 (Qt 4.8.4 is tested). For documentation, fixes and download, go to Qt Project (Installers at download 4.8). Lazarus with Qt interface (qt-lcl) can be used on Windows, Linux x32/x64/arm, FreeBSD, macOS 32 bit (Carbon)/ 64 bit (Cocoa).

Quick start guide for Linux

As of lazarus 0.9.29 svn rev. 23858 2.1 bindings are needed, also bindings name is changed from libqt4intf to libQt4Pas !
IMPORTANT NOTE: for qt >= 4.7.XX libQt4Pas is compiled with -mstackrealign to avoid crashes, so download proper version from bindings page (binary bindings for 4.7 are marked) if your Qt version is 4.7 or higher.
The first thing to do is go to the official website of the bindings and download the binary Qt bindings. Copy the file libQt4Pas.so.5.2.1 + its symlinks libQt4Pas.so.5.2 libQt4Pas.so.5 libQt4Pas.so to the directory /usr/lib/ or /usr/local/lib Now run "ldconfig" to update the linker cache. You can verify its success by running:

ldconfig -p | grep libQt4Pas.so.5.2.1

It must say something like:

       libQt4Pas.so (libc6) => /usr/local/lib/libQt4Pas.so

If it didn't work, you have to check the config files in /etc/ld.so.conf.d/ or the config file /etc/ld.so.conf, depending on your distro - it must include the path where you copied the libQt4Pas.so* files.

Hint: If you use a Debian based distribution, you can add the following repositories to your sources.list 
 deb http://ppa.launchpad.net/ximion/ppa/ubuntu karmic main 
 deb-src http://ppa.launchpad.net/ximion/ppa/ubuntu karmic main
 The repositories contain libQt4Pas.

To let your package management system trust the keys in the PPA mentioned above use something like:

gpg --recv-keys 4BF17E057EC6E8C3 --keyserver http://wwwkeys.eu.pgp.net 
gpg --armor --export 4BF17E057EC6E8C3 | apt-key add - #may need to use sudo here


For Lazarus 0.9.30 and below

Now compile the LCL for Qt. First open your normal gtk2 compiled Lazarus. Then go on the menu "Tools" --> "Configure Build Lazarus". Set LCL to "clean+build" and everything else to "None". Now select "Qt" and click on the "Ok" button. Next go to the menu "Tools" --> "Build Lazarus". Now the LCL is compiled for Qt.

To compile a project for Qt just select it as the target widgetset on the Compiler Options dialog.

For Lazarus 0.9.31

To compile the IDE for qt, first create a backup of the lazarus executable for the case something goes wrong. Then open Tools / Configure Build Lazarus and set LCL Widget Type to qt. Then click Build. After a restart you will get the qt IDE. All projects are now compiled by default with qt.

If you use a gtk2 IDE and want to compile a project for qt, open the Project / Project Options / Build Modes. Go to Set Macro Values. Choose macro name LCLWidgetType and choose macro value to qt. Close the dialog with Ok and compile. All packages needed by your project will be automatically updated.


Installing Qt 4

Most distributions now have packages for Qt 4. If your distribution is RPM-based you can search for a qt4 package here: http://rpm.pbone.net/index.php3/stat/2/simple/2
The supported Qt version is 4.5.0 or superior

Known problems on linux

  • glibc < 2.4 (older distros eg. FC3) users must compile qt-x11 with -no-sse or you have immediate segfaults.
  • Qt-4.4.1 if x11 < 7.0 & glibc < 2.4 (older distros) QPalette doesn't return good results for some palettes eg. QToolTip_palette().

Quick start guide for macOS

Instructions on the Qt Interface Mac wiki page.

Quick start guide for PDAs and Smartphones

please write me

Quick start guide for Windows

There's nothing special to say for Windows, it works like on Linux and seems less buggy than the Win32 interface with some controls (TListView). Not needed to rebuild IDE, just set Qt in current project:

  • open "Project / Project Options / Build Modes"
  • go to "Set Macro Values"
  • choose macro name LCLWidgetType and set macro value to "qt"

Version

It seems Qt 4.8.6 doesn't work with current Qt4Pas5.dll. Better use 4.8.4 or maybe 4.8.5.

Installation

  • Download Qt4 opensource edition for MinGW, from official website, from this archive folder
  • Download Qt4Pas5.dll from FPC Qt4 Binding
  • Download MinGW installer, from installer add MinGW C++ compiler and DLLs
  • Add to system PATH: a) Qt4 "bin" folder, b) folder of Qt4Pas5.dll, c) folder of MinGW DLLs
  • Alternative to prev step: copy all DLLs into app folder

Qt 4 Bindings

This interface utilizes Qt 4 bindings created by Den Jean. The bindings are a c++ library which exports the methods of the Qt objects as procedures. The library (around 800kb in Linux) consists of a single .so file that needs to be distributed with your LCL program.

You can find more information about those bindings on the official website and on FreePascal Qt4 binding.

It is being reported that it may be possible to link to Qt 4 directly, using some tricks. Many think it is not. This is yet to be tested. It is expected that any such binding will be compatible with the currently utilized one, so the interface code won´t have to be changed.

Compiling the bindings

  • Qt-4.5 and higher are now available under the LGPL license. This means that you can distribute qt Pascal bindings with your program, GPL or non-GPL.
  • Lower Qt versions:
    • If you plan to release GPL-licensed software: it is not necessary to compile the bindings yourself. GPL Binaries are available on Den Jean's website.
    • If you want to release non-GPL code, then you must compile the bindings yourself using the Commercial Edition of Qt.
Light bulb  Note: If you plan to compile the bindings make sure to compile Qt with OpenSSL support. In debian for example, installing the libssl-dev package should do it

Step 1 - To start with download all the files needed to compile the bindings.

  • Download the source code of the bindings. Go to the official website of the bindings. Link above.
  • Also Download Qt 4.5.2(3) or Qt 4.6.2(3) source code for the desired platform. This is the download page: [1]

Step 2 - Unpack all the files you downloaded. Enter the directory where you downloaded Qt 4.5(6).2(3) source code and use this command:

run qmake -query to inspect your Qt installation
qmake (creates Makefiles)
make
make install
use make clean to clean sources directory when switching qt versions

Step 3 - Go to the directory where you downloaded and extracted qt4pas sources and edit the file compile_lib.bash. Change the path for the Qt 4.5.2(3) source code. needed for old bindings.

Step 4 - Run the script called compile_lib.bash. Now you should have a file called libqt4intf.so.5.XXXX where XXXX is version of qt bindings, and its symbolic links libqt4intf.so.5 and libqt4intf.so needed for old bindings.With new bindings you'll get libQt4Pas.so.5.2.1 and symlinks libQt4Pas.so.5.2 libQt4Pas.so.5 libQt4Pas.so which must be in your library path (eg. copy it into /usr/lib).

Road map for the Qt 4 interface

Moved here: Roadmap#Widgetset_dependent_components

Conditional defines accepted by the Qt Interface

Moved here: LCL_Defines#Qt_defines

Screenshots

Much qt progress.png

More screenshots
Qt Lazarus IDE running under linux (kernel 2.6.12, XOrg-6.8.2, KDE-3.4.0)
Qt Lazarus IDE running under Tiger 10.4.10

Contributing

How to add a new control

For example TButton.

TButton is defined in lcl/buttons.pp. This is the platform independent part of the LCL, which is used by the normal LCL programmer.

Its widgetset class is in lcl/widgetset/wsbuttons.pp. This is the platform independent base for all widgetsets (qt, carbon, gtk, win32, ...).

Its qt interface class is in lcl/interfaces/qt/qtwsbuttons.pp:

 TQtWSButton = class(TWSButton)
 private
 protected
 public
   class function  CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
 end;

Every WS class, that actually implements something must be registered. See the initialization section at the end of the qtwsXXX.pp unit:

 RegisterWSComponent(TQtButton, TQtWSButton);

TQtWSButton overrides CreateHandle to create a qt QPushButton. The code is short and should be easily adaptable for other controls like TCheckBox. Remember that all controls on the Qt widgetset have a helper class on qtprivate.pp, and it is also necessary to add a class for the new control. This isn´t difficult.

Also notice that DestroyHandle should be implemented to clean up memory utilized by the control.

Mailling List

There is a Lazarus - Qt mailling list for support and talk about the development of this interface here: http://lists.lazarus.freepascal.org/mailman/listinfo/qt

Other Interfaces

Platform specific Tips

Interface Development Articles