Recent

Author Topic: QT6 and new stuff  (Read 1793 times)

El Salvador

  • Full Member
  • ***
  • Posts: 108
QT6 and new stuff
« on: November 15, 2022, 12:08:08 pm »
Hi,

@zeljko I'm porting my component ASuiteComps in QT6 (precisely global hotkey) and I am seeing that they have removed QX11Extras from QT. In QT5 I needed QX11Info_display, but now I need to use nativeInterface (and QNativeInterface) method from QGuiApplication https://doc-snapshots.qt.io/qt6-dev/qguiapplication.html#nativeInterface(https://code.qt.io/cgit/qt/qtbase.git/commit/?id=f5203eeada83bbe8e316a5188e24636af3e83b09).

I saw that this code is missing in libqt6pas bindings. Is there any hope it could be added?

zeljko

  • Hero Member
  • *****
  • Posts: 1386
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: QT6 and new stuff
« Reply #1 on: November 15, 2022, 12:39:52 pm »
Yes, feel free to create patch

zeljko

  • Hero Member
  • *****
  • Posts: 1386
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: QT6 and new stuff
« Reply #2 on: November 15, 2022, 12:45:37 pm »
hmmmm.....there's warning about QNativeInterface: "Warning: There are no source or binary compatibility guarantees for the native interface APIs, meaning that an application using these interfaces is only guaranteed to work with the Qt version it was developed against."

zeljko

  • Hero Member
  • *****
  • Posts: 1386
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: QT6 and new stuff
« Reply #3 on: November 15, 2022, 01:09:51 pm »
I've added TQtWidgetSet.x11Display:PDisplay
https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/1751d3c2edc6197773d5ad48e1086b238b411613
So, no need to implement risky QNativeInterface.

El Salvador

  • Full Member
  • ***
  • Posts: 108
Re: QT6 and new stuff
« Reply #4 on: November 16, 2022, 02:49:15 pm »
Hey thanks! I should have adapted the code to qt6, but I still have to figure out why the hotkeys only work in the program window and not globally.

Anyway, if I will complete it, is there any hope for including this code (see https://github.com/salvadorbs/AsuiteComps/tree/main/library/platform/unix/QGHotkeyHookPas/src) in libqt5pas & libqt6pas for Lazarus 2.4?

zeljko

  • Hero Member
  • *****
  • Posts: 1386
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: QT6 and new stuff
« Reply #5 on: November 16, 2022, 03:01:56 pm »
That looks interesting, but why include QX11Info and Xlib ?
1.It can work with xcb only included.
2.If it's suposed to work on win32 and mac then ifdefs for platforms should be added, so native events can be passed to the lcl.
3.It's pitty to have keypress only events from nativeevent hook.

El Salvador

  • Full Member
  • ***
  • Posts: 108
Re: QT6 and new stuff
« Reply #6 on: November 16, 2022, 04:46:25 pm »
Indeed, you are right. Unfortunately I am very inexperienced on QT and c(++).

Quote
why include QX11Info and Xlib ?
Removed. Thanks. https://github.com/salvadorbs/AsuiteComps/commit/45f47680f97363d01efea01d5e5bc10ffb2f5b44#diff-da8349f220705517018be2ff4d677f21b2b15a0db3baeb3948b500e70b470c72

Quote
2.If it's suposed to work on win32 and mac then ifdefs for platforms should be added, so native events can be passed to the lcl.
I would like to, but I don't have the time and knowledge to expand on windows & mac. Also, for my software, I only needed the Linux & QT combination (on windows, I use the win32 widgetset) and capture global hotkey.

Quote
3.It's pitty to have keypress only events from nativeevent hook.
What other events were you thinking about?
« Last Edit: November 16, 2022, 04:48:50 pm by El Salvador »

zeljko

  • Hero Member
  • *****
  • Posts: 1386
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: QT6 and new stuff
« Reply #7 on: November 16, 2022, 05:01:08 pm »
Actually, you're grabbing only keyPress event on xcb...why not other events if nativeeventfilter hook is installed ?

El Salvador

  • Full Member
  • ***
  • Posts: 108
Re: QT6 and new stuff
« Reply #8 on: November 16, 2022, 05:26:38 pm »
For global hotkey, you need only key press event (XCB_KEY_PRESS). Maybe you mean it's better to bring the event to pascal and handle it via LCL?

zeljko

  • Hero Member
  • *****
  • Posts: 1386
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: QT6 and new stuff
« Reply #9 on: November 16, 2022, 05:34:11 pm »
Yes, not only key events, but others to, just pass native event to lcl and handle it there.

El Salvador

  • Full Member
  • ***
  • Posts: 108
Re: QT6 and new stuff
« Reply #10 on: November 16, 2022, 06:20:31 pm »
Ok, now I understand what you meant. But in this case, I wouldn't know how to translate the actual C code into pascal.

Code: [Select]
        auto *genericEvent = static_cast<xcb_generic_event_t *>(message);

        //Pass to FPC only XCB_KEY_PRESS
        if (genericEvent->response_type == XCB_KEY_PRESS) {
          Q_GHotkey_hook* sender = this;

          // Pass keyCode and Modifiers to FPC
          xcb_key_press_event_t *keyEvent = static_cast<xcb_key_press_event_t *>(message);
          uint8_t keyCode = (uint8_t) keyEvent->detail;
          uint16_t keyState = (uint8_t) keyEvent->state;
And pass eventType as QByteArray and message as ? in lcl?

zeljko

  • Hero Member
  • *****
  • Posts: 1386
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: QT6 and new stuff
« Reply #11 on: November 16, 2022, 11:07:26 pm »
See here about static_cast, reinterpret_cast and dynamic_cast ...
https://stackoverflow.com/questions/52648049/what-is-the-equivalent-of-dynamic-cast-in-delphi
you need translation of xcb headers and event structs

El Salvador

  • Full Member
  • ***
  • Posts: 108
Re: QT6 and new stuff
« Reply #12 on: November 18, 2022, 05:26:37 pm »
Done. See commit https://github.com/salvadorbs/AsuiteComps/commit/d87adccddc90be486ccac9a8b547301c8760f511

Anyway for a reason I still don't understand, the key_press_event event is not caught by the nativeEventFilter when the program has no focus in qt6 (in qt5, it works everywhere). Between qt5 and qt6, only how the display is retrieved changes. I will continue to investigate.

zeljko

  • Hero Member
  • *****
  • Posts: 1386
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: QT6 and new stuff
« Reply #13 on: November 18, 2022, 07:36:44 pm »
Probably you (me) should get Display from xcb_get_connection() and then see what happens.
EDIT: should be xcb_connect() to get xcb_connection structure but I'm wrong about it - you cannot get Display from xcb_connection_t.
XOpenDisplay() is used only if we mix xlib and xcb calls. So, xcb_connect() is proper way to get connection and then use it  in all xcb functions.
« Last Edit: November 18, 2022, 07:43:50 pm by zeljko »

El Salvador

  • Full Member
  • ***
  • Posts: 108
Re: QT6 and new stuff
« Reply #14 on: November 28, 2022, 12:45:10 am »
Nothing. All my attempts with xcb have failed. When I have focus on a different window than my lcl program, the lib doesn't catch the xcb_key_press event. This only in qt6. Quite strange.

 

TinyPortal © 2005-2018