I use C++ and Qt 5.15.x. I've built WebAssembly version of my desktop application. The application is loaded using URL like "http://192.168.21.55:5555" (intranet application). I'd like to extract server IP address within WebAssembly application. How can I achieve it?
Asked
Active
Viewed 479 times
1 Answers
5
There is no solution for ip extraction, but I've found the way to get host and port (host is equal to ip in my case).
#include <emscripten/val.h>
emscripten::val location = emscripten::val::global("location");
auto host = QString::fromStdString(location["host"].as<std::string>());
auto port = QString::fromStdString(location["port"].as<std::string>());

ilya
- 1,103
- 14
- 36
-
1Small remark: Using `"hostname"` instead of `"host"` will remove any port number that might be specified. See [this question](https://stackoverflow.com/a/11379802/6700329). For me, this was an important detail. Apart from that, great answer. – wychmaster Mar 21 '23 at 10:24