Qt World Summit: Register Today!

Console app can't access network

  • Hi all. I have an app that was originally built with Qt 5.12.3. This is a command line app which communicates with a remote server using SSL on a single thread and which uses the QNetworkAccessManager class to do so.

    I recently upgraded to Qt 5.14.2 (this is the last version supporting MSVC 2017 with some QML features I needed) but now when running my app I get the following warning when creating the QNetworkAccessManager object:

    qt.network.monitor: Failed to initialize COM: "Cannot change thread mode after it is set."

    along with the following error emitted from the QNetworkReply object:

    Network access is disabled.

    I have the two OpenSSL 1.1.1.c DLLs in the exe directory which is a version I believe is compatible with Qt 5.14.2 (though confirmation of this seems to be hard to find) and these are named libcrypto-1_1-x64.dll and libssl-1_1-x64.dll.

    Does anyone know why this is now an issue? I am using the COM in other parts of my application prior to the creation of the QNetworkAccessManager class using the following code:

    HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);

  • Looks like Qt started using the COM with a different thread mode to me, or they were already using it and changed the thread mode for some reason. Kind of annoying but moving my QNetworkAccessManager class to another thread or calling CoUninitialize() when no-longer required circumvented the issue.

Log in to reply