[Interest] Crash when creating QNetworkAccessManager in qt 5.14.x

maitai maitai at virtual-winds.org
Wed Feb 5 21:10:28 CET 2020


As I said, I now have doubts it comes from COM threading... 

I have built a small app with nothing inside, with the same .pro file
exactly (qt modules, libs, etc, in the same order). The only difference
is HEADERS and SOURCES of course, main.cpp being the same at least until
it crashes. No problem in this small app (running in the same
directory). 

Again for those who missed it: 

main.cpp:

    QNetworkAccessManager *inet = new QNetworkAccessManager();

    delete inet;

    QApplication app(argc, argv);

this works.

   QApplication app(argc, argv);

   QNetworkAccessManager *inet = new QNetworkAccessManager();

    delete inet;

this crashes on new in our app, not in a sample without HEADERS and
SOURCES.

I cannot understand that, certainly there is something obvious I am
missing.

Philippe Lelong.

Le 05-02-2020 17:06, Henry Skoglund a écrit :

> On 2020-02-05 16:32, maitai wrote:
> 
>> Hi Rainer, 
>> 
>> Unfortunately your suggestion didn't work 
>> 
>> I have added in my pro file:
>> 
>> win32: QMAKE_LFLAGS += /CLRTHREADATTRIBUTE:MTA
>> 
>> and I can see the option in the link command (I also tried the 2 other possibilities STA and NONE of course), but that does not fix anything.
>> 
>> My feeling is that it does not come from CoInitializeEx() finally, because anyway in regular builds we are calling it at the very beginning of main, before creating QApplication or QNetworkManager, so the threading model should be already determined.
> Hi, I've seen similar discussions re. COM threading model and Qt, mostly though they are about QFileDialog and not QNetworkManager, anyways one solution seems to be to call CoUninitialize when switching the threading model, more for example here: https://stackoverflow.com/questions/46581081/qt-qfiledialog-create-unknown-com-object-and-security
> 
> P.S. Also that linker switch /CLRTHREADATTRIBUTE:MTA isn't that mostly for .NET programs?
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200205/0fdd0897/attachment-0001.html>


More information about the Interest mailing list