Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 a item into the localStorage:

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

The error is happened, and the error messages in the webkit inspector console are:

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

like image 883
johnnyfee Avatar asked Jan 10 '23 11:01

johnnyfee


1 Answers

I was raging all day, because it was not working after restart of the app. So I think this will be helpfull for someone:

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

Notice the enablePersistentStorage

like image 161
Daniel Georgiev Avatar answered Jan 19 '23 00:01

Daniel Georgiev