Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Handle Platform specific imports

Handle Platform specific imports

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
5 Posts 3 Posters 905 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SyntaXS Offline
    SyntaXS Offline
    SyntaX
    wrote on last edited by
    #1

    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

    J.HilkJ 1 Reply Last reply
    0
    • SyntaXS SyntaX

      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

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      SyntaXS 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        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

        SyntaXS Offline
        SyntaXS Offline
        SyntaX
        wrote on last edited by
        #3

        Thanks @J-Hilk for your reply, I will investigate the QML Loader type :D
        https://doc.qt.io/qt-5/qml-qtquick-loader.html

        1 Reply Last reply
        1
        • lorn.potterL Offline
          lorn.potterL Offline
          lorn.potter
          wrote on last edited by
          #4

          @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::saveFileContent

          https://doc.qt.io/qt-5/qfiledialog.html#saveFileContent

          Also, currently there is no support for SQL or other databases in Qt WebAssembly.

          Freelance Software Engineer, Platform Maintainer QtWebAssembly, Maintainer QtSensors
          Author, Hands-On Mobile and Embedded Development with Qt 5 http://bit.ly/HandsOnMobileEmbedded

          SyntaXS 1 Reply Last reply
          2
          • lorn.potterL lorn.potter

            @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::saveFileContent

            https://doc.qt.io/qt-5/qfiledialog.html#saveFileContent

            Also, currently there is no support for SQL or other databases in Qt WebAssembly.

            SyntaXS Offline
            SyntaXS Offline
            SyntaX
            wrote on last edited by
            #5

            Hey @lorn-potter and thanks for your reply and the provided information!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved