PDA

View Full Version : Qt WebEngine crashes after downloading



mentalmushroom
5th April 2016, 11:56
I am using Qt 5.6 WebEngine in my simple browser application. Every time I try downloading something the program crashes when I close it (so the crash doesn't happen immediately). The program doesn't crash if I do not try downloading. However, it doesn't really matter whether to accept() or cancel() the download in the downloadRequested(QWebEngineDownloadItem *) handler.

So this is my code:


#include <QtCore>
#include <QtWebEngineWidgets>

class WebView : public QWebEngineView
{
Q_OBJECT
public:
WebView(QWidget *parent = 0);
private slots :
void handleDownloadRequested(QWebEngineDownloadItem *download);
};

WebView::WebView(QWidget *parent)
{
connect(page()->profile(), SIGNAL(downloadRequested(QWebEngineDownloadItem *)), this, SLOT(handleDownloadRequested(QWebEngineDownloadIte m *)));
}

void WebView::handleDownloadRequested(QWebEngineDownloa dItem *download)
{
download->cancel();
//download->accept(); // also crashes
}

int main(int argc, char * argv[])
{
QApplication app(argc, argv);
WebView view;
view.setGeometry(100,100, 1000, 700);
view.load(QUrl("https://www.binsearch.info"));
//view.load(QUrl("https://bugreports.qt.io/browse/QTVSADDINBUG-404"));
view.show();
return app.exec();
}

#include "main.moc"


When I close the program it shows the unhandled exception window telling:

Exception thrown: read access violation.
_q_value was 0xDDDDDDDD.

Stack Trace:


Qt5WebEngineWidgetsd.dll!QGenericAtomicOps<QAtomicOpsBySize<4> >::load<int>(const int & _q_value) Line 83 C++
Qt5WebEngineWidgetsd.dll!QBasicAtomicInteger<int>::load() Line 116 C++
Qt5WebEngineWidgetsd.dll!QtPrivate::RefCount::isSh ared() Line 95 C++
Qt5WebEngineWidgetsd.dll!QMap<unsigned int,QPointer<QWebEngineDownloadItem> >::detach() Line 360 C++
Qt5WebEngineWidgetsd.dll!QMap<unsigned int,QPointer<QWebEngineDownloadItem> >::remove(const unsigned int & akey) Line 927 C++
Qt5WebEngineWidgetsd.dll!QWebEngineProfilePrivate: :downloadDestroyed(unsigned int downloadId) Line 142 C++
Qt5WebEngineWidgetsd.dll!QWebEngineDownloadItemPri vate::~QWebEngineDownloadItemPrivate() Line 88 C++
[External Code]
Qt5WebEngineWidgetsd.dll!QScopedPointerDeleter<QWebEngineDownloadItemPrivate>::cleanup(QWebEngineDownloadItemPrivate * pointer) Line 54 C++
Qt5WebEngineWidgetsd.dll!QScopedPointer<QWebEngineDownloadItemPrivate,QScopedPointerDelete r<QWebEngineDownloadItemPrivate> >::~QScopedPointer<QWebEngineDownloadItemPrivate,QScopedPointerDelete r<QWebEngineDownloadItemPrivate> >() Line 101 C++
Qt5WebEngineWidgetsd.dll!QWebEngineDownloadItem::~ QWebEngineDownloadItem() Line 315 C++
[External Code]
Qt5Cored.dll!QObjectPrivate::deleteChildren() Line 1963 C++
Qt5Cored.dll!QObject::~QObject() Line 1036 C++
Qt5WebEngineWidgetsd.dll!QWebEngineProfile::~QWebE ngineProfile() Line 238 C++
[External Code]
Qt5Cored.dll!QObjectPrivate::deleteChildren() Line 1963 C++
Qt5Cored.dll!QObject::~QObject() Line 1036 C++
[External Code]
Qt5Cored.dll!qt_call_post_routines() Line 298 C++
Qt5Widgetsd.dll!QApplication::~QApplication() Line 819 C++
> browser.exe!main(int argc, char * * argv) Line 30 C++
browser.exe!WinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, char * __formal, int __formal) Line 113 C++
[External Code]
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]


Am I doing something wrong or it's a bug?


Added after 18 minutes:

It seems like download->deleteLater() fixes the issue, but the documentation is not really clear about QWebEngineDownloadItem deletion:

The download argument holds the state of the download. The download has to be explicitly accepted with QWebEngineDownloadItem::accept() or it will be cancelled by default. The download item is parented by the profile. If it is not accepted, it will be deleted immediately after the signal emission. This signal cannot be used with a queued connection.

As far as I understand it, the profile is responsible for deletion. But why does it crash then?