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. How to compile a cmakelists based QT project for web-assembly?
Forum Update on Monday, May 27th 2025

How to compile a cmakelists based QT project for web-assembly?

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
2 Posts 2 Posters 620 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.
  • S Offline
    S Offline
    shome
    wrote on 12 Mar 2024, 10:33 last edited by shome 3 Dec 2024, 10:45
    #1

    I have a project that uses C++ and QT (QtWidgets, QtCore, QtGui only). The project comes with CMakelists.txt for each folder in the project. How do I compile this project for wasm? I have compiled qt6.6 for wasm that provides a qt-cmake (and qmake also)

    Do I need to

    • convert CMakeLists.txt to .pro files and then use => qmake=>make

    • OR

    • can I use qt-cmake(from qt for wasm build) with the cmakelists.txt using =>qt-cmake . => make

    I tried to compile the example gui_webgltest using the second method. It compiled but it failed to provide a wasm or html file.

    I had added find_package(Qt6 REQUIRED COMPONENTS Widgets OpenGLWidgets) to the existing cmakelists.txt

    cmake_minimum_required(VERSION 3.16)
    project(openglwindow LANGUAGES CXX)
    
    find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL Widgets OpenGLWidgets)
    
    qt_standard_project_setup()
    
    qt_add_executable(openglwindow
        main.cpp
        trianglerenderer.cpp trianglerenderer.h
    )
    
    target_link_libraries(openglwindow PRIVATE
        Qt6::Core
        Qt6::Gui
        Qt6::Widgets
        Qt6::OpenGL
        Qt6::OpenGLWidgets
    )
    
    
    1 Reply Last reply
    0
    • E Offline
      E Offline
      Even Oscar Andersen
      wrote on 27 Mar 2024, 15:10 last edited by
      #2

      For windows, visual studio build with Qt 6.6.2 installed in C:\Qt

      Note the two different ways of running cmake

      1. vcvars64 (for msvc build)
      2. git clone https://github.com/msorvig/qt-webassembly-examples.git
      3. cd qt-webassembly-examples\gui_webgltest
      4. C:\Qt\6.6.2\wasm_singlethread\bin\qt-cmake .
        (creates openglwindow.html)
      5. cmake --build .
        (creates .js, .wasm)
      6. start emrun openglwindow.html
      1 Reply Last reply
      1

      • Login

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