Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to run something in background
Forum Updated to NodeBB v4.3 + New Features

How to run something in background

Scheduled Pinned Locked Moved General and Desktop
6 Posts 6 Posters 7.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    endla.ravi
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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/

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • I Offline
          I Offline
          Immii
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vcsala
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rugginoso
              wrote on last edited by
              #6

              And this is not the case :D

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved