Search code examples
c++qthtmlwebkitqtwebkit

How to make Qt support HTML 5 database?


I am using Qt 4.7.1 and embedded a webview in my app. But I got the following error when trying to visit http://webkit.org/demos/sticky-notes/ to test the HTML 5 database feature

Failed to open the database on disk.  This is probably because the version 
was bad or there is not enough space left in this domain's quota

I compiled my static Qt library with the following command:

configure --prefix=/usr/local/qt-static-release-db --accessibility --multimedia 
--audio-backend --svg --webkit --javascript-jit --script --scripttools 
--declarative --release -nomake examples -nomake demos --static --openssl -I
/usr/local/ssl/include -L /usr/local/ssl/lib -confirm-license -sql-qsqlite 
-sql-qmysql -sql-qodbc

Solution

  • Check QWebSettings documentation.

    In particular, you have to use setAttribute to enable QWebSettings::OfflineStorageDatabaseEnabled and point out the local storage location using setOfflineStoragePath (e.g. QDesktopServices::DataLocation).

    You might want to do it per-page, but as an example, doing it globally can be done using:

        QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
        QWebSettings::globalSettings()->setOfflineStoragePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));