Qt 5: Access Cookies in QtWebEngine

2019-02-15 12:36发布

问题:

Is it possible to access the QNetworkCookieJar in QtWebEngine like you could before with QtWebKit? I can't find it anywhere in the documentation...

回答1:

From Qt 5.6 onwards you can use the QWebEngineCookieStore class.



回答2:

QNetworkCookie is available for QtWebEngine, but only through the old QNetworkAccessManager as QtWebEngine is using its own HTTP implementation. You can notice this while reading one of the examples:

contains(DEFINES, QWEBENGINEPAGE_SETNETWORKACCESSMANAGER) {
    HEADERS += cookiejar.h networkaccessmanager.h
    SOURCES += cookiejar.cpp networkaccessmanager.cpp
}

Please refer to the following example for details:

WebEngine Tab Browser Example