Important: Please read the Qt Code of Conduct -

How to combine two eventloops into one?

  • I want to develop a http/2 server using Qt5 + nghttp2.
    From the example given by nghttp2, I found that nghttp2 has its own eventloop.
    server.listen_and_serve(ec, addr, port) is very similar to app.exec() in Qt.
    Is it possible to handle both eventloop in a single thread?

  • @Mr-Pang
    I admit I have no experience in this area so take with a pinch of salt, but until someone knowing better replies I would say not. If you need server.listen_and_serve() to run its own event loop that won't combine with the Qt loop, so it should run in its own thread?

  • Moderators


    I would say no, but I'm not 100% sure on this.

    Your situation actually seems to be one of the cases where Subclassing QThread and overwriting run() seems like the best option to do.

    That would also allow you to define signals to emit, to react to the state changes and responses etc.

  • @Mr-Pang said in How to combine two eventloops into one?:


    Anytime you link Qt with a library that has its own event loop you should run that library event loop in its own thread and do some thread to thread communications between the two frameworks. Let each exist independently within your program and have them communicate between each other. Trying to implement signal/slot in nghttp2 is probably a disaster waiting to happen, but you could create semaphores or message queues to ship data back and forth between the two framworks.

    Edit: BTW: some libraries recognize that you will use them in a framework that has its own event queue and will provide an explicit call to process messages in their own queue...such as a ficticious example: nghttp2::process_event_queue()

Log in to reply