Important: Please read the Qt Code of Conduct -

How to run something in background

  • Hi...

    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..

  • 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": like "QTcpSocket": 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":

  • 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.

  • 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.

  • You can find pepe's article on the wiki "here": It also gives you some hint in which cases it is not required to use threads.

  • And this is not the case :D

Log in to reply