#include #include #include #include #include #include "qt_dialog.h" #include #include #include // 全局 Qt 对话框指针 QtDialog *g_dialog = nullptr; // 每次 Motif 回调中处理 Qt 事件 void processQtEvents() { auto app = QApplication::instance(); if (app) { app->processEvents(); // 处理 Qt 事件,不阻塞 } } // 回调函数:点击按钮弹出 Qt Dialog void openQtDialog(Widget w, XtPointer client_data, XtPointer call_data) { auto app = QApplication::instance(); int argc = 0; if (!app) { app = new QApplication(argc, nullptr); } if (!g_dialog) { g_dialog = new QtDialog(); } g_dialog->show(); // 非阻塞显示 } int main(int argc, char **argv) { XtAppContext app_context; Widget toplevel, button; toplevel = XtVaAppInitialize(&app_context, "MotifQtApp", NULL, 0, &argc, argv, NULL, NULL); button = XtVaCreateManagedWidget("Open Qt Dialog", xmPushButtonWidgetClass, toplevel, NULL); XtAddCallback(button, XmNactivateCallback, openQtDialog, NULL); XtRealizeWidget(toplevel); // Motif 主循环中周期性处理 Qt 事件 while (1) { while (XtAppPending(app_context)) { XEvent event; XtAppNextEvent(app_context, &event); XtDispatchEvent(&event); } processQtEvents(); // 处理 Qt 事件 usleep(1000); // 避免 CPU 空转 } return 0; }