From 4fad197fbe0ba1239c17a26ace77bb4d2f133e66 Mon Sep 17 00:00:00 2001 From: Frank Dana Date: Mon, 23 Mar 2020 08:16:02 -0400 Subject: [PATCH] Add version gating for Zmq and Qt deprecations (#470) * ZmqLogger: Avoid deprecated send() in later ZMQ * QtImageReader: byteCount() deprecated in QT 5.10+ --- src/QtImageReader.cpp | 7 ++++++- src/ZmqLogger.cpp | 12 +++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/QtImageReader.cpp b/src/QtImageReader.cpp index 864af23db..cf64ef930 100644 --- a/src/QtImageReader.cpp +++ b/src/QtImageReader.cpp @@ -111,7 +111,12 @@ void QtImageReader::Open() info.has_audio = false; info.has_video = true; info.has_single_image = true; - info.file_size = image->byteCount(); + #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + // byteCount() is deprecated from Qt 5.10 + info.file_size = image->sizeInBytes(); + #else + info.file_size = image->byteCount(); + #endif info.vcodec = "QImage"; info.width = image->width(); info.height = image->height(); diff --git a/src/ZmqLogger.cpp b/src/ZmqLogger.cpp index 89d2798a6..f607d08f8 100644 --- a/src/ZmqLogger.cpp +++ b/src/ZmqLogger.cpp @@ -120,14 +120,20 @@ void ZmqLogger::Log(string message) // Create a scoped lock, allowing only a single thread to run the following code at one time const GenericScopedLock lock(loggerCriticalSection); +#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 1) // Send message over socket (ZeroMQ) + zmq::message_t reply(message); + + // Set flags for immediate delivery (new API) + publisher->send(reply, zmq::send_flags::dontwait); +#else zmq::message_t reply (message.length()); memcpy (reply.data(), message.c_str(), message.length()); publisher->send(reply); +#endif - // Write to log file (if opened, and force it to write to disk in case of a crash) - if (log_file.is_open()) - log_file << message << std::flush; + // Also log to file, if open + LogToFile(message); } // Log message to a file (if path set)