Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Hints for web-application with Qt5 server-side code



  • I wonder what the best approach for a web-application with these requirements:

    • needs server-side code to push content
    • the content itself is already retrieved by a Console Qt5 application
    • needs a async channel to exchange data (i.e. websockets) along with the common submit pattern

    No problems with the last two points.
    About the first one, I have few questions:

    1. as far as I know Qt5 is not usable to write server-side code directly. But if I write my web application using, say, PHP how would I exchange data with my Qt application?

    2. if this approach is still valid, who should handle the web socket communication? PHP or Qt5?

    Any idea is very appreciated. Of course feel free to ask further details!


  • Lifetime Qt Champion

    Hi,

    1. You likely want to take a look at the cutelyst project.
      If you are talking about e.g. a REST service that should be consumed by the client, the fact that it is implemented in PHP, C++, Python or any other language doesn't play any role in terms of exchanging data. That's defined by the standard you want to use, not the language you used to implement it.

    2. What approach ?



  • I meant the approach described in the previous line: write the server-side code in PHP and exchange data between the Qt5 console application to retrieve/send data.

    No, I'm not talking about a REST service.
    I try with an example, then I read the cutelyst project link.

    There is a field with several machines (PLCs). They are connected to an embedded board using RS485 serial.
    On the embedded board runs my Qt5 console application that handles all the modbus communications with the PLCs, stores their data into an SQL database, writes logs, sends TCP telemetry to custom services, etc...

    Now I need to write a web application - I mean dynamic HTML pages - to interact with my application. For example a table to read and update the parameters, an overview to see the state of each PLCs, etc... Of course all this information are available inside my Qt5 Console application.

    I'm used to write such a web application using PHP on server-side and HTML5/js on client-side.
    But usually the whole application is created in PHP! In this scenario all the data is inside the Qt5 application (real-time data) and in the SQL database (settings, past data) and I'm not sure how to exchange this information between PHP and Qt5. For example I need to:

    • retrieve the settings value to create a table with their value
    • receive the new value of a settings via websocket and update it
    • receive the whole set of parameters via a form submit and update them
    • display the real-time data on the web-page
    • ...

  • Moderators

    @mark81

    take a look at this website, it deals with Qt and integrating Web content
    https://doc.qt.io/qt-5/topics-web-content.html

    since last update there's also now Qt for WebAssembly which could be interesting for your case ?



  • @j-hilk Thanks for the link. I think these classes are very useful for communications between the client and the server.
    The only point that is still missing is the server-side code to generate dynamic content.

    You have, say 1200 parameters (well, the actual application has more) to display and let the user to edit them.
    In PHP you can query the data from the database, page the records, write the HTML code on the fly and push to the client.

    How would you do the same with Qt5?
    Or, if it's not worth to, how to pass the data to the PHP scripts so they can create the dynamic web-page?


  • Lifetime Qt Champion

    One thing I'm not sure you are not over-engineering: it looks like you want to build a big application that does everything.

    You already have the backend running with your console application. Then why not just plug the frontend on the same database and let it run on its side whatever the technology you prefer ?



  • @sgaist said in Hints for web-application with Qt5 server-side code:

    Then why not just plug the frontend on the same database and let it run on its side whatever the technology you prefer ?

    Because as said not all data is stored into the db.
    Most information are available in real-time only. I don't think is a good idea to continuously update hundreds of records every second 24/7...



  • @mark81 said in Hints for web-application with Qt5 server-side code:

    I don't think is a good idea to continuously update hundreds of records every second 24/7...

    Just change the update frecuency :-)



  • @mark81 said in Hints for web-application with Qt5 server-side code:

    Because as said not all data is stored into the db.

    Have you consider the MQTT protocol? Qt does support it.

    Your Qt console app (talking to the devices/sensors) will be a publisher to a MQTT broker server, and then your web-based GUI app (very like running in the same host as the MQTT broker) will be a subscriber to whatever topics you want to display online...


  • Moderators

    @mark81 said in Hints for web-application with Qt5 server-side code:

    @j-hilk Thanks for the link. I think these classes are very useful for communications between the client and the server.
    The only point that is still missing is the server-side code to generate dynamic content.

    You have, say 1200 parameters (well, the actual application has more) to display and let the user to edit them.
    In PHP you can query the data from the database, page the records, write the HTML code on the fly and push to the client.

    How would you do the same with Qt5?
    Or, if it's not worth to, how to pass the data to the PHP scripts so they can create the dynamic web-page?

    I'm sorry, that is not really my forte. I know classes exists, So I linked them, but I haven't used them myself yet


Log in to reply