Handle Platform specific imports
-
Hey there :D
I am trying to build my application for WebAssembly and found out, that QtQuick.LocalStorage is not supported (still searching for an alternative / best practice to save local data in Wasm):
> module "QtQuick.LocalStorage" is not installed
(on Firefox)
So I wanted to temporary exclude the import in the QML file, but I don't know how?
Doing with macros like in C++ code does not work#ifndef Q_OS_WASM // error: Unexpected token `' import QtQuick.LocalStorage 2.12 #endif
neither the platform flags I use in the project file
Wasm { import QtQuick.LocalStorage 2.12 // error: Unexpected token 'import' }
or a classic if to get platform information
if (Qt.platform.os != "wasm") // error: Unexpected token 'if' import QtQuick.LocalStorage 2.12 }
Is there a way I can solve this so I can further investigate the WebAssembly build?
Or is the conventional way to have different implementations for Wasm and iOS/Android/macOs? (Maybe https://doc.qt.io/qt-5/qqmlfileselector.html is the way to go?)
Or maybe there exists a common way to use LocalStorage on all platforms?Thanks for any information,
best regards SyntaX -
Hi @SyntaX
sadly, there is currently only really one (cumbersome) way to exclude stuff depending on flags, in QML
By Shoveling everything it its own qml file and using a Loader, to conditionally load.
IIRC this should change with Qt6, there we should get something along the line if #if #else #endif
-
@SyntaX said in Handle Platform specific imports:
I am trying to build my application for WebAssembly and found out, that QtQuick.LocalStorage is not supported (still searching for an alternative / best practice to save local data in Wasm):
The only way to open and save data to the local (desktop) filesystem with wasm is to use
QFileDialog::getOpenFileContent
and
QFileDialog::saveFileContenthttps://doc.qt.io/qt-5/qfiledialog.html#saveFileContent
Also, currently there is no support for SQL or other databases in Qt WebAssembly.
-
Hey @lorn-potter and thanks for your reply and the provided information!