简体   繁体   中英

How can I integrate new Qt windows with an existing X application?

I have an existing (large) X application based on raw XLib. I would like to add additional windows to this application using Qt 4. What is the best way to do this?

Research so far:

(If it matters for the details, I'm looking at Qt 4.7.4 right now.)

My existing application calls XtAppNextEvent in a loop to handle its events. What I am hoping to do is replace this event loop with a Qt-based event loop, let Qt handle its own events, and make calls to XtDispatchEvent for non-Qt events.

I have located the part of Qt that processes X events (in src/gui/kernel/qapplication_x11.cpp , QApplication::x11ProcessEvent ). I believe the key part of this function is:

QETWidget *widget = (QETWidget*)QWidget::find((WId)event->xany.window);

which determines whether the event refers to a window that Qt knows about. For non-Qt windows, this returns NULL . There are a couple of processing exceptions after this, then a block like:

if (!widget) {                     // don't know this windows
    QWidget *popup = QApplication::activePopupWidget();
    if (popup) {
        // ... bunch of stuff not involving widget ...
    }
    return -1;
}

What I was hoping was there would be an event callback at this point that was called for non-Qt related window events, so I could simply implement a virtual function in my derived QApplication and proceed with the application's existing event processing. I can add such a function and rebuild Qt, but I would rather avoid that if possible.

Am I on the right track with this, or might there be a better way?

I have found existing questions similar to this, but they're all for Windows (MFC or .NET). This is specific to X.

The solution I ended up with was to find a copy of the Qt Motif Extension (it's no longer available from Digia directly as it is now unsupported, but you can still find copies of qtmotifextension-2.7-opensource.zip ). In there, the qtmotif.h and qtmotif.cpp modules show how to create a QAbstractEventDispatcher that handles X events for both Xt/Motif and Qt components.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM