libevent-based event dispatcher for Qt
QSocketNotifier::Exception
(libevent offers no support for this)QWinEventNotifier
is not supported (registerEventNotifier()
and unregisterEventNotifier()
functions
are currently implemented as stubs; libevent does not natively support Windows events and addition of the support
to the event dispatcher will mean a completely different event loop code for Windows).cd src
qmake
make
Replace make
with nmake
if your are using Microsoft Visual C++.
The above commands will generate the static library and .prl
file in ../lib
directory.
After completing Build step run
*NIX:
sudo make install
Windows:
nmake install
For Windows this will copy eventdispatcher_libevent.h
and eventdispatcher_libevent_config.h
to ../lib
directory.
For *NIX this will install eventdispatcher_libevent.h to /usr/include
, libeventdispatcher_libevent.a
and libeventdispatcher_libevent.prl
to /usr/lib
, eventdispatcher_libevent.pc
to /usr/lib/pkgconfig
.
Simply include the header file and instantiate the dispatcher in main()
before creating the Qt application object.
#include "eventdispatcher_libevent.h"
int main(int argc, char** argv)
{
EventDispatcherLibEvent dispatcher;
QCoreApplication app(argc, argv);
// ...
return app.exec();
}
And add these lines to the .pro file:
unix {
CONFIG += link_pkgconfig
PKGCONFIG += eventdispatcher_libevent
}
else:win32 {
include(/path/to/qt_eventdispatcher_libevent/lib/eventdispatcher_libevent.pri)
}
or
HEADERS += /path/to/eventdispatcher_libevent.h
LIBS += -L/path/to/library -leventdispatcher_libevent
Simply include the header file and instantiate the dispatcher in main()
before creating the Qt application object.
#include "eventdispatcher_libevent.h"
int main(int argc, char** argv)
{
QCoreApplication::setEventDispatcher(new EventDispatcherLibEvent);
QCoreApplication app(argc, argv);
// ...
return app.exec();
}
And add these lines to the .pro file:
unix {
CONFIG += link_pkgconfig
PKGCONFIG += eventdispatcher_libevent
}
else:win32 {
include(/path/to/qt_eventdispatcher_libevent/lib/eventdispatcher_libevent.pri)
}
or
HEADERS += /path/to/eventdispatcher_libevent.h
LIBS += -L/path/to/library -leventdispatcher_libevent
Qt 5 allows to specify a custom event dispatcher for the thread:
QThread* thr = new QThread;
thr->setEventDispatcher(new EventDispatcherLibEvent);
EventDispatcherLibEvent
is more compatible with Qt 4.2.x and 4.3.x than the native UNIX event dispatcher from those Qt's.
For example, Qt 4.2.1 fails tst_QTimer::livelock(zero timer)
and tst_QTimer::livelock(non-zero timer)
tests
('tester.postEventAtRightTime' returned FALSE
) and hangs in tst_QEventLoop::processEventsExcludeTimers
test
but EventDispatcherLibEvent
passes them all!
It should, however, be noted that these tests were taken from Qt 4.8 :-)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。