Qt和手动输入事件

时间:2018-01-05 10:17:34

标签: c++ multithreading qt

我正在尝试处理手动创建的输入事件,如下所示:

 class WebView : public QWebView {
     Q_OBJECT
 public:
 ...
     Q_INVOKABLE bool ProcessEvent(QEvent *ev) {
         bool res = this->event(ev);
         delete ev;
         return res;
     }
 ...
 };

从另一个线程发送它:

QEvent *ev = new QMouseEvent{ QEvent::MouseMove, { msg->x, msg->y }, Qt::NoButton, Qt::NoButton, Qt::NoModifier };
QMetaObject::invokeMethod(web_view_, "ProcessEvent", Qt::QueuedConnection, Q_ARG(QEvent *, ev));

它在Windows上工作正常,但是在几十个事件之后我在linux(Ubuntu)上遇到错误而崩溃:

[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
web_daemon: ../../src/xcb_io.c:165: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq` failed.

我使用Qt :: QueuedConnection,因此将从GUI线程调用方法,我不应该遇到任何线程问题。 我使用手动编译,静态链接的Qt 4.8.7,但我想我在这里做了一些根本性的错误,所以版本并不重要。

0 个答案:

没有答案