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. Using qrc/qss files with Qt WASM
Forum Updated to NodeBB v4.3 + New Features

Using qrc/qss files with Qt WASM

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
3 Posts 2 Posters 716 Views 2 Watching
  • 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.
  • L Offline
    L Offline
    LorenzE
    wrote on 9 Jun 2020, 16:32 last edited by
    #1

    Hi all,

    I have a question regarding Qt WASM. I would like to change between different style sheets during run time in a WASM application. In the desktop version of my application I just use QFile to access the .qss file included in my .qrc file.

    if(QApplication *pApp = qobject_cast<QApplication *>(QApplication::instance())) {
      QFile file;
      file.setFileName(":/styles/dark.qss");
      file.open(QFile::ReadOnly | QFile::Text);
      QTextStream stream(&file);
      pApp->setStyleSheet(stream.readAll());
    }
    

    However, under Qt WASM QFile is not supported. Instead one can use QFileDialog::getOpenFileContent to read the complete data as a QByteArray. But this prompts me with a QFileDialog first, which I do not want/need. My question: Is there a way to read from a file included in a .qrc file directly into a QByteArray? I had a look at QResource, but it seems that this class can only be used to read from an external qrc/rcc file during runtime. Any ideas?

    Thanks,

    Lorenz

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lorn.potter
      wrote on 13 Jun 2020, 06:39 last edited by
      #2

      QFile is supported in webassembly, just not QFileDialog.
      using qrc files will also work, but it seems to have issues with paths more than one deep, so using an alias for them will definitely work.

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

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LorenzE
        wrote on 16 Jun 2020, 01:59 last edited by LorenzE
        #3

        Thanks! The following code, using QFile and a top level path, did indeed work:

        QFile file(":/dark.qss");
        file.open(QFile::ReadOnly);
        QTextStream stream(&file);
        pApp->setStyleSheet(stream.readAll());
        
        1 Reply Last reply
        0

        2/3

        13 Jun 2020, 06:39

        • Login

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