Qt: Fixed segfault in destroying form handle when form is child of another control.Fixed segfault in TQtListStrings.Clear() - we must check here if handle exist since Clear is called when control is destroyed.Introduced TQtComboBox.ClearItems, TQtListWidget.ClearItems for faster deletion of items in TQtListStrings and TQtComboStrings.

git-svn-id: trunk@24088 -
This commit is contained in:
zeljko 2010-03-18 19:12:41 +00:00
parent e9613684e0
commit 2307785cf3
3 changed files with 49 additions and 12 deletions

View File

@ -402,24 +402,24 @@ end;
procedure TQtComboStrings.Put(Index: Integer; const S: string); procedure TQtComboStrings.Put(Index: Integer; const S: string);
begin begin
FOwner.BeginUpdate;
inherited Put(Index, S); inherited Put(Index, S);
FOwner.BeginUpdate;
FOwner.setItemText(Index, S); FOwner.setItemText(Index, S);
FOwner.EndUpdate; FOwner.EndUpdate;
end; end;
procedure TQtComboStrings.InsertItem(Index: Integer; const S: string); procedure TQtComboStrings.InsertItem(Index: Integer; const S: string);
begin begin
FOwner.BeginUpdate;
inherited InsertItem(Index, S); inherited InsertItem(Index, S);
FOwner.BeginUpdate;
FOwner.insertItem(Index, S); FOwner.insertItem(Index, S);
FOwner.EndUpdate; FOwner.EndUpdate;
end; end;
procedure TQtComboStrings.InsertItem(Index: Integer; const S: string; O: TObject); procedure TQtComboStrings.InsertItem(Index: Integer; const S: string; O: TObject);
begin begin
FOwner.BeginUpdate;
inherited InsertItem(Index, S, O); inherited InsertItem(Index, S, O);
FOwner.BeginUpdate;
FOwner.insertItem(Index, S); FOwner.insertItem(Index, S);
FOwner.EndUpdate; FOwner.EndUpdate;
end; end;
@ -443,17 +443,21 @@ var
C: Integer; C: Integer;
begin begin
C := Count; C := Count;
FOwner.BeginUpdate;
inherited Clear; inherited Clear;
for I := C - 1 downto 0 do
FOwner.removeItem(I); if Assigned(FOwner.LCLObject) and
FOwner.EndUpdate; (FOwner.LCLObject.HandleAllocated) then
begin
FOwner.BeginUpdate;
FOwner.ClearItems;
FOwner.EndUpdate;
end;
end; end;
procedure TQtComboStrings.Delete(Index: Integer); procedure TQtComboStrings.Delete(Index: Integer);
begin begin
FOwner.BeginUpdate;
inherited Delete(Index); inherited Delete(Index);
FOwner.BeginUpdate;
FOwner.removeItem(Index); FOwner.removeItem(Index);
FOwner.EndUpdate; FOwner.EndUpdate;
end; end;
@ -462,8 +466,8 @@ procedure TQtComboStrings.Sort;
var var
I: Integer; I: Integer;
begin begin
FOwner.BeginUpdate;
inherited Sort; inherited Sort;
FOwner.BeginUpdate;
for I := 0 to Count - 1 do for I := 0 to Count - 1 do
FOwner.setItemText(I, Strings[I]); FOwner.setItemText(I, Strings[I]);
FOwner.EndUpdate; FOwner.EndUpdate;
@ -473,8 +477,8 @@ procedure TQtComboStrings.Exchange(AIndex1, AIndex2: Integer);
var var
i: Integer; i: Integer;
begin begin
FOwner.BeginUpdate;
inherited Exchange(AIndex1, AIndex2); inherited Exchange(AIndex1, AIndex2);
FOwner.BeginUpdate;
for I := 0 to Count - 1 do for I := 0 to Count - 1 do
FOwner.setItemText(I, Strings[I]); FOwner.setItemText(I, Strings[I]);
FOwner.EndUpdate; FOwner.EndUpdate;
@ -521,8 +525,14 @@ var
begin begin
C := Count; C := Count;
inherited Clear; inherited Clear;
for I := C - 1 downto 0 do
FOwner.removeItem(I); if Assigned(FOwner.LCLObject) and
(FOwner.LCLObject.HandleAllocated) then
begin
FOwner.BeginUpdate;
FOwner.ClearItems;
FOwner.EndUpdate;
end;
end; end;
procedure TQtListStrings.Delete(Index: Integer); procedure TQtListStrings.Delete(Index: Integer);

View File

@ -759,6 +759,7 @@ type
public public
FList: TStrings; FList: TStrings;
destructor Destroy; override; destructor Destroy; override;
procedure ClearItems;
procedure setBorder(const ABorder: Boolean); procedure setBorder(const ABorder: Boolean);
function currentIndex: Integer; function currentIndex: Integer;
function getEditable: Boolean; function getEditable: Boolean;
@ -952,6 +953,7 @@ type
procedure signalSelectionChanged(); cdecl; procedure signalSelectionChanged(); cdecl;
procedure ItemDelegatePaint(painter: QPainterH; option: QStyleOptionViewItemH; index: QModelIndexH); cdecl; override; procedure ItemDelegatePaint(painter: QPainterH; option: QStyleOptionViewItemH; index: QModelIndexH); cdecl; override;
public public
procedure ClearItems;
function currentRow: Integer; function currentRow: Integer;
function IndexAt(APoint: PQtPoint): Integer; function IndexAt(APoint: PQtPoint): Integer;
procedure insertItem(AIndex: Integer; AText: String); overload; procedure insertItem(AIndex: Integer; AText: String); overload;
@ -6493,6 +6495,11 @@ begin
inherited Destroy; inherited Destroy;
end; end;
procedure TQtComboBox.ClearItems;
begin
QComboBox_clear(QComboBoxH(Widget));
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: TQtComboBox.currentIndex Function: TQtComboBox.currentIndex
Params: None Params: None
@ -7512,6 +7519,11 @@ begin
TQtDeviceContext(DrawStruct.DC).Free; TQtDeviceContext(DrawStruct.DC).Free;
end; end;
procedure TQtListWidget.ClearItems;
begin
QListWidget_clear(QListWidgetH(Widget));
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: TQtListWidget.currentRow Function: TQtListWidget.currentRow
Params: None Params: None

View File

@ -80,6 +80,7 @@ type
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure CloseModal(const ACustomForm: TCustomForm); override; class procedure CloseModal(const ACustomForm: TCustomForm); override;
class procedure DestroyHandle(const AWinControl: TWinControl); override;
class procedure SetAllowDropFiles(const AForm: TCustomForm; AValue: Boolean); override; class procedure SetAllowDropFiles(const AForm: TCustomForm; AValue: Boolean); override;
class procedure SetFormBorderStyle(const AForm: TCustomForm; const AFormBorderStyle: TFormBorderStyle); override; class procedure SetFormBorderStyle(const AForm: TCustomForm; const AFormBorderStyle: TFormBorderStyle); override;
class procedure SetFormStyle(const AForm: TCustomform; const AFormStyle: TFormStyle); override; class procedure SetFormStyle(const AForm: TCustomform; const AFormStyle: TFormStyle); override;
@ -207,6 +208,20 @@ begin
inherited CloseModal(ACustomForm); inherited CloseModal(ACustomForm);
end; end;
class procedure TQtWSCustomForm.DestroyHandle(const AWinControl: TWinControl);
var
w: TQtWidget;
begin
w := TQtWidget(AWinControl.Handle);
{forms which have another widget as parent
eg.form inside tabpage or mdichilds
can segfault without hiding before release.
So we save our day here.}
if w.getVisible and (w.getParent <> nil) then
w.Hide;
w.Release;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TQtWSCustomForm.SetAllowDropFiles Method: TQtWSCustomForm.SetAllowDropFiles
Params: Params: