libevent for qt网络模块,直接替换qt的select模型,支持epoll,select,pool.使用非常简单,无需修改以前的代码结构

最近在开发im服务器,需要大并发链接。QT默认的是使用select模型的,这种轮询方式非常慢。在高并发连接,我们需要epoll才能发挥linux服务器的性能.而且使用简单,整个服务端代码架构无需修改,设置QT的分发事件就可以使用了,只要在main里面添加 :

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main(int argc, char *argv[])  
{  
  #ifdef Q_OS_LINUX  
    QCoreApplication::setEventDispatcher(new EventDispatcherLibEvent);  
   // qInstallMessageHandler(customMessageHandler);  
  #endif  
  
  QCoreApplication a(argc, argv);  
    
  auto *ser=new ConfigServer;  
  ser->startServer();
 
  return a.exec();  
}

在.pro文件添加

 
 
 
 
 

Vim

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
linux{
    LIBS += -levent_core
 
    SOURCES += ../common/eventdispatcher_libevent/eventdispatcher_libevent.cpp \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent_config.cpp \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent_p.cpp \
    ../common/eventdispatcher_libevent/socknot_p.cpp \
    ../common/eventdispatcher_libevent/tco_eventfd.cpp \
    ../common/eventdispatcher_libevent/tco_pipe.cpp \
    ../common/eventdispatcher_libevent/tco.cpp \
    ../common/eventdispatcher_libevent/timers_p.cpp
 
    HEADERS += ../common/eventdispatcher_libevent/common.h \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent.h \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent_config.h \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent_config_p.h \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent_p.h \
    ../common/eventdispatcher_libevent/libevent2-emul.h \
    ../common/eventdispatcher_libevent/qt4compat.h \
    ../common/eventdispatcher_libevent/tco.h \
    ../common/eventdispatcher_libevent/wsainit.h
}

可以直接跨平台了使用了
附上qt libevent源码下载地址:qt_libevent.zip

http://love.junzimu.com/archives/2657

libevent for qt网络模块的更多相关文章

  1. libevent for qt的讨论

    一直对Qt官方的QtNetwork模块抱有遗憾,Qt自带的网络模块用的是select模型,无法支持高并发的服务器开发.最近在网上看到有个libevent for qt的东西,它直接替换了Qt的sele ...

  2. Qt 网络模块如何使用?

    1.网络模块介绍 类名 说明 中文 QAbstractNetworkCache The interface for cache implementations 缓存实现的接口 QNetworkCach ...

  3. Qt网络模块如何使用(表格)

    1.网络模块介绍 类名 说明 中文 QAbstractNetworkCache The interface for cache implementations 缓存实现的接口 QNetworkCach ...

  4. GeoServer-REST应用:基于Qt网络编程一键同步发布空间数据和样式至GeoServer

    @ 目录 简介 配置 步骤   1.引入Qt网络模块   2.创建网络管理.网络响应.网络请求   3.创建工作空间   4.创建数据存储并上传数据   5.上传样式文件   6.图层发布   6.图 ...

  5. Primecoin在windows上的部署和启动服务

     Primecoin在windows上的部署和启动服务: 一.从官方获得Primecoin的windows版安装包: 二.一路像安装客户端一样的安装: 三.安装成功后它会自动弹出客户端运行,同步数据, ...

  6. bitcoind

    Bitcoin Core Daemon version v0.15.1.0-g7b57bc998f Usage: bitcoind [options] Start Bitcoin Core Daemo ...

  7. Qt中加载Libevent静态库(通过reimp和rs两条语句将lib转为a)

    文章来源:http://blog.sina.com.cn/s/blog_731bf4c90102wnpr.html 本文仅是个人经验总结,若有错误欢迎指教! 最近要做一个跨平台的项目,同时也涉及到网络 ...

  8. Qt 工程 pro文件

    工作中,感觉pro文件的有些内容真不太懂,现系统性的学习一下.于此备录,分享共勉. 为了更好的理解,先创建一个简单的工程作为实践. [1]创建一个pro文件 1.1 新建proDemo工程.步骤如下: ...

  9. Qt之Threads和QObjects

    简述 QThread继承自QObject,它发射信号(signals)以表明线程执行开始或结束,并提供了一些槽函数(slots). 更有趣的是,QObjects可以在多线程中使用,发射信号以在其它线程 ...

随机推荐

  1. CentOS下安装无线网卡驱动 (转)

    1. 确定自己的网卡和内核版本:lspci | grep Network  #根据输出的信息确定网卡的型号.uname -a             #确定内核版本 2. 配置yum使用RPMForg ...

  2. Find Successor & Predecessor in BST

    First, we use recursive way. Successor public class Solution { public TreeNode inorderSuccessor(Tree ...

  3. RedHat安装GCC问题-解决依赖问题

    RedHat Linux在安装gcc时需要cpp和cloog-ppl但是在安装cpp的时候需要这个依赖:libmpfr.so.1()(64bit) is needed by cpp-4.4.6-3.e ...

  4. Jquery radio checked

    Jquery radio checked     radio 1. $("input[name='radio_name'][checked]").val(); //选择被选中Rad ...

  5. 判断一个int 型整数 是否为回文数

    leetcode 上的题目 Determine whether an integer is a palindrome. Do this without extra space. 由于不能使用额外空间, ...

  6. FileUtils.copyDirectory without .SVN

    方法1:列出所有文件逐个筛选: File selectedFolder = new File(path); // path to folder to list final IOFileFilter d ...

  7. sqlserver中几种典型的等待

    为了准备今年的双11很久没有更新blog,在最近的几次sqlserver问题的排查中,总结了sqlserver几种典型的等待类型,类似于oracle中的等待事件,如果看到这样的等待类型时候能够迅速定位 ...

  8. zabbix-web界面图形中文乱码解决方法

    1.搜索windows-server X86-64机器上C:/windows/fonts的simkai.tts文件,windows7下有时候不行. 2.把它拷贝到zabbix的web端的fonts目录 ...

  9. Asp.net数据库缓存依赖

    Asp.net数据库缓存依赖 更多的时候,我们的服务器性能损耗还是在查询数据库的时候,所以对数据库的缓存还是显得特别重要,上面几种方式都可以实现部分数据缓存功能.但问题是我们的数据有时候是在变化的,这 ...

  10. iOS 之改变状态栏颜色

    1.在工程中找到 info.plist  文件,点击“+”号,选择 View controller-based status bar appearance 并设为 NO 2.在 AppDelegate ...