Sign in Join

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

Mailing lists / lazarus / 2017-12

Qt Ws doesn't support properly GetWindowSize() and GetWindowRect()

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Giuliano Colla

This snippet of code, which executes as expected with GTK2 WS, fails with QT WS:

Show quoted text 16 lines
procedure TForm1.btnWsizeClick(Sender: TObject); var  aHandle: THandle;   aWidth,aHeight: Integer;   aRect: TRect; begin   aHandle:= Form1.Handle;   if GetWindowSize(aHandle,aWidth,aHeight) then begin     Label3.Caption:= Format('Width: %d Height: %d',[aWidth,aHeight]);   end   else Label3.Caption:= 'Failed to get Window Size';   GetWindowRect(aHandle,aRect);   Label3.Caption:= Label3.Caption + Format(' Rect: %d,%d',[   aRect.Right-aRect.Left,   aRect.Bottom-aRect.Top]);   Label3.Visible:= True; end;

As it is, it crashes with an AV in the GetWindowSize call. The failing call is in TQtWidget.GetWidget: it executes Result := QWidgetH(TheObject) where TheObject appears to have taken a bogus value.

If I remove the offending call, then the subsequent GetWindowRect() returns bogus values, sort of -32704 and -85984614 instead of 689 and 522.

Under GTK2 both calls work as expected.

Tested under Linux x86_64 (CentOs 6) with Lazarus 1.8 - QT45 - fpc 3.0.4

It doesn't appear to be a regression, because it does the same even with a very old Lazarus 1.2.6 , qt45 and fpc 2.6.4

Should I report a bug or is it a known issue?

Giuliano

Reply by email

zeljko
to Giuliano Colla
Giuliano Colla wrote 35 lines
This snippet of code, which executes as expected with GTK2 WS, fails with QT WS: > procedure TForm1.btnWsizeClick(Sender: TObject); > var  aHandle: THandle; >    aWidth,aHeight: Integer; >    aRect: TRect; > begin >    aHandle:= Form1.Handle; >    if GetWindowSize(aHandle,aWidth,aHeight) then begin >      Label3.Caption:= Format('Width: %d Height: %d',[aWidth,aHeight]); >    end >    else Label3.Caption:= 'Failed to get Window Size'; >    GetWindowRect(aHandle,aRect); >    Label3.Caption:= Label3.Caption + Format(' Rect: %d,%d',[ >    aRect.Right-aRect.Left, >    aRect.Bottom-aRect.Top]); >    Label3.Visible:= True; > end; As it is, it crashes with an AV in the GetWindowSize call. The failing call is in TQtWidget.GetWidget: it executes Result := QWidgetH(TheObject) where TheObject appears to have taken a bogus value. If I remove the offending call, then the subsequent GetWindowRect() returns bogus values, sort of -32704 and -85984614 instead of 689 and 522. Under GTK2 both calls work as expected. Tested under Linux x86_64 (CentOs 6) with Lazarus 1.8 - QT45 - fpc 3.0.4 It doesn't appear to be a regression, because it does the same even with a very old Lazarus 1.2.6 , qt45 and fpc 2.6.4 Should I report a bug or is it a known issue?

Of course, please do so, also attach example.

zeljko

Reply by email

zeljko
to Giuliano Colla: This snippet of code, which executes as expected with GTK2 WS, fails with QT WS: As it…
Giuliano Colla wrote 35 lines
This snippet of code, which executes as expected with GTK2 WS, fails with QT WS: > procedure TForm1.btnWsizeClick(Sender: TObject); > var  aHandle: THandle; >    aWidth,aHeight: Integer; >    aRect: TRect; > begin >    aHandle:= Form1.Handle; >    if GetWindowSize(aHandle,aWidth,aHeight) then begin >      Label3.Caption:= Format('Width: %d Height: %d',[aWidth,aHeight]); >    end >    else Label3.Caption:= 'Failed to get Window Size'; >    GetWindowRect(aHandle,aRect); >    Label3.Caption:= Label3.Caption + Format(' Rect: %d,%d',[ >    aRect.Right-aRect.Left, >    aRect.Bottom-aRect.Top]); >    Label3.Visible:= True; > end; As it is, it crashes with an AV in the GetWindowSize call. The failing call is in TQtWidget.GetWidget: it executes Result := QWidgetH(TheObject) where TheObject appears to have taken a bogus value. If I remove the offending call, then the subsequent GetWindowRect() returns bogus values, sort of -32704 and -85984614 instead of 689 and 522. Under GTK2 both calls work as expected. Tested under Linux x86_64 (CentOs 6) with Lazarus 1.8 - QT45 - fpc 3.0.4 It doesn't appear to be a regression, because it does the same even with a very old Lazarus 1.2.6 , qt45 and fpc 2.6.4 Should I report a bug or is it a known issue?

It's bug in your code (range error). You're using aHandle: System.THandle (longint) instead of LCLIntf.THandle which is of ptruint type.
Best and correct usage would be to use HWND type which is what it needs to be on all platforms and widgetsets.
When aHandle type is corrected, or LCLType is included with it's THandle then everything works as expected.
Don't ask me my gtk2 works, in any case it's wrong on 64bit platform.

zeljko

Reply by email

Giuliano Colla
to zeljko

Il 15/12/2017 18:30, zeljko ha scritto:

Show quoted text 8 lines
It's bug in your code (range error). You're using aHandle: System.THandle (longint) instead of LCLIntf.THandle which is of ptruint type. Best and correct usage would be to use HWND type which is what it needs to be on all platforms and widgetsets. When aHandle type is corrected, or LCLType is included with it's THandle then everything works as expected. Don't ask me my gtk2 works, in any case it's wrong on 64bit platform.

Thanks a lot. With the proper type of aHandle it works fine both with Qt and GTk2.

Maybe it was working with gtk2 because there's an additional check on handle validity but I didn't investigate further. A bug of mine is a bug of mine.

Giuliano

Reply by email