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. Problem to find main.qml
Qt 6.11 is out! See what's new in the release blog

Problem to find main.qml

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
3 Posts 2 Posters 1.3k 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.
  • Q Offline
    Q Offline
    qwendt
    wrote on last edited by qwendt
    #1

    Hello
    I build my first Qt for WebAssembly project. I have many troubles to just get a minimal working example. I can build it but in the browser I just see white with the error messages

    QQmlApplicationEngine failed to load component appqt3d.js:11688:12
    qrc:/qml/main.qml: No such file or directory
    

    My project structure looks as follow:

    build_wasm.sh  clion_wasm_env  cmake-build-debug  cmake-build-debug-qt-webassembly  CMakeLists.txt  main.cpp  qml  resources.qrc
    

    and inside the qml folder there is the file main.qml

    The root CMakeLists.txt:

    cmake_minimum_required(VERSION 3.21)
    project(qt3d_wasm_project VERSION 0.1 LANGUAGES CXX)
    
    
    message(STATUS "CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}")
    message(STATUS "ENV EMSDK = $ENV{EMSDK}")
    message(STATUS "ENV EM_CONFIG = $ENV{EM_CONFIG}")
    
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    set(CMAKE_AUTOUIC ON)
    
    find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Quick3D Qml Quick3DHelpers)
    
    qt_add_executable(appqt3d
            main.cpp
            resources.qrc
    )
    
    target_link_options(appqt3d PRIVATE
            "-sASYNCIFY=1"
            "-sASYNCIFY_IMPORTS=qt_asyncify_suspend_js,qt_asyncify_resume_js"
            "-s MODULARIZE=1"
            "-s EXPORT_NAME=appqt3d_entry"
            "-s ALLOW_MEMORY_GROWTH=1"
            "-s INITIAL_MEMORY=64MB"
            "-s MAXIMUM_MEMORY=4GB"
            "-s ERROR_ON_UNDEFINED_SYMBOLS=1"
            "-s FETCH=1"
            "-s STACK_SIZE=5MB"
            "-s MAX_WEBGL_VERSION=2"
            "-s WASM_BIGINT=1"
            "--profiling-funcs"
            "-o ${CMAKE_CURRENT_BINARY_DIR}/appqt3d.html"
    )
    
    
    target_link_libraries(appqt3d PRIVATE
            Qt6::Core Qt6::Gui Qt6::Quick Qt6::Quick3D Qt6::Quick3DHelpers
    )
    

    my main.cpp:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QUrl>
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
    
        engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
    
        if (engine.rootObjects().isEmpty())
            return -1;
    
        return app.exec();
    }
    

    and my resources.qrc

    <!DOCTYPE RCC>
    <RCC>
      <qresource prefix="/qml">
        <file>qml/main.qml</file>
      </qresource>
    </RCC>
    
    

    Also after reading the other blog entries i still cannot understand why it cannot find my main.qml. Or where the problem lies,
    Thank you

    Christian EhrlicherC 1 Reply Last reply
    0
    • Q qwendt

      Hello
      I build my first Qt for WebAssembly project. I have many troubles to just get a minimal working example. I can build it but in the browser I just see white with the error messages

      QQmlApplicationEngine failed to load component appqt3d.js:11688:12
      qrc:/qml/main.qml: No such file or directory
      

      My project structure looks as follow:

      build_wasm.sh  clion_wasm_env  cmake-build-debug  cmake-build-debug-qt-webassembly  CMakeLists.txt  main.cpp  qml  resources.qrc
      

      and inside the qml folder there is the file main.qml

      The root CMakeLists.txt:

      cmake_minimum_required(VERSION 3.21)
      project(qt3d_wasm_project VERSION 0.1 LANGUAGES CXX)
      
      
      message(STATUS "CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}")
      message(STATUS "ENV EMSDK = $ENV{EMSDK}")
      message(STATUS "ENV EM_CONFIG = $ENV{EM_CONFIG}")
      
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_AUTORCC ON)
      set(CMAKE_AUTOUIC ON)
      
      find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Quick3D Qml Quick3DHelpers)
      
      qt_add_executable(appqt3d
              main.cpp
              resources.qrc
      )
      
      target_link_options(appqt3d PRIVATE
              "-sASYNCIFY=1"
              "-sASYNCIFY_IMPORTS=qt_asyncify_suspend_js,qt_asyncify_resume_js"
              "-s MODULARIZE=1"
              "-s EXPORT_NAME=appqt3d_entry"
              "-s ALLOW_MEMORY_GROWTH=1"
              "-s INITIAL_MEMORY=64MB"
              "-s MAXIMUM_MEMORY=4GB"
              "-s ERROR_ON_UNDEFINED_SYMBOLS=1"
              "-s FETCH=1"
              "-s STACK_SIZE=5MB"
              "-s MAX_WEBGL_VERSION=2"
              "-s WASM_BIGINT=1"
              "--profiling-funcs"
              "-o ${CMAKE_CURRENT_BINARY_DIR}/appqt3d.html"
      )
      
      
      target_link_libraries(appqt3d PRIVATE
              Qt6::Core Qt6::Gui Qt6::Quick Qt6::Quick3D Qt6::Quick3DHelpers
      )
      

      my main.cpp:

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QUrl>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
          QQmlApplicationEngine engine;
      
          engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
      
          if (engine.rootObjects().isEmpty())
              return -1;
      
          return app.exec();
      }
      

      and my resources.qrc

      <!DOCTYPE RCC>
      <RCC>
        <qresource prefix="/qml">
          <file>qml/main.qml</file>
        </qresource>
      </RCC>
      
      

      Also after reading the other blog entries i still cannot understand why it cannot find my main.qml. Or where the problem lies,
      Thank you

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @qwendt said in Problem to find main.qml:

      <qresource prefix="/qml">
      <file>qml/main.qml</file>

      Your file is in :/qml/qml/main.qml

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Q 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @qwendt said in Problem to find main.qml:

        <qresource prefix="/qml">
        <file>qml/main.qml</file>

        Your file is in :/qml/qml/main.qml

        Q Offline
        Q Offline
        qwendt
        wrote on last edited by qwendt
        #3

        @Christian-Ehrlicher thank you, so the working solution is

        SOLVED:

        <!DOCTYPE RCC>
        <RCC>
          <qresource prefix="/">
            <file>qml/main.qml</file>
          </qresource>
        </RCC>
        
        

        and

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        #include <QUrl>
        #include <QDirIterator>
        
        int main(int argc, char *argv[])
        {
            QGuiApplication app(argc, argv);
            QQmlApplicationEngine engine;
        
            engine.load(QUrl(QStringLiteral("qrc:qml/main.qml")));
        
            if (engine.rootObjects().isEmpty())
                return -1;
        
            return app.exec();
        }
        
        

        I am happy!!!

        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