I would like to integrate a C library into my C++/Qt project. The library accepts a FILE* stream in order to print debug messages (rather than providing a hook for a logging callback function...).
It works properly if I just pass stderr
, but I would like to integrate this into my own logging infrastructure, which uses qDebug()
and co.
My initial idea was to use socketpair()
, get the FILE* stream of the sending side's fd, pass it to the library, and handle the receiving side with QSocketNotifier, but I hit 2 issues with it:
- It's not multiplatform, although there are implementations for Windows.
- My application is single-threaded (and I want to keep it that way), and this means that the socketpair's 2 sockets are written and read from the same thread. This seems to be ending up with a deadlock after a while.
What are other methods existing to provide a FILE* stream, integrate its reading into Qt's event loop, doesn't require multiple threads, and is multiplatform?