Recent

Author Topic: Works on GTK2 but not qt  (Read 10100 times)

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Works on GTK2 but not qt
« on: January 19, 2016, 10:59:49 pm »
System: i7 PC running Linux Mint 17.3 and Lazarus 1.4.4. I found this problem in a larger application that I reduced to isolate the problem.

The attached demo works on GTK2 but not qt.

Run the attached demo in both GTK2 and qt, changing the compilation directive from GTK2 to qt. When the toggle-button is clicked the contents of both the combo-box and the image above the button should change.

Recompile with qt, and only the combo-box contents will change.

The problem also occurred when the application was compiled with a recent trunk version. A compilation error was shown, but the program ran despite the errors, which may be a pointer to the root cause. It presumably also happens in Laz 1.6.

If someone can confirm the above, I will enter it in the bug tracker.



« Last Edit: January 20, 2016, 11:47:19 am by Windsurfer »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Works on GTK2 but not qt
« Reply #1 on: January 19, 2016, 11:41:30 pm »
Wigetsets differ. I notice it whenever I design EC-Controls. Gtk2 can call Invalidate; in certain situation (resizing or so) where Qt doesn't (and oppositely).

Just add
Code: Pascal  [Select][+][-]
  1. Shape1.Invalidate;
after Shape1Paint().
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Works on GTK2 but not qt [Solved]
« Reply #2 on: January 20, 2016, 10:35:30 am »
Thanks Blazen,

It worked perfectly. I spent many hours searching for a solution. I have become used to not having to use invalidate, so will remember it.

In trunk there was still a compile time divide by zero error, so I'll download the latest and test it.

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Works on GTK2 but not qt [Solved]
« Reply #3 on: January 20, 2016, 11:46:41 am »
After adding Shape1.Invalidate in the current trunk it gives (in Linux Mint 17.3 with qt) the following error:

Quote
Project project1 raised exception class 'External: SIGFPE'.

 In file 'lclproc.pas' at line 902:
if (length(Msg) div (length(Msg) div 10000))=0 then ;

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Works on GTK2 but not qt [Solved]
« Reply #4 on: January 20, 2016, 12:24:17 pm »
In file 'lclproc.pas' at line 902:
if (length(Msg) div (length(Msg) div 10000))=0 then ;

That is the RaiseGDBException procedure meant for helping GDB to catch FPC exceptions.
You need the whole GDB backtrace instead.

I think this should be reported if no easy workaround is found.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Works on GTK2 but not qt
« Reply #5 on: January 20, 2016, 12:58:57 pm »
Thanks Juha,

I'll have a poke around. I'm not familiar with using backtraces, but will be soon.

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Works on GTK2 but not qt
« Reply #6 on: January 20, 2016, 01:14:28 pm »
System: i7 PC running Linux Mint 17.3 and Lazarus 1.4.4. I found this problem in a larger application that I reduced to isolate the problem.

The attached demo works on GTK2 but not qt.

Run the attached demo in both GTK2 and qt, changing the compilation directive from GTK2 to qt. When the toggle-button is clicked the contents of both the combo-box and the image above the button should change.

Recompile with qt, and only the combo-box contents will change.

The problem also occurred when the application was compiled with a recent trunk version. A compilation error was shown, but the program ran despite the errors, which may be a pointer to the root cause. It presumably also happens in Laz 1.6.

If someone can confirm the above, I will enter it in the bug tracker.

By calling ShapePaint(Self) in ToggleBox1Click you're painting outside of paint event, so that's problem with Qt, Carbon and Cocoa.
Comment ShapePaint() in ToggleBox1Click and add Shape1.Invalidate, in Shape1.OnPaint use code from ShapePaint().
Your code works on gtk2 and win32 since they support painting outside of paint event.

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Works on GTK2 but not qt
« Reply #7 on: January 20, 2016, 02:14:49 pm »
Thanks Zeljko.

I'll do that and report back.

I just downloaded the latest trunk from getlazarus. The existing code now crashes lazarus/startlazarus when recompiling for the qt widget set.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Works on GTK2 but not qt
« Reply #8 on: January 20, 2016, 02:31:25 pm »
By calling ShapePaint(Self) in ToggleBox1Click you're painting outside of paint event, so that's problem with Qt, Carbon and Cocoa.
Comment ShapePaint() in ToggleBox1Click and add Shape1.Invalidate, in Shape1.OnPaint use code from ShapePaint().
Your code works on gtk2 and win32 since they support painting outside of paint event.

Right, I should have looked at the code properly at once. Painting outside OnPaint event is a common error. Many bug reports have been opened because of it.
This limitation just has to be advertised more I guess.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Works on GTK2 but not qt
« Reply #9 on: January 20, 2016, 04:40:47 pm »
Quote
By calling ShapePaint(Self) in ToggleBox1Click you're painting outside of paint event, so that's problem with Qt, Carbon and Cocoa.
Comment ShapePaint() in ToggleBox1Click and add Shape1.Invalidate, in Shape1.OnPaint use code from ShapePaint().
Your code works on gtk2 and win32 since they support painting outside of paint event.

Interesting, because here it works with Qt too, without any crash.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Works on GTK2 but not qt
« Reply #10 on: January 20, 2016, 07:43:08 pm »
Quote
By calling ShapePaint(Self) in ToggleBox1Click you're painting outside of paint event, so that's problem with Qt, Carbon and Cocoa.
Comment ShapePaint() in ToggleBox1Click and add Shape1.Invalidate, in Shape1.OnPaint use code from ShapePaint().
Your code works on gtk2 and win32 since they support painting outside of paint event.

It works perfectly in 1.4.4. The problems in trunk are unrelated.

The
Code: Pascal  [Select][+][-]
  1. Shape1.Invalidate;
code can be placed at either end of the Shape1Paint event and it works equally well.

I'll look through the wiki for somewhere to make a note about it.

Thanks for the help and education.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Works on GTK2 but not qt
« Reply #11 on: January 20, 2016, 08:58:08 pm »
The
Code: Pascal  [Select][+][-]
  1. Shape1.Invalidate;
code can be placed at either end of the Shape1Paint event and it works equally well.

No, the OnPaint method should not have a Shape1.Invalidate call. The button click handler can have it, but most likely it is not needed.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Works on GTK2 but not qt
« Reply #12 on: January 20, 2016, 10:08:23 pm »
It works without the Invalidate anywhere.

I have added an item to the wiki at:
http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Common_OnPaint_Error

Please edit as you feel necessary.

 

TinyPortal © 2005-2018