Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to run something in background
endla.ravi last edited by
how can i run something in background and a form in front..
But when the background process is waiting for something,the form crashes.
How can i do this?...
For example,my server sends some messages at random time intervals,Now my client should observe receive this and inform to to the form at client.
How can i do this?can anyone explain how to implement this with detailed explanation
Thanking u in advance..
goetz last edited by
That depends on what you are doing.
As you mention client and server, it's likely that you use some network protocol for the communication. "QIODevices":http://doc.qt.nokia.com/stable/qiodevice.html like "QTcpSocket":http://doc.qt.nokia.com/stable/qtcpsocket.html work asynchronously by design. Just connect to the signals and process the data that comes in. There are some examples in the Qt sources for a client/server architecture.
Another way is to use QThread, as you already tried in "this thread":http://developer.qt.nokia.com/forums/viewthread/2639/
andre last edited by
There are many ways to do what you want. What is causing your crash, is impossible to diagnose without seeing your implementation. Since you are talking about a "server" that "sends messages", I assume you have an open network connection and that that is the "background process" you refer to. If that assumption is wrong, please correct me.
Qt's network classes are asynchronous in nature. That means that they are meant to be used in the way you need: you set them up, and they will notify you (through signals) when anything interesting happens (like data that arrives). That does mean that you will have to make sure that you keep the eventloop running. That is: no bussy waiting loops or too heavy processing in the same thread as the rest of your application, otherwise both your UI and your network connection will freeze up.
Immii last edited by
You can do it using thread, QThread, you can have a separate thread running in background which can send signal to the thread having form.
vcsala last edited by
You can find pepe's article on the wiki "here":http://developer.qt.nokia.com/wiki/ThreadsEventsQObjects. It also gives you some hint in which cases it is not required to use threads.
rugginoso last edited by
And this is not the case :D