Friday 15 June 2012

c++ - Want to put a method into a QThread -


How to add a thread within the class to execute the thread?

I do not want to put "Pig" into a separate class which inherited Quetta because it is an abstract example of some legacy code. I; } Zero dogs: Init () {Koothhade * Dogthread = New Qtith (); Pup- & gt; MoveToThread (dogThread); // It's all wrong Pup- & gt; Connect (dogThread,?, Puppy, slot (puppy),?) DogThread.start (); }

Try it out:

  Zero dogs: : Init () {Quitet * DogStread = New Qt; Connect (dogthread, signal (start ()), this, slot (pig ()), qt :: directconnection; DogThread- & gt; Start (); }   

It basically creates a new qthread named dogThread and adds it to start () To indicate which method you want to run inside the thread ( dog :: pig () , it should be a slot.)

When you type Qt: : Using the QueuedConnection slot will be executed in the receiver's thread, but when you use Qt :: DirectConnection , the slot will be applied immediately, and because < Code RT () code> Dogthred , the slot will be added to the dogThread . You get more information about connection types here:.

No comments:

Post a Comment