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. Using QThread
QtWS25 Last Chance

Using QThread

Scheduled Pinned Locked Moved General and Desktop
11 Posts 7 Posters 5.1k Views
  • 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.
  • Q Offline
    Q Offline
    qwertyuiopearendil
    wrote on last edited by
    #1

    Hi All,
    I'm using an application that uses QThread, only one, it provides the new chart that i should show into my QGraphicsObject Class.
    My Question is:
    If i should request another chart when my thread is running, what can i do to send a new chart request to my thread even if it already running to provide the old one?
    Thanks.

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

      Signals and slots come into mind...

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

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qwertyuiopearendil
        wrote on last edited by
        #3

        I cannot use them, in my my mind the best thing should be for example call start when i must recalc the chart, but i've read into documentation that if i call start when thread is still running it doesn nothing.

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

          [quote author="qwertyuiopearendil" date="1299610629"]I cannot use them[/quote]

          Oh, of course ... how could I miss that. My false, sorry.

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

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Franzk
            wrote on last edited by
            #5

            [quote author="Volker" date="1299611262"][quote author="qwertyuiopearendil" date="1299610629"]I cannot use them[/quote]

            Oh, of course ... how could I miss that. My false, sorry.[/quote]
            Aaah! !http://circleofcrones.co.uk/images/smilies/sarcasm.gif!

            qwertyuiopearendil, you are probably shooting yourself in the foot by not using signal-slot connections here...

            "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

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

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qwertyuiopearendil
              wrote on last edited by
              #6

              I'm using thread to handle when a valid chart is ready, but can happen that I should invalidate the last one calc to recalc, and this could happen when a thread is running.
              Thanks.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                Read something like: "this":http://developer.qt.nokia.com/wiki/ThreadsEventsQObjects to get some more ideas.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

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

                  I guess it depends on the code in your thread that generates your chart for you. I am assuming, based on your hints above, that this is probably a single procedure of some kind that does not return to the event loop of the thread, making it impossible for (queued) signals to be delivered in to your thread in the meantime.

                  So, you need to create some way your procedure can be interrupted. One way would be to check if a cancel flag has been set at regular intervals. You can set such a flag using a direct method call (you can use a signal/slot connection, but not a queued connection as will be the default between threads). If a request for a new chart comes in while you are already processing a current chart, what I would do is to queue the request, set a cancel flag for the current request, and have your thread check after it is cancelled if there is a new request in the queue, and if so, process it.

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

                    Or call one of the "QCoreApplication::processEvents() ":http://doc.qt.nokia.com/4.7/qcoreapplication.html#processEvents methods regularly (seems you are in a kind of loop anyways) and have the events delivered and the slots called.

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

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      luca
                      wrote on last edited by
                      #10

                      You can try this:
                      @
                      void MyThread::restartMe()
                      {
                      m_stopMe = true;
                      while(this->isRunning())
                      {
                      //wait and do nothing
                      }
                      this->start();
                      }

                      void MyThread::run()
                      {
                      ...
                      if(m_stopMe)
                      return;
                      ...
                      if(m_stopMe)
                      return;
                      ...
                      if(m_stopMe)
                      return;
                      ...
                      }

                      @
                      So you can call restartMe from outside of the QThread to restart the thread.

                      1 Reply Last reply
                      0
                      • Z Offline
                        Z Offline
                        ZapB
                        wrote on last edited by
                        #11

                        Take a look at the Mandelbrot example that ships with Qt. It uses the pattern you are after here I think.

                        Nokia Certified Qt Specialist
                        Interested in hearing about Qt related work

                        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