[Qt] uclibc + libqt4intf- EAccessViolation : Access violation
Nataraj S Narayan
natarajsn at gmail.com
Mon Feb 1 13:19:38 CET 2010
Hi
The following code is part one the examples in demos-V1.72_Qt4.5.2.
regards
Nataraj
program concentric;
{$mode objfpc}{$H+}
(* {$linklib gcc_s}
*)
uses
CMem,Strings,
SysUtils,Classes,Types,Math,qt4;
function SlotName(Name:String):PAnsiChar;
begin
Result:=StrNew(PChar('1'+Name));
end;
function SignalName(Name:String):PAnsiChar;
begin
Result:=StrNew(PChar('2'+Name));
end;
type
TMainForm = class;
TCircleWidget = class(TObject)
private
Handle : QWidgetH;
FFloatBased : Boolean;
FAntialiased : Boolean;
FFrameNo : Integer;
procedure SetFloatBased (const Value : Boolean);
procedure SetAntiAliased (const Value : Boolean);
procedure NextAnimationFrame;cdecl;
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
procedure Paint (QPaintEvent : QPaintEventH);
public
constructor Create(Parent:TMainForm);
property FloatBased : Boolean read FFloatBased write SetFloatBased;
property Antialiased : Boolean read FAntialiased write SetAntialiased;
end;
TMainForm = class(TObject)
private
CircleWidgets : array [1..2,1..2] of TCircleWidget;
function CreateLabel (s : WideString) : QLabelH;
public
Handle : QWidgetH;
quitButton : QPushButtonH;
constructor Create;
end;
TApplication = class(TObject)
private
public
MainForm : TMainForm;
constructor Create;
end;
//*******************************************************
// TCircleWidget
//*******************************************************
//===============================================
constructor TCircleWidget.Create(Parent:TMainForm);
var
Hook : QWidget_hookH;
begin
inherited Create();
Handle:=QWidget_create(Parent.Handle);
FFloatBased:=false;
FAntialiased:=false;
FFrameNo:=0;
QWidget_setBackgroundRole(Handle, QPaletteBase);
QWidget_setSizePolicy(Handle, QSizePolicyExpanding, QSizePolicyExpanding);
// Event filter
Hook:=QWidget_hook_create(handle);
QObject_hook_hook_events(Hook, at EventFilter);
end;
//===============================================
procedure TCircleWidget.SetFloatBased (const Value : Boolean);
begin
FFloatbased:=Value;
QWidget_update(Handle);
end;
//===============================================
procedure TCircleWidget.SetAntiAliased (const Value : Boolean);
begin
FAntialiased:=Value;
QWidget_update(Handle);
end;
//===============================================
procedure TCircleWidget.NextAnimationFrame;cdecl;
begin
FFrameNo:=FFrameNo+1;
QWidget_update(Handle);
end;
//===============================================
function TCircleWidget.EventFilter(Sender: QObjectH; Event: QEventH):
Boolean; cdecl;
begin
Result:=False;
if QEvent_type(Event) = QEventPaint then Paint(QPaintEventH(Event));
end;
//===============================================
procedure TCircleWidget.Paint (QPaintEvent : QPaintEventH);
var
Painter : QPainterH;
Diameter : Integer;
Alpha, Delta : Integer;
QPen : QPenH;
QColor : TQColor;
QRectF : QRectFH;
begin
try
Painter:=QPainter_create(QWidget_to_QPaintDevice(Handle));
QPainter_setRenderHint(Painter,QPainterAntialiasing, Antialiased);
QPainter_translate(Painter,QWidget_width(Handle) div 2,
QWidget_height(Handle) div 2);
Diameter:=0;
while Diameter < 256 do
begin
Delta := abs((FFrameNo mod 128) - Diameter div 2);
Alpha := 255 - (Delta * Delta) div 4 - Diameter;
if (Alpha > 0) then
begin
QColor_fromRGB(@QColor,0, Diameter div 2, 127, Alpha);
QPen := QPen_create(@QColor);
QPen_setWidth(QPen, 3);
QPainter_setPen(painter, QPen);
if FloatBased then
begin
QRectF:=QRectF_create(-diameter / 2.0, -diameter / 2.0,
Diameter, Diameter);
QPainter_drawEllipse(painter,QRectF);
QRectF_destroy(QRectF);
end
else
QPainter_drawEllipse(painter,-diameter div 2, -diameter div 2,
Diameter, Diameter);
end;
Diameter:=Diameter+9;
end;
finally
QPen_destroy(QPen);
QPainter_destroy(Painter);
end;
end;
//*******************************************************
// TMainForm
//*******************************************************
//===============================================
constructor TMainForm.Create;
var
w : Widestring;
i, j : integer;
layout : QGridLayoutH;
QTimer : QTimerH;
TimerHook : QTimer_hookH;
begin
inherited;
Handle:=QWidget_create();
layout := QGridLayout_create;
QGridLayout_addWidget(layout,CreateLabel('Aliased'), 0, 1);
QGridLayout_addWidget(layout,CreateLabel('Antialiased'), 0, 2);
QGridLayout_addWidget(layout,CreateLabel('Int'), 1, 0);
QGridLayout_addWidget(layout,CreateLabel('Float'), 2, 0);
QTimer:=QTimer_create(Self.Handle);
for i:=1 to 2 do
for j:=1 to 2 do
begin
circleWidgets[i][j]:=TCircleWidget.Create(Self);
circleWidgets[i][j].Antialiased := j <> 1;
circleWidgets[i][j].FloatBased := i <> 1;
TimerHook:=QTimer_hook_create(QTimer);
QTimer_hook_hook_timeout(TimerHook, at circleWidgets[i][j].NextAnimationFrame);
QGridLayout_addWidget(layout,circleWidgets[i][j].Handle, i, j);
end;
QTimer_start(QTimer, 100);
QWidget_setLayout(Handle,layout);
w:='Concentric Circles';
QWidget_setWindowTitle(Handle, at w);
QWidget_resize(Handle,600,600);
QWidget_show(Handle);
end;
//===============================================
function TMainForm.CreateLabel (s : WideString) : QLabelH;
begin
Result := QLabel_create(@s);
QLabel_setAlignment(Result, QtAlignCenter);
QLabel_setMargin(Result, 2);
QFrame_setFrameStyle(Result, Integer(QFrameBox) or Integer(QFrameSunken));
end;
//*******************************************************
// TApplication
//*******************************************************
//===============================================
constructor TApplication.Create;
begin
inherited;
QApplication_Create(@argc,argv);
MainForm:=TMainForm.Create;
QApplication_Exec();
end;
//*******************************************************
// Main
//*******************************************************
begin
writeln('start of program');
TApplication.Create;
writeln('end of program');
end.
On Mon, Feb 1, 2010 at 5:36 PM, zeljko <zeljko at holobit.net> wrote:
> On Monday 01 February 2010 11:41, Nataraj S Narayan wrote:
>> Hi
>>
>> Program received signal SIGSEGV, Segmentation fault.
>> [Switching to Thread 1024 (LWP 495)]
>> 0x00000000 in ?? ()
>> (gdb) bt
>> #0 0x00000000 in ?? ()
>> #1 0x401c0ab4 in QObject_hook::eventFilter () from /usr/lib/libqt4intf.so
>> #2 0x40456424 in QCoreApplicationPrivate::sendThroughObjectEventFilters ()
>> from /usr/armel-311009/lib/libQtCore.so.4
>> #3 0x40721d64 in QApplicationPrivate::notify_helper ()
>> from /usr/armel-311009/lib/libQtGui.so.4
>> #4 0x407243cc in QApplication::notify ()
>> from /usr/armel-311009/lib/libQtGui.so.4
>> #5 0x404560f4 in QCoreApplication::notifyInternal ()
>> from /usr/armel-311009/lib/libQtCore.so.4
>> #6 0x4076334c in QWidget::ensurePolished ()
>> from /usr/armel-311009/lib/libQtGui.so.4
>> #7 0x407633d4 in QWidget::ensurePolished ()
>> from /usr/armel-311009/lib/libQtGui.so.4
>> #8 0x40771d0c in QWidget::setVisible ()
>> from /usr/armel-311009/lib/libQtGui.so.4
>> #9 0x401bff5c in QWidget::show () from /usr/lib/libqt4intf.so
>> #10 0x40116de8 in QWidget_show () from /usr/lib/libqt4intf.so
>> #11 0x0000968c in TMAINFORM__CREATE (vmt=0x37c2c, this=0x5bb4c)
>> at concentric.pas:214
>> #12 0x00009874 in TAPPLICATION__CREATE (vmt=0x37d1c, this=0x4b4fc)
>> at concentric.pas:241
>> #13 0x00009958 in main () at concentric.pas:254
>
> What code is inside concentric.pas ? It seem that widget is trying to set it's
> visiblity inside TMainForm.Create before handle is created or something like
> that. I cannot give you more information without code from concentric.pas.
>
> zeljko
>
> _______________________________________________
> Qt mailing list
> Qt at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/qt
>
More information about the Qt
mailing list