线程中的QEventLoop::exec是怎么实现的
来源:互联网 发布:朱文臣 网络频道和讯 编辑:程序博客网 时间:2024/06/09 19:03
在Qt Creator中添加如下测试代码:
void myThread::run(){ QEventLoop eventLoop; eventLoop.exec();}
//C:\Qt\Qt5.7.0\5.7\Src\qtbase\src\corelib\kernel\qeventloop.cppint QEventLoop::exec(ProcessEventsFlags flags){ //... while (!d->exit.loadAcquire()) processEvents(flags | WaitForMoreEvents | EventLoopExec); //...}
//C:\Qt\Qt5.7.0\5.7\Src\qtbase\src\corelib\kernel\qeventdispatcher_win.cppbool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags){ //... if (!d->internalHwnd) { createInternalHwnd(); wakeUp(); // trigger a call to sendPostedEvents() } //... haveMessage = PeekMessage(&msg, 0, 0, 0, PM_REMOVE); //... if (!filterNativeEvent(QByteArrayLiteral("windows_generic_MSG"), &msg, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } //... waitRet = MsgWaitForMultipleObjectsEx(nCount, pHandles, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE | MWMO_INPUTAVAILABLE); //...}其中createInternalHwnd()调用了qt_create_internal_window
static HWND qt_create_internal_window(const QEventDispatcherWin32 *eventDispatcher){ QWindowsMessageWindowClassContext *ctx = qWindowsMessageWindowClassContext(); if (!ctx->atom) return 0;#ifdef Q_OS_WINCE HWND parent = 0;#else HWND parent = HWND_MESSAGE;#endif HWND wnd = CreateWindow(ctx->className, // classname ctx->className, // window name 0, // style 0, 0, 0, 0, // geometry parent, // parent 0, // menu handle qWinAppInst(), // application 0); // windows creation data. if (!wnd) { qErrnoWarning("CreateWindow() for QEventDispatcherWin32 internal window failed"); return 0; }#ifdef GWLP_USERDATA SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG_PTR)eventDispatcher);#else SetWindowLong(wnd, GWL_USERDATA, (LONG)eventDispatcher);#endif return wnd;}创建了一个"message-only window"
https://msdn.microsoft.com/en-us/library/windows/desktop/ms632599(v=vs.85).aspx#message_only
Message-Only Windows
A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.
To create a message-only window, specify the HWND_MESSAGE constant or a handle to an existing message-only window in the hWndParent parameter of the CreateWindowEx function. You can also change an existing window to a message-only window by specifying HWND_MESSAGE in thehWndNewParent parameter of theSetParent function.
To find message-only windows, specify HWND_MESSAGE in the hwndParent parameter of the FindWindowEx function. In addition, FindWindowEx searches message-only windows as well as top-level windows if both thehwndParent andhwndChildAfter parameters are NULL.
- 线程中的QEventLoop::exec是怎么实现的
- 手机中的AR是怎么实现的
- Stringbuffer的线程安全是怎么实现的
- JAVA中的输入语句是怎么实现的?
- 虚拟机是怎么实现的?
- mysql是怎么实现的
- TagHelper是怎么实现的
- sping是怎么处理线程并发的
- 什么是线程安全? 线程安全是怎么完成的(原理)?
- QEventLoop 的使用两例
- QEventLoop 的使用两例
- QEventLoop 的使用两例
- QEventLoop 的使用两例
- QEventLoop 的使用两例
- QEventLoop 的使用两例
- QEventLoop 的使用两例
- QEventLoop 的使用两例
- QEventLoop会卡住的解决方法
- js选择一个选项 跳出另一个选项 跳出一个输入框
- onItemClick
- Java ActiveMQ Spring ActiveMQ整合+注解消息监听
- ListView下拉刷新、上拉载入更多之封装改进
- view类的XML属性
- 线程中的QEventLoop::exec是怎么实现的
- 自定义View常处理的回调函数
- 自定义控件
- listView上拉刷新下拉加载
- 选择 隐藏 与展出
- php 10.1总
- Duilib使用时资源文件路径约定
- Intent
- 是否有可能运用tempates对XML之前应用在XSL参数模板