Good day!

Qt 5.4 QWebView with a slightly modified QNetworkAccessManager drops the program when loading some pages. I do not know how to explain in more detail, therefore, the simplest example.

Note: the file to which the link located here no longer exists. However, from the answer you can try to restore the general idea of ​​the problem area.

  • When an application crashes, it throws an exception. Find out what exception you get. - ixSci
  • And please, don't create labels with class names in Qt. - ixSci
  • Pavel, explain why you use QCustomNetworkReply? Why did you enter it? - alexis031182

1 answer 1

You get an interesting situation here in the overridden method QCustomNetworkAccessManager::createRequest() :

  1. create a QNetworkRequest request by receiving a QNetworkReply response;
  2. wait until the request is executed and the response is filled with data without leaving the method of creating the request;
  3. Create a new QCustomNetworkReply custom response QCustomNetworkReply and copy the headers and received content from the existing response, the latter, in addition to QNetworkReply opening its own QIODevice instance, is transferred to a separate QByteArray ;
  4. return the received "custom response".

Your "custom" answer is not an exact copy of the real answer. You did not redefine all the methods that handle the data, limiting QCustomNetworkReply::readData() only to QCustomNetworkReply::readData() . And there are many, because QNetworkReply inherited from QIODevice . Since your "custom" response contains, albeit an open, but empty QIODevice instance, when you call it, any other undefined method will, as they say, undefined behavior. This is probably the reason for the segfolt, since the web page that you cited as an example performs many downloads of various content. Not surprisingly, on a relatively static page with Yandex from the second example, an error does not occur, whereas in the first case a “crash” occurs.

Also, you missed the moment that the object of the real answer class remains active, you do not delete it after creating the "custom" answer, which means it will live as long as the object of the QCustomNetworkAccessManager class QCustomNetworkAccessManager . Since the latter usually exists throughout the life of the entire program, a bunch of real answers will be accumulated in memory.

The purpose of entering a separate class "custom" answer is unknown to me, but probably you should change the approach.

  • Thank you, the goal is simple. I need to change the headers in the request sent from the browser. Including the "Accept-Encoding" header, and further miracles, it turned out that having received the modified "Accept-Encoding" QNetworkAccessManager does not unpack gzip-packed responses. bugs.webkit.org/show_bug.cgi?id=63696 You have to wait for an answer, unpack it yourself and transfer it as QCustomNetworkReply - Pavel Vershinin
  • PS By the way, yes, sorry, in the example I forgot reply-> deleteLater (); in the real program, it is, though it does not save from falling :) - Pavel Vershinin