Message Queue under Qt5: zmq + nzmqt + qt

来源:互联网 发布:软件服务外包专业 编辑:程序博客网 时间:2024/06/05 22:11

Using nzmqt, you can use message queue under QT5

The synchronised message deliver method:

For example:

I ask a question and wait till the peer answered.


Solution:

http://blog.sina.com.cn/s/blog_413978670100m9y3.html


int loginSync(const QString& username, const QString& password){  QEventLoop q;  connect(this, SIGNAL(OnLoginStatusChanged()), &q, SLOT(quit()));  //异步调用完成退出  Login(username, password);   //调用异步函数   q.exec();     //以下可以根据异步函数的返回结果进行进一步操作并返回函数结果。 // now i_am_test == 1  assert(i_am_test == 1); }void <pre name="code" class="cpp">OnLoginStatusChanged(){      i_am_test = 1;}


ZMQ Requester-Replier 's synchronization method


int loginSync(const QString& username, const QString& password){  QEventLoop q;  nzmqt::Requester req;  req.sendReq("Requesting something");  connect(&req, SIGNAL(reply()), *q, SLOT(quit()); // wait till the reply reached. connect(this, SIGNAL(OnLoginStatusChanged()), &q, SLOT(quit()));  //异步调用完成退出  Login(username, password);   //调用异步函数   q.exec();  assert("I_am_the_answer" == req.getAnswer());    //以下可以根据异步函数的返回结果进行进一步操作并返回函数结果。 // now i_am_test == 1  assert(i_am_test == 1); }void <pre name="code" class="cpp">OnLoginStatusChanged(){      i_am_test = 1;}




0 0