Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / qt / 2007-08

QListView_indexAt and QAbstractItemModel_index

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Павел Ишенин

Hello, Items specific to the Qt widget set

Is it ok to write such contructions:

function TQtListWidget.IndexAt(APoint: PQtPoint): Integer;
var
  AModelIndex: QModelIndexH;
begin
  AModelIndex := QModelIndex_create();
  QListView_indexAt(QListWidgetH(Widget), AModelIndex, APoint);
  Result := QModelIndex_row(AModelIndex);
end;
I mean such will be better:
  AModelIndex := QListView_indexAt(QListWidgetH(Widget), APoint);
  Result := QModelIndex_row(AModelIndex);

Maybe I misunderstand something?

Best regards,
Paul Ishenin.

Den Jean
to Павел Ишенин
????? ?????? wrote 18 lines
Hello, Items specific to the Qt widget set Is it ok to write such contructions: function TQtListWidget.IndexAt(APoint: PQtPoint): Integer; var AModelIndex: QModelIndexH; begin AModelIndex := QModelIndex_create(); QListView_indexAt(QListWidgetH(Widget), AModelIndex, APoint); Result := QModelIndex_row(AModelIndex); end; I mean such will be better: AModelIndex := QListView_indexAt(QListWidgetH(Widget), APoint); Result := QModelIndex_row(AModelIndex); Maybe I misunderstand something?

When a function result is a Qt Class without a "*" (so not a pointer to a class instance), you are not supposed to keep it around. In C++ you would immediately assign it (copy into) another c++ class instance. The c++ compiler knows how. The pascal compiler does not know how to copy an instance into another. The binding could return a pointer to the instance, but would the violate the c++ header. Therefore I chose to make all Qt Classes function results (without *), parameters instead, and let the c++ compiler do the copying inside the binding. You have to create an instance ofcourse.

C++:
void test {
QModelIndex model; // -> instantiate instance on stack model = SomeAbstractItemView->indexAt(somePoint); // c++ does the copying } // --> model get destroyed from stack by compiler

pascal:
procedure test;
begin
var model QModelIndexH;
model:=QModelIndex_create;// -> instantiate instance on stack
AbstractItemView_indexAt(SomeAbstractItemView,model,somePoint);  // c++ does the copying in the binding.
QModelIndex_destroy(model);  // you have to destroy manually
end;

I you prefer me not doing this, we can try to revert and see what happens. I am not sure this was necessary.

Show quoted text 6 lines
Best regards, Paul Ishenin. _______________________________________________ Qt mailing list http://www.lazarus.freepascal.org/mailman/listinfo/qt
Павел Ишенин
to Den Jean: When a function result is a Qt Class without a "*" (so not a pointer to a class…
Den Jean wrote 50 lines
On Tuesday 28 August 2007 19:47:24 ????? ?????? wrote: > Hello, Items specific to the Qt widget set > > Is it ok to write such contructions: > > function TQtListWidget.IndexAt(APoint: PQtPoint): Integer; > var > AModelIndex: QModelIndexH; > begin > AModelIndex := QModelIndex_create(); > QListView_indexAt(QListWidgetH(Widget), AModelIndex, APoint); > Result := QModelIndex_row(AModelIndex); > end; > > I mean such will be better: > AModelIndex := QListView_indexAt(QListWidgetH(Widget), APoint); > Result := QModelIndex_row(AModelIndex); > > Maybe I misunderstand something? > When a function result is a Qt Class without a "*" (so not a pointer to a class instance), you are not supposed to keep it around. In C++ you would immediately assign it (copy into) another c++ class instance. The c++ compiler knows how. The pascal compiler does not know how to copy an instance into another. The binding could return a pointer to the instance, but would the violate the c++ header. Therefore I chose to make all Qt Classes function results (without *), parameters instead, and let the c++ compiler do the copying inside the binding. You have to create an instance ofcourse. C++: void test { QModelIndex model; // -> instantiate instance on stack model = SomeAbstractItemView->indexAt(somePoint); // c++ does the copying } // --> model get destroyed from stack by compiler pascal: procedure test; begin var model QModelIndexH; model:=QModelIndex_create;// -> instantiate instance on stack AbstractItemView_indexAt(SomeAbstractItemView,model,somePoint); // c++ does the copying in the binding. QModelIndex_destroy(model); // you have to destroy manually end; I you prefer me not doing this, we can try to revert and see what happens. I am not sure this was necessary.

No need for revert. I added destroy calls after that. Thanks.

Best regards,
Paul Ishenin.