PDA

View Full Version : Qt and Web Assembly - Installation, running examples and openCV



Stophe
16th February 2023, 11:44
Hi,
I've searched in the documentation and a few pages here how to solve my issues, without luck.

First, I have an issue when running any example, it compiles, open a browers and says :

- Qt for WebAssembly: [project]
Application exit (RuntimeError: Aborted('specialHTMLTargets' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the FAQ)))
Did not find what causes this in the FAQ, and even ChatGPT lied to me.

Example, a very simple hello world program :



#include <QApplication>
#include <QPushButton>
#include <QTranslator>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTranslator translator;
if (!translator.load("hellotr_la"))
return 1;

app.installTranslator(&translator);

QPushButton hello(QPushButton::tr("Hello world!"));
hello.resize(100, 30);
hello.show();
return app.exec();
}



Second issue is linking libraries such as opencv, it says the .dll built with mingw are "unknown file type"


wasm-ld: error: unknown file type: C:/Dev/opencv/mingw-build/bin/libopencv_calib3d460.dll

Thanks for any help !

d_stranz
16th February 2023, 16:13
and even ChatGPT lied to me.

:D

It looks like your bug is caused by something in the Qt CMake scripts used to build Qt for WebAssembly. Check out this Qt bug report post (https://bugreports.qt.io/browse/QTBUG-104882?attachmentOrder=asc) and compare with your Qt6WasmMacros.cmake file contents.


Second issue is linking libraries such as opencv, it says the .dll built with mingw are "unknown file type"

Usually you link to the ".lib" file, not the ".dll" file. DLLs are used only at runtime, not at compile and link time.

Stophe
18th February 2023, 15:36
:D

It looks like your bug is caused by something in the Qt CMake scripts used to build Qt for WebAssembly. Check out this Qt bug report post (https://bugreports.qt.io/browse/QTBUG-104882?attachmentOrder=asc) and compare with your Qt6WasmMacros.cmake file contents.

I found a Qt5WasmMacros.cmake in the folder wasm_32/lib/cmake/Qt6Core, here it is :

# Copy in Qt HTML/JS launch files for apps.
function(_qt_internal_wasm_add_target_helpers target)
/----- (some stuff here) -----/

function(_qt_internal_add_wasm_extra_exported_meth ods target)
get_target_property(wasm_extra_exported_methods "${target}" QT_WASM_EXTRA_EXPORTED_METHODS)

if(NOT wasm_extra_exported_methods)
set(wasm_extra_exported_methods ${QT_WASM_EXTRA_EXPORTED_METHODS})
endif()

if(wasm_extra_exported_methods)
target_link_options("${target}" PRIVATE
"SHELL:-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF 16,${wasm_extra_exported_methods}"
)
else()
# an errant dangling comma will break this
target_link_options("${target}" PRIVATE
"SHELL:-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF 16"
)
endif()
endfunction()

I don't know if it get used by make, by the compiler or not, or at which state. I usually use cmake but I simply try to understand the basics of it until it works.

Am I supposed to copy this file to "HTML/JS Launch file (??)" or is that what this file do ?

(that's true for .dll, I'll have a look later at why it links them instead of lnking libs.)

d_stranz
18th February 2023, 16:44
I don't know if it get used by make, by the compiler or not, or at which state. I usually use cmake but I simply try to understand the basics of it until it works.


This file is used by cmake as it generates the Makefile for Qt WebAssembly.

I think you can define a cmake variable QT_WASM_EXTRA_EXPORTED_METHODS and set it to "specialHTMLTargets" (or append this to what is there if it is already defined, separated by a comma). The script above looks for this variable and appends the contents to the wasm_extra_exported_methods variable, which in turn adds it to the "SHELL: -s" link options.

You might find the QT_WASM... variable defined (but possibly empty) in one of the top-level CMakeLists.txt files for Qt WebAssembly.

Edit: Now that I changed your QUOTE tags to CODE tags, I can see that what you pasted was a function definition. I was misreading it a bit prior to that. Instead of a variable, you may have to look for a call to set_target_properties() or set_property( TARGET ... ) that contains the QT_WASM... name and modify that. See this stackoverflow post (https://stackoverflow.com/questions/47416090/cmake-is-there-a-difference-between-set-propertytarget-and-set-target-pro) about how to use set_property.

My Qt 5.14.2 distribution doesn't seem to have any of the Qt WebAssembly source files, so I can't really check this out.