Unsolved How can I add a progress for message sending operation (smtp) with blocking sockets API's?
-
Hello!
I'm using blocking sockets API (waitFor* functions) for sending mail by smtp protocol (it's a DLL modue). All operations are synchronous: connect->waitForConnected(timeout)->login->waitForReadyRead(timeout)->sendMessage->waitForBytesWritten(timeout)->etc.
I'm using blocking API, because QCoreApplication absence is required (DLL used by different apps, incl. non-qt-based). Blocking functions don't require event loop and it works fine.
But how can I make a visual progress for long-term sending mail operations (with big attachment, for example)?
And how can organize callbacks for progress notifications in sendmail DLL?ps: all blocking waitFor* functions marked as
functions, that may fail randomly on Windows. Consider using the event loop and the readyRead() signal if your software will run on Windows.
Why? -
@meteoir
I assume that since they are blocking and don't use event loop you won't have the GUI updated.I presume two possibilities:
-
Make
timeout
small, and expect to call functions repeatedly, with GUI update/progress after each timeout expires. -
Put blocking calls into separate thread from GUI.
-
-
mail sending functions will called in separated thread. But how can I take a progress notifications if waitForBytesWritten function is hang on or big file transferred?
-
@meteoir
Make yourwaitForBytesWritten()
take a small timeout if you want to avoid "hang".However, as you say, the docs state:
Note: This function may fail randomly on Windows. Consider using the event loop and the bytesWritten() signal if your software will run on Windows.
so you may not be able to do what you want under Windows.