c++ - MovetoThread problems with custom Qobject -


I am new to QThreads and could not understand why I did not get a new thread ID for my class. But first about my basic problem some basic

I have a normal C ++ class, which requires long time to calculate, gives the name Heavybase class I have no QT element in this class.

My goal is to calculate this square in its thread so that GUI can run normal during computing.

I have read some implementation for the Qt threading problem and I decided to use QTthread with a QObject. It may be possible to stop this thread and with my first try Qt Conquer was not possible.

Because I have created my own QObject: h.file:

  # include & lt; QObject & gt; #include & lt; HeavyBaseClass.h & gt; Class Captimization: Public Q Object, Heavyboxecas {Q Object Public: Coopermization (Heavyweight Class Input Parameter, QoBect * Parents = 0); Zero debug and fed (); Hint: public slot:}; #endif // QOPTIMIZATION_H   

CPP file:

  #include "qoptimization.h" # include & lt; QDebug & gt; # Include & lt; QThread & gt; Cooptimization :: Cooptimization (HeavyBase class INPUT parameter, Q object * Parent): Quoabetget (parent), heavybase class (input parameter) {qDebug () & Lt; "Init Thread" & lt; & Lt; This- & gt; Thread () - & gt; Current threadid (); } Zero Qoptimization :: debugThread () {qDebug () & lt; & Lt; "Current thread" & lt; & Lt; Thread () - & gt; Current threadid (); }   

Now I call it on my main window

  qDebug () & lt; & Lt; "Main thread" & lt; & Lt; This- & gt; Thread () - & gt; CurrentThreadId (); Coupitimization Captimization (F); QThread * customizationTrade = new qthread (); QDebug () & lt; & Lt; "Before going to a thread" & lt; & Lt; Qoptimization.thread () - & gt; CurrentThreadId (); Qoptimization.moveToThread (optimizationThread); OptimizationThread- & gt; Start (); Qoptimization.debugThread (); QDebug () & lt; & Lt; "After running the thread" & lt; & Lt; Qoptimization.thread () - & gt; CurrentThreadId ();   

The problem I am unable to understand is that my Thread ID is the same on Alle Output.

DEBUG INFORMATION: Thread 0xd88 after running the current thread 0xd88 before running the main thread 0xd88 init thread 0xd88 thread to 0xd88

Do you have an idea what I did? Update:

New CPP

  Zero Coupling :: Debug and Fred & Lt; In "Debug ThreadedTrade ()" in & lt; & Lt; QThread :: currentThread (); QDebug () & lt; & Lt; "In debug threads threads" & lt; & Lt; Thread (); If (QThread :: currentThread ()! = Thread ()) {// Force slot object to be emmited in the object QTimer :: singleShot (0, this slot (debugthread ()); Return; }}   

Output:

  The main thread 0x156c init thread 0x156c debugThred currentThread () in the qthread (0xeccc00) debugThread thread qthread (before going to thread 0x156c) 0x156c  

is a STATIC member of QThread according to the documentation after running If you always print Caller thread ID, you should print the (quint64) qoptimization.thread () object member.

If you have your member zero debug and fred () ; want to execute In another thread - you should declare it as a slot and do not call the Directorate. You should call it connected signal, object metadata or timer. Try the next code:

  Public Slots: Zero Qoptimization :: debugThread (); Zero Qoptimization :: debugThread () (If (QThread :: currentThread ()! = Thread ()) {// Force slot object to be emmited in thread QTimer :: singleShot (0, this, slot (debugthread () (Fred)); Return; } QDebug () & lt; & Lt; "Current thread" & lt; & Lt; Thread () - & gt; Current threadid (); }   

There are good samples but first of all, you should understand the system.

------- Pseudocode for comment:

  class MyClass {int thread () const {return m_id; } Zero step toothrhead (int throttled) {m_id = threadid; } Int m_id; } Myclass A; Const int curTread = 1; A.moveToThread (2); QDebug () & lt; & Lt; Quebrate & Lt; & Lt; "" & Lt; & Lt; a thread(); // Output: 1/2 // is already different!    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -