Recent

Author Topic: SIGSEGV in dynamic library with widgetsets QT5/6  (Read 818 times)

7bit

  • New Member
  • *
  • Posts: 24
SIGSEGV in dynamic library with widgetsets QT5/6
« on: October 15, 2025, 09:55:39 pm »
If unit "Interface" used in the dynamic library, a SIGSEGV error occurs when unloading the library. Moreover, the error occurs if you load the library dynamically with the LoadLibrary function. Most likely, there is a failure in unit "Interface" when calling FreeWidgetset in the finalization section. There is no such problem with GTK2 and Win32 widgets. I made an example. Even the simplest library causes a crash. What could be the problem?

Lazarus 4.3 (rev lazarus_4_2-26-g44b59001af) FPC 3.2.3 x86_64-linux-qt5

qt5pas version 2.16.4
« Last Edit: October 16, 2025, 06:09:45 am by 7bit »

7bit

  • New Member
  • *
  • Posts: 24
Re: SIGSEGV in dynamic library with widgetsets QT5/6
« Reply #1 on: October 16, 2025, 07:58:43 am »
The queue doesn't even reach FreeWidgetSet. The error occurs when calling QWidget_WindowTitle(Widget, Str). And if you try to skip this call by adding TQtMainWindow.getText Exit(") to the method, then the error occurs already in QWidget_hide(Widget).

If you link the library to the program statically (via external) without calling LoadLibrary, then everything works fine.

7bit

  • New Member
  • *
  • Posts: 24
Re: SIGSEGV in dynamic library with widgetsets QT5/6
« Reply #2 on: October 17, 2025, 09:16:43 am »
I started looking for what in the "Interface" module could be the source of the error. I did all the manipulations for the dynamic library, but the code in the application itself remained unchanged. First, in this module, I commented out the lines in the initialization and finalization sections - there was an error anyway. Eventually I got to the qt56 module and in it I commented out the initPWideStrings call. As a result, the test application with LoadLibrary and FreeLibrary calls terminated without errors.  Interestingly, now when linking the library statically, an error began to occur when launching the application: The Project1 project called the exception class 'External: SIGSEGV'. I'm at a loss.

cdbc

  • Hero Member
  • *****
  • Posts: 2466
    • http://www.cdbc.dk
Re: SIGSEGV in dynamic library with widgetsets QT5/6
« Reply #3 on: October 17, 2025, 09:33:55 am »
Hi
It gets worse with Qt6. Below is the output in a terminal, when I run one of my test-apps from there:
Code: Bash  [Select][+][-]
  1. bc@red svc-view-via-plim [test]$ ./testplimview
  2. QObject::installEventFilter(): Cannot filter events for objects in a different thread.
  3. QObject: Cannot create children for a parent that is in a different thread.
  4. (Parent is QClipboard(0x1643cf0), parent's thread is QThread(0x145ebd0), current thread is QThread(0x7f023c003b00)
  5. QObject::startTimer: Timers can only be used with threads started with QThread
  6. QObject::installEventFilter(): Cannot filter events for objects in a different thread.
  7. Segmentfejl                ./testplimview
  8. bc@red svc-view-via-plim [test]$
  9.  
I haven't fiddled with the code in qt62pas.
Run from the GUI I don't see these errors / hints...
Quote
Eventually I got to the qt56 module and in it I commented out the initPWideStrings call.
I don't think you can do that, because Qt uses unicodestrings and, at least, on Linux it needs a 'unicode-/widestring manager'...
Let's just hope @Zeljko sees this thread, as he is the maintainer of QtPasxxx
Regards Benny
« Last Edit: October 17, 2025, 09:36:21 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6 -> FPC 3.2.2 -> Lazarus 4.0 up until Jan 2025 from then on it's both above &: KDE6/QT6 -> FPC 3.3.1 -> Lazarus 4.99

7bit

  • New Member
  • *
  • Posts: 24
Re: SIGSEGV in dynamic library with widgetsets QT5/6
« Reply #4 on: October 17, 2025, 10:59:43 am »
I don't think you can do that, because Qt uses unicodestrings and, at least, on Linux it needs a 'unicode-/widestring manager'...

Yes, I understand that. I just hope this helps @Zeljko find the problem.

zeljko

  • Hero Member
  • *****
  • Posts: 1792
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: SIGSEGV in dynamic library with widgetsets QT5/6
« Reply #5 on: October 17, 2025, 02:36:16 pm »
Sorry, no free time atm , and won't have any free time next 4-5 months :(

Thaddy

  • Hero Member
  • *****
  • Posts: 18344
  • Here stood a man who saw the Elbe and jumped it.
Re: SIGSEGV in dynamic library with widgetsets QT5/6
« Reply #6 on: October 17, 2025, 02:54:08 pm »
@cdbc
initPWideStrings  looks like initPWideChars in this context: and these are not refcounted so do not need a widestring manager. I am also under the impression that Qt does its own memory management internally.
If Qt expects aligned access (which it does) the most likely cause is an alignment issue. Alignment should be 16 bytes I believe.(not bits)
« Last Edit: October 17, 2025, 02:56:42 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

cdbc

  • Hero Member
  • *****
  • Posts: 2466
    • http://www.cdbc.dk
Re: SIGSEGV in dynamic library with widgetsets QT5/6
« Reply #7 on: October 17, 2025, 03:20:36 pm »
Hi
I'm not fiddling with Qt62pas -- at all!
...But I get these hints (and 1 error on shutdown) only when I run a GUI-app from commandline.
...But2 it's only when the app in question loads /nasty/ plugins containing Qt-gui-stuff in one thread for use in another thread and finally being free'd by the main-thread  O:-) :D
In a purely commandline app, there are only the timers "Shenanigans" and they don't bother me...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6 -> FPC 3.2.2 -> Lazarus 4.0 up until Jan 2025 from then on it's both above &: KDE6/QT6 -> FPC 3.3.1 -> Lazarus 4.99

cdbc

  • Hero Member
  • *****
  • Posts: 2466
    • http://www.cdbc.dk
Re: SIGSEGV in dynamic library with widgetsets QT5/6
« Reply #8 on: October 22, 2025, 04:30:16 pm »
Hi
@zeljko: attached is a screenshot of Qt6 whining at application shutdown...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6 -> FPC 3.2.2 -> Lazarus 4.0 up until Jan 2025 from then on it's both above &: KDE6/QT6 -> FPC 3.3.1 -> Lazarus 4.99

 

TinyPortal © 2005-2018