← Back to Docs
  • index.html
  • Clayground
  • Clayground.Storage
  • StorageSync
  • Clayground 2026.8
  • StorageSync QML Type

    Makes what was stored survive a browser reload. More...

    Import Statement: import Clayground.Storage

    Methods

    Detailed Description

    In a WebAssembly build, files live in memory and are gone when the page reloads. Clayground.Storage therefore keeps the data directory (where QML LocalStorage puts its databases) in the browser's IndexedDB: it is loaded from there before the app starts, and persist() writes it back.

    KeyValueStore calls persist() after every change, so a KeyValueStore needs nothing more. Call it yourself only after writing to that directory some other way, e.g. with QtQuick.LocalStorage directly:

    import QtQuick.LocalStorage
    import Clayground.Storage
    
    function save(db, score) {
        db.transaction(tx => tx.executeSql('INSERT INTO scores VALUES (?)', [score]))
        StorageSync.persist()
    }

    In a native build there is nothing to write back and persist() does nothing.

    Method Documentation

    void persist()

    Writes the data directory back to IndexedDB, in the background. Calls that arrive while a write is still running are folded into one more write after it. A change is safe from a page reload once the page's JavaScript reads window.clayStorage.busy as false.