Difference between revisions of "FPC and Qt"

From Lazarus wiki
Jump to navigationJump to search
 
Line 17: Line 17:
 
This piece of code is taken from the second of these two packages mentioned above.
 
This piece of code is taken from the second of these two packages mentioned above.
  
<nowiki>
+
var
var
+
  app: QApplicationH;
  app: QApplicationH;
+
  btn: QPushButtonH;
  btn: QPushButtonH;
+
begin
begin
+
  // create static ( interfaced handled ) QApplicationH
  // create static ( interfaced handled ) QApplicationH
+
  app := NewQApplicationH(ArgCount, ArgValues).get;
  app := NewQApplicationH(ArgCount, ArgValues).get;
+
  // due to a bug in fpc 1.9.5 the WideString helper methods with default parameter are disabled
 
+
  //btn := NewQPushButtonH('Quit', nil).get;
  // due to a bug in fpc 1.9.5 the WideString helper methods with default parameter are disabled
+
  btn := NewQPushButtonH(qs('Quit').get, nil, nil).get;
  //btn := NewQPushButtonH('Quit', nil).get;
+
  btn.setGeometry(100, 100, 300, 300);
  btn := NewQPushButtonH(qs('Quit').get, nil, nil).get;
+
  btn.show;
  btn.setGeometry(100, 100, 300, 300);
+
  // override the virtual eventFilter method of btn
  btn.show;
+
  btn.OverrideHook.eventFilter := @TTest.MyEventFilter;
 
+
  // and install the btn as it's own eventFilter
  // override the virtual eventFilter method of btn
+
  btn.installEventFilter(btn);
  btn.OverrideHook.eventFilter := @TTest.MyEventFilter;
+
  // connect Qt signal to Qt slot
  // and install the btn as it's own eventFilter
+
  QObjectH.connect(btn, SIGNAL('clicked()'), app, SLOT('quit()'));
  btn.installEventFilter(btn);
 
 
 
  // connect Qt signal to Qt slot
 
  QObjectH.connect(btn, SIGNAL('clicked()'), app, SLOT('quit()'));
 
</nowiki>
 
  
 
If you know Qt used in C++, you might see, that there is no much difference.
 
If you know Qt used in C++, you might see, that there is no much difference.

Revision as of 21:15, 25 September 2004

Introduction

Since a few months, there are now Qt3 interface units available for FPC. There are two different packages available:

http://www.theo.ch/kylix/Qt3pas.zip http://andy.jgknet.de/oss/qt/qt3forFPC/

The first one aims on linux/unix users while the second one is for win32.

How it works

FPC still can't use C++ classes natively so these interface units use the same scheme as e.g. the official C interface to Qt does: there are wrapper procedures written which export an procedural interface. This procedural interface is wrapped by an object pascal interface again to make usage easier.

This might sound like an huge overhead but these wrapper are mainly necessary to hide name mangling differences so there shouldn't be a noticable speed decrease in real world applications.

Example

This piece of code is taken from the second of these two packages mentioned above.

var
  app: QApplicationH;
  btn: QPushButtonH;
begin
  // create static ( interfaced handled ) QApplicationH
  app := NewQApplicationH(ArgCount, ArgValues).get;
  // due to a bug in fpc 1.9.5 the WideString helper methods with default parameter are disabled
  //btn := NewQPushButtonH('Quit', nil).get;
  btn := NewQPushButtonH(qs('Quit').get, nil, nil).get;
  btn.setGeometry(100, 100, 300, 300);
  btn.show;
  // override the virtual eventFilter method of btn
  btn.OverrideHook.eventFilter := @TTest.MyEventFilter;
  // and install the btn as it's own eventFilter
  btn.installEventFilter(btn);
  // connect Qt signal to Qt slot
  QObjectH.connect(btn, SIGNAL('clicked()'), app, SLOT('quit()'));

If you know Qt used in C++, you might see, that there is no much difference.