2

I currently use libevent heavily for C/C++ network programming and I love how easily I can make an event-based app without having to worry if I need to use select,poll,epoll,kqueues etc. The apps I've made are text-only, and now I'm looking at Qt/QML to make a GUI for my existing network apps.

I just don't know how I can integrate them into one application, as both libevent and qt want to run their own event loops. Do I need to look at running each in its own thread (gui in one thread and libevent-backend in another) or am I missing something very simple? :-)

Thanks, Nina

2 Answers2

0

Implement QAbstractEventDispatcher that wraps libevent.

Andrew
  • 603
  • 1
  • 5
  • 13
0

You could call QApplication::processEvents from an idle timer in the libevent loop (or maybe the other way around, assuming libevent has something similar).

OTOH, having two threads might not be that bad, since Qt allows signals/slots connections (as well as general method calls via QMetaObject::invokeMethod) between threads.

It depends on how tight the integration between libevent and Qt's GUI needs to be in your app.

Macke
  • 24,812
  • 7
  • 82
  • 118
  • Would this be an efficient way to make an event loop? I'm thinking that continuously calling QApplication::processEvents based on an idle timer method from libevent would be very inefficient. For instance, the GUI can become very laggy if Qt emits an event while libevent is handling its own event loop, or the other way around. Forgive me if I understood wrongly. – Nina Nordstrom May 20 '11 at 07:11
  • @Nina: It can be a bit laggy. It depends on how long each iteration of libevent's loop is. GUI need not be _that_ fast, 100 ms is enough. Sadly, I don't know enough about libevent to give better advice. Threading is safest, but is trickier to implement. How about writing a small prototype (or two) to test your different options? – Macke May 20 '11 at 07:30