Skip to content

Commit

Permalink
Add version gating for Zmq and Qt deprecations (#470)
Browse files Browse the repository at this point in the history
* ZmqLogger: Avoid deprecated send() in later ZMQ
* QtImageReader: byteCount() deprecated in QT 5.10+
  • Loading branch information
ferdnyc authored Mar 23, 2020
1 parent 94e9ad3 commit 4fad197
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/QtImageReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 9 additions & 3 deletions src/ZmqLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CriticalSection> 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)
Expand Down

0 comments on commit 4fad197

Please sign in to comment.