Updating a text/variable remotely using the simplest way
-
Hi all,
Assume the simplest situation where we have a text "one" or int variable "3" in a QML app installed on an Android device and we want to update that text to "two" or the int to "4", remotely, through the Internet.
I know there might be many ways for that like using a website which is connected to the app, or using another app which is once again connected to our first app and they send "two" or "4" and the text or integer value will be updated/changed.
But what is the simplest way, in your points of view please?
-
@tomy said in Updating a text/variable remotely using the simplest way:
for QML as well?
yes,you can use every class in qml just make your class reachable
-
Thank you very much friends.
Sorry, I must change my mind a little bit and ask you for guidance following which I can eventually create the apps (client-server) I want for this project.The project description is below. Please read it carefully so that you best conduct me. :)
1- Our client app is installed on many Android mobiles roaming around the city or maybe even in different cities. So no shared network; the server app must connect to them through the Internet. So, it's a "one-way" connection. The clients only see the changes made by the server.
2- The server app is installed on one Android device, the admins' device, and controls all of those apps installed on the clients' devices, for example, by changing the text or the int value we mentioned earlier.
So the code is very simple. Just a text or int or maybe both are involved.
Clear up to now?Interestingly, I want to do all the back-end in C++, and the design (front-end) using QML. This will be the first project I will be familiar with using C++ in a QML app. :)
Now it's time to get my feet wet. I guess I firstly must be familiar with the stuff I need for the project. After that start studying them until I master them to a good extent, and then begin writing the project practically. Right?
So please tell me, what should I study for that project, and where to start the first step.
Thanks so much. I hope I finally succeed in creating the apps, and also will learn many new things about Qt. :)
-
Sorry, I must change my mind a little bit and ask you for guidance following
No problem, I'm happy top help, if I can!
1- Our client app is installed on many Android mobiles roaming around the city or maybe even in different cities. So no shared network; the server app must connect to them through the Internet. So, it's a "one-way" connection. The clients only see the changes made by the server.
As far has such a thing can be one way, but I get it I think, the users are readonly
2- The server app is installed on one Android device, the admins' device, and controls all of those apps installed on the clients' devices, for example, by changing the text or the int value we mentioned earlier.
So the code is very simple. Just a text or int or maybe both are involved.
Clear up to now?sure, you update data on your server and want to notify connected users.
I want to do all the back-end in C++, and the design (front-end) using QML.
perfectly balanced, as all things should be
Now it's time to get my feet wet. I guess I firstly must be familiar with the stuff I need for the project. After that start studying them until I master them to a good extent, and then begin writing the project practically. Right?
If that works for you, sure.
When I start to work in a new area, I usually read up on the basics, look up some examples and then create an example on my own. From there on I just wing it. But shht, don't tell my employer ;-)So please tell me, what should I study for that project, and where to start the first step.
well you need some kind of server and client application and a way to connect them.
For the sever you can go with some kind of http server and your client would regularly make get requests.Or, what I would suggest, TCP connection via Internet.
Take a look at the fortune server/client exampleIt is set up for an local area network, but adapting it for your purpose should be doable. (few easy steps on qt side (if at all) and some major steps on your router/firewall etc ;-) )
-
As far has such a thing can be one way, but I get it I think, the users are readonly
Yes. For this stage of the project, I want the users are read-only ones; that is they only can see the changes.
sure, you update data on your server and want to notify connected users.
Yes. When the variables change, the users are notified.
If that works for you, sure.
When I start to work in a new area, I usually read up on the basics, look up some examples and then create an example on my own. From there on I just wing it. But shht, don't tell my employer ;-)Hhhhhhh. :-) I won't! ;-)
I exactly want to go through the same way. But both of us must be sure about the details to decide what basic things and examples are needed to be thoroughly read.well you need some kind of server and client application and a way to connect them.
For the sever you can go with some kind of http server and your client would regularly make get requests.
Or, what I would suggest, TCP connection via Internet.
Take a look at the fortune server/client example
It is set up for an local area network, but adapting it for your purpose should be doable. (few easy steps on qt side (if at all) and some major steps on your router/firewall etc ;-) )But I don't have a router/server etc! I just want to do the job by two QML projects, one as an admin app on one Android device, and the other project on many Android devices as clients.
-
What do you think of this method? Please tell me if you agree.
Implementing my own publish/subscribe service using QWebSockets and nodejs's websockets. And using Firebase as the interface so that it can get data from the server app and delivers it to the client apps.
Probably QWebSockets is used for publish side of the service and nodejs's websockets is used for the subscribe side of the service.
-
@tomy said in Updating a text/variable remotely using the simplest way:
Implementing my own publish/subscribe service using QWebSockets
In that case, you may want to look at MQTT protocol, which has a pub/sub model using websockets, and the Qt MQTT module implementing that...
-
Thank you.
But the problem is I'm too new to this complicated task and just want to both do the job and also learn new things. So I know nothing about whether the method is a right one or not and if yes, what items collectively I should study.
So for now I need two things:1- Is the method I mentioned good for my purpose?
2- If so, what is the most basic part for that method I take and go through? -
@tomy
router and server are just terms,The application that provides the data, is the server, the application that receives the data is the client.
If you want outside connections to your 'server' you will most likely need a static Ip and at least 1 port open, for port forwarding to your server.
You could start with the fortune client/server example.
Modify it so, that the server sends a new fortune to all clients every 10 seconds or so.Should be a good start.
-
Thank you.
I think if I use Firebase I won't need a static IP.Anyhow, I go for the fortune client/server example and my road map will be like the following way seemingly, making me have to:
1- firstly learn how to use C++ in a QML app and for that I start from this Overview - QML and C++ Integration.
2- learn how to modify that fortune client/server example into a QML project and understand it thoroughly.
3- do what you said: "Modify it so, that the server sends a new fortune to all clients every 10 seconds or so."