【问题标题】:How to enable LocalStorage in Qt 5.3如何在 Qt 5.3 中启用 LocalStorage
【发布时间】:2014-07-26 03:23:40
【问题描述】:

我试过方法:

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

window.localStorage 为 true(不是 null 或未定义),但是当我将项目插入 localStorage 时:

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

发生了错误,webkit inspector 控制台中的错误信息是:

QuotaExceededError: DOM Exception 22: 尝试向存储中添加超出配额的内容。

【问题讨论】:

    标签: qt webkit local-storage


    【解决方案1】:

    我整天都在发脾气,因为重新启动应用程序后它无法正常工作。 所以我认为这对某人有帮助:

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

    注意 enablePersistentStorage

    【讨论】:

      【解决方案2】:

      我忘了我启用了一个非常重要的开关:

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

      这会将浏览器设置为私有模式并阻止您向 localStorage 插入值。但是官方的api文档并没有提到。

      你只要设置禁用切换器就可以解决问题:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-23
        • 2016-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-27
        相关资源
        最近更新 更多