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. Get URL / local IP in Qt WASM
Forum Updated to NodeBB v4.3 + New Features

Get URL / local IP in Qt WASM

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
ipv4wasmurl
3 Posts 3 Posters 1.7k Views 1 Watching
  • 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.
  • O Offline
    O Offline
    Ollie_A
    wrote on 12 Dec 2020, 15:34 last edited by
    #1

    Hi all, I'm wondering if there's any way to get the local IP (or URL) of the web server hosting a Qt WASM program, from the program? From what I've seen through looking online, it seems it can be done through javascript, but I'm not sure how I'd go about it through this, apart from messing around with the generated js gluecode?

    To clarify what I'm doing it for, I have a chat client and, not relevant for this task, a chat server. The chat client will always be downloaded from a web server running on the same IP as the chat server (on different hardcoded ports). I don't want a user to need to input the IP, as it will always be the same IP as the one it's just downloaded the client from.

    Any ideas on how to go about this?

    Cheers,

    Ollie

    O 1 Reply Last reply 27 May 2021, 13:27
    1
    • O Ollie_A
      12 Dec 2020, 15:34

      Hi all, I'm wondering if there's any way to get the local IP (or URL) of the web server hosting a Qt WASM program, from the program? From what I've seen through looking online, it seems it can be done through javascript, but I'm not sure how I'd go about it through this, apart from messing around with the generated js gluecode?

      To clarify what I'm doing it for, I have a chat client and, not relevant for this task, a chat server. The chat client will always be downloaded from a web server running on the same IP as the chat server (on different hardcoded ports). I don't want a user to need to input the IP, as it will always be the same IP as the one it's just downloaded the client from.

      Any ideas on how to go about this?

      Cheers,

      Ollie

      O Offline
      O Offline
      ocgltd
      wrote on 27 May 2021, 13:27 last edited by
      #2

      @Ollie_A Although 1.5 years old, did you ever solve this? I'm trying to figure out the same

      1 Reply Last reply
      1
      • K Offline
        K Offline
        Karmo
        wrote on 2 Jun 2021, 20:32 last edited by
        #3

        You can use emscripten API to read the JavaScript window.location object.

        #include <emscripten/val.h>
        ...
        emscripten::val location = emscripten::val::global("location");
        auto host = location["hostname"].as<std::string>();
        auto port = location["port"].as<std::string>();
        
        1 Reply Last reply
        3

        • Login

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