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. Qt WebAssembly with OpenCV

Qt WebAssembly with OpenCV

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
4 Posts 3 Posters 1.1k 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.
  • I Offline
    I Offline
    ihmc
    wrote on last edited by ihmc
    #1

    I have tried Qt for WebAssembly with the provided examples and a simple custom widget with OpenGL ES 2.0/3.0 works fine (*Only QOpenGLContext::makecurrent in non-main thread will lead to crash even the context is created in the calling thread. Maybe a bug). I have a question on using external library, e.g. OpenCV here. I have compiled OpenCV with emscripten. Using QtCreator to add external library

    unix:!macx: LIBS += -L$$PWD/path/to/opencv/build_wasm/lib -lopencv_core
    
    INCLUDEPATH += $$PWD/path/to/opencv/install/include/opencv4
    DEPENDPATH += $$PWD/path/to/opencv/install/include/opencv4
    
    unix:!macx: PRE_TARGETDEPS += $$PWD/path/to/opencv/build_wasm/lib/libopencv_core.a
    
    

    The build is fine but when run with Firefox (emrun), the following error shown on the browser.

    Qt for WebAssembly: Test
    TypeError: Response.arrayBuffer: Body has already been consumed.
    

    When I removed all the OpenCV dependencies again, the program runs without problem on Firefox.

    --More Information---
    I have built from source the whole Qt 5.15.1 with emscripten that enables multithreading on Ubuntu20.

    L 1 Reply Last reply
    0
    • I ihmc

      I have tried Qt for WebAssembly with the provided examples and a simple custom widget with OpenGL ES 2.0/3.0 works fine (*Only QOpenGLContext::makecurrent in non-main thread will lead to crash even the context is created in the calling thread. Maybe a bug). I have a question on using external library, e.g. OpenCV here. I have compiled OpenCV with emscripten. Using QtCreator to add external library

      unix:!macx: LIBS += -L$$PWD/path/to/opencv/build_wasm/lib -lopencv_core
      
      INCLUDEPATH += $$PWD/path/to/opencv/install/include/opencv4
      DEPENDPATH += $$PWD/path/to/opencv/install/include/opencv4
      
      unix:!macx: PRE_TARGETDEPS += $$PWD/path/to/opencv/build_wasm/lib/libopencv_core.a
      
      

      The build is fine but when run with Firefox (emrun), the following error shown on the browser.

      Qt for WebAssembly: Test
      TypeError: Response.arrayBuffer: Body has already been consumed.
      

      When I removed all the OpenCV dependencies again, the program runs without problem on Firefox.

      --More Information---
      I have built from source the whole Qt 5.15.1 with emscripten that enables multithreading on Ubuntu20.

      L Offline
      L Offline
      linoleo
      wrote on last edited by
      #2

      @ihmc This is marked as "solved" - so what's the solution?

      I 1 Reply Last reply
      0
      • haikuH Offline
        haikuH Offline
        haiku
        wrote on last edited by
        #3

        I ran into the same problem with Firefox giving me: TypeError: Response.arrayBuffer: Body has already been consumed.

        The problem for me was not related to the .wasm but to the qtloader.js file that qt uses to load the .wasm file. It appears to have a bug where it tries to read the arrayBuffer (body) of a fetch request twice (which is not allowed and results in the above error). This code path is only hit when WebAssembly.compileStreaming throws an error. Because qtloader.js catches this error all you see is the TypeError: Response.arrayBuffer: Body has already been consumed.

        In my case the underlying error was caused by using brotli content compression on the .wasm file without a https connection. It looks like firefox throws an exception without any error message in this case which is caught inside qtloader.js and hidden so it's not obvious at all that this was the issue. I think any error thrown by WebAssembly.compileStreaming should cause the same problem though.

        1 Reply Last reply
        0
        • L linoleo

          @ihmc This is marked as "solved" - so what's the solution?

          I Offline
          I Offline
          ihmc
          wrote on last edited by
          #4

          @linoleo Hey, sorry for replying lately. The problem should be a bug in Firefox like @haiku said.
          You should use opencv.js instead, it is not solved actually.

          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