-2

In Qt webassembly documentation there is a mention, than one can use QNetworkAccessManager for HTTP communication with the server that hosts my website. The problem is, that I can't hard-code URL for the server as it should be able to be deployed on any server. Is there a simple way to receive it somehow?

Mariusz Jaskółka
  • 4,137
  • 2
  • 21
  • 47
  • 1
    I don't understand your question. What server would you like to obtain the URL for? Do you have any code demonstrating the problem you're having? – JarMan Oct 26 '20 at 17:50
  • Is [this](https://stackoverflow.com/questions/6042007/how-to-get-the-host-url-using-javascript-from-the-current-page) what you're looking for? – JarMan Oct 26 '20 at 18:09
  • @JarMan The server that hosts a website. The question you linked, but in C++/wasm or Qt. OFC, I could build a bridge to receive it using JS eventually, if there is no a better way. But my intuition tells me it should be. – Mariusz Jaskółka Oct 27 '20 at 06:21
  • My recommendation would be to [edit](https://stackoverflow.com/posts/64483285/edit) your question and give names to programs and server and client machines, and provide some [mre]. **In its current form, *your question is unclear*, so please improve it**, don't comment it. – Basile Starynkevitch Oct 31 '20 at 08:05
  • I have developed a server/client computer vision app before by Qt for wasm. The server(written by Qt5, native codes) process the frames, then send the frames and results to the client(Qt5, wasm), the client can connect to the server by different url(it need to be https). I use websocket to communicate with the client and server. – StereoMatching Mar 12 '21 at 01:34

1 Answers1

0

The problem is, that I can't hard-code URL for the server as it should be able to be deployed on any server. Is there a simple way to receive it somehow?

Yes. Your server program runs a QApplication, and the single instance of that class could get that URL.

In other words, you'll document that your C++ program (the executable file obtained by compilation, e.g. with GCC) foo would accept some --server-url argument, and you would start foo --server-url http://example.com/somestrangeurl/

Please notice that WebAssembly is often running inside Web browsers (that is, inside Web or HTTP clients). Most HTTP servers (e.g. lighttpd) are running on Linux OS (and you might use Wt or libonion or some other HTTP server library for them, if you have to code your HTTP server from scratch).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • It's not server that has to know its own IP. I need it in the clent (web browser) site to be able to send the request for the server. Just like regular JS applications normally does. The only difference here is that I am using Qt/wasm, not JS/html. – Mariusz Jaskółka Nov 01 '20 at 19:51
  • Hi Mariusz I got the same problem and so far looking for a solution. Did you get an answer? – r9guy May 05 '23 at 16:11