How to enable LocalStorage in Qt 5.3

I tried the method:

QWebSettings* settings = QWebSettings::globalSettings();
settings->setAttribute(QWebSettings::LocalStorageEnabled, true);
auto path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
settings->setOfflineStoragePath(path);

window.localStorage is true (not null or undefined), but when I insert an element into localStorage:

localStorage.setItem("b","isaac");
alert(localStorage["b"]);

An error has occurred and error messages in the webkit inspector console:

QuotaExceededError: DOM Exception 22: An attempt was made to add something to the repository that exceeded the quota.

+4
source share
2 answers

I raged all day, because it did not work after restarting the application. Therefore, I think it will be useful for someone:

QWebSettings* settings = QWebSettings::globalSettings();
settings->setAttribute(QWebSettings::LocalStorageEnabled, true);
auto path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
settings->setOfflineStoragePath(path);
settings->enablePersistentStorage(path);

Note that enablePersistentStorage

+5
source

I forgot that I included a very important swithcer:

settings->setAttribute(QWebSettings::PrivateBrowsingEnabled,true);

, localStorage. api doc .

disable, :

settings->setAttribute(QWebSettings::PrivateBrowsingEnabled,false);
+2

Source: https://habr.com/ru/post/1543365/


All Articles