Difference between revisions of "Qt Interface"

From Lazarus wiki
Jump to navigationJump to search
Line 15: Line 15:
 
===Compiling the bindings===
 
===Compiling the bindings===
  
It is not necessary to compile the bindings yourself if you plan to release a GPL software. GPL Binaries are available on Jen Dean website. If you want to release non-GPL code, then you must compile the bindings yourself using the Commercial Edition of Qt.
+
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.
  
 
'''Step 1''' - To start with download all the files needed to compile the bindings.
 
'''Step 1''' - To start with download all the files needed to compile the bindings.
Line 21: Line 21:
 
* Download the source code of the bindings. Go to the offical website of the bindings. Link above.
 
* Download the source code of the bindings. Go to the offical website of the bindings. Link above.
  
* Also Download Qt 4.0.1 source code for the desired platform. This is the download page: [http://www.trolltech.com/download/opensource.html]
+
* Also Download Qt 4.1.1 source code for the desired platform. This is the download page: [http://www.trolltech.com/download/opensource.html]
  
'''Step 2''' - Unpack all the files you downloaded. Enter the directory where you downloaded Qt 4.0 source code and use this command:
+
'''Step 2''' - Unpack all the files you downloaded. Enter the directory where you downloaded Qt 4.1.1 source code and use this command:
  
 
<pre>
 
<pre>
Line 29: Line 29:
 
</pre>
 
</pre>
  
'''Step 3''' - Go to the directory where you downloaded and extrected qt4pas sources and edit the file compile_lib.bash. Change the path for the Qt 4.0.1 source code.
+
'''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.
  
 
'''Step 4''' - Run the script called compile_lib.bash. Now you should have a file called libqt4intf.so
 
'''Step 4''' - Run the script called compile_lib.bash. Now you should have a file called libqt4intf.so

Revision as of 21:11, 7 March 2006

Introduction

The Qt 4 widgetset is in an early stage of development.

This interface is based on Qt 4.0 and it's corresponding documentation here.

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

Compiling the bindings

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.

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

  • Download the source code of the bindings. Go to the offical website of the bindings. Link above.
  • Also Download Qt 4.1.1 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.1.1 source code and use this command:

./configure

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.

Step 4 - Run the script called compile_lib.bash. Now you should have a file called libqt4intf.so

Road map for the Qt 4 interface

currently implemented components with their status

  • TApplication - Partially implemented
  • TCustomForm - Partially implemented
  • TCustomButton - Fully implemented!
  • TCustomMemo - Partially implemented
  • TMouse - Fully implemented!
  • TCanvas - Partially implemented - Only works on the OnPaint event
  • TTimer - Fully implemented!
  • TCheckBox - Partially implemented
  • TRadioButton - Partially implemented
  • TStaticText - Partially implemented
  • TLabel - Partially implemented

components scheduled to be implemented

  • TPopUpMenu
  • TBitmap - Needs a description of the internal format used by Qt
  • TPixmap
  • TIcon

currently implemented Windows API functions by group and with status

Mouse functions

SetCursorPos, GetCursorPos for TMouse - Fully working

GDI functions

BeginPaint, GetDC, EndPaint, ReleaseDC, Rectangle for TCanvas and OnPaint event- Fully working

wish-list of new components

Use this space for components you would like to see implemented

It's really interesting.

Buy if will works also on Win32 OS?

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.

When do you think to can see the Lazarus IDE run full on QT4 Lib?

No idea. If only I work on this, maybe 6 months. If others help, sooner.

When do you think will be possible create full GUI applications using QT4?

No idea. If only I work on this, maybe 6 months. If others help, sooner.

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.