Home > Mobile >  Qt signal back to the main thread trough, the signal after the groove function does not perform
Qt signal back to the main thread trough, the signal after the groove function does not perform

Time:10-09

Using qt qthread new thread processing data, processing is completed, using the constructor of the return to conne qt signals and slots (queuedconnection) ct main thread, but the signal was given and the groove function does not perform!

CodePudding user response:

You parameter is defined by yourself?
If it's own definition, have to register

CodePudding user response:

reference 1/f, walk every step response:
you define your own parameters?
If it's own definition, have to register

Not defined themselves, don't pass parameters

CodePudding user response:

refer to the second floor mike to reply:
Quote: refer to 1st floor walk every step response:
you define your own parameters?
If it's own definition, have to register

Not defined themselves, and not the parameter


Code to come out

CodePudding user response:

ThreadFunc: : ThreadFunc (QObject * parent) :
QThread (parent)
{
The connect (this, SIGNAL (SIGNAL ()), and this, SLOT (AfterFunc ()), Qt: : QueuedConnection);
}

ThreadFunc: : ~ ThreadFunc ()
{
Release ();
}

Void ThreadFunc: : run ()
{
//...
Emit Signal ();//signal
}

Void ThreadFunc: : AfterFunc ()//slot function
{//not come??
//...
}




reference 3 floor walk every step response:
Quote: refer to the second floor mike to reply:

Quote: refer to 1st floor walk every step response:
you define your own parameters?
If it's own definition, have to register

Not defined themselves, and not the parameter


Code to come out

CodePudding user response:

Haven't run into, integrity code?

.h
.cpp

All post


You can refer to the QThread document (QT's own document)

CodePudding user response:

Signal receiver call the following function to you,
And start the thread thread - & gt; Start ()
The receiver - & gt; MoveToThread (thread);

CodePudding user response:

 class WorkerThread: public QThread 
{
Q_OBJECT
Void the run () override {
QString result;
/*... Here is the expensive or blocking operation... */
Emit resultReady (result);
}
Signals:
Void resultReady (const QString & amp; S);
};

Void MyObject: : startWorkInAThread ()
{
WorkerThread * WorkerThread=new WorkerThread (this);
The connect (workerThread, & amp; WorkerThread: : resultReady, this, & amp; MyObject: : handleResults);
The connect (workerThread, & amp; WorkerThread: : finished, WorkerThread, & amp; QObject: : deleteLater);
WorkerThread - & gt; Start ().
}

CodePudding user response:

Learn how to use QT Creator in the help documents

CodePudding user response:

In the Run call the connect (this, SIGNAL (SIGNAL ()), this, SLOT (AfterFunc ()), Qt: : QueuedConnection);

CodePudding user response:

Also run to block, block will not directly out of threads, return how to call?

CodePudding user response:

references 9 f hzh_Beyond response:
in the Run call the connect (this, SIGNAL (SIGNAL ()), and this, SLOT (AfterFunc ()), Qt: : QueuedConnection);



Do not need to connect in the run, also don't have to be blocked,
Good or official reference example,

CodePudding user response:

Suggest that the original poster learning under win32 programming

Recommended books
Windows core programming foreigners write
Wang yan zheng zhang Windows programming

CodePudding user response:

refer to 12th floor walk every step response:
suggest that the original poster learning under win32 programming

Recommended books
Windows core programming foreigners write
Windows programming wang yan zheng zhang

Thank you very much for your case, I will try to continue to learn this knowledge, and I would like to know what was wrong with my code? Nor has been back to less than the main thread, sometimes can sometimes not, I think is a time-consuming operation, auxiliary thread has been completed to send signals to the main thread slot (function)

CodePudding user response:

references to the tenth floor hzh_Beyond response:
also run to block, block will not directly exit threads, return how to call?

Why don't you block will exit?

CodePudding user response:

refer to 6th floor csdnwingwu response:
signal receiver call the following function to you,
And start the thread thread - & gt; Start ()
The receiver - & gt; MoveToThread (thread);

A thread - & gt; Start ().

Call the receiver - & gt; MoveToThread (thread); ?

CodePudding user response:

Direct look at the official examples, reference can write that the


Or stick you complete code come out, you stick a half, how to let others help you?

CodePudding user response:

2 floor post what you can do, you don't want to drag,,
What valuable source of business,,,,,,,,

CodePudding user response:

on the 14th floor pockmarked references to reply:
Quote: reference to the tenth floor hzh_Beyond response:
also run to block, block will not directly exit threads, return how to call?

Why don't you block will exit?


Probably understand your approach, the child thread processing is completed, the signal is sent to the main thread and then exit the child thread, you are in the use of the child thread should be a new one, delete after the thread is? After you try the child thread signal qsleep (100), dormancy 100 ms to see can solve the problem of sometimes can sometimes not,

CodePudding user response:

After the new thread object, invoke the start method?

CodePudding user response:

It is recommended to use the connect (this, SIGNAL (SIGNAL ()), this, SLOT (AfterFunc ()), Qt: : DriectConnection);
Or the connect (this, SIGNAL (SIGNAL ()), and this, SLOT (AfterFunc ()), Qt: : BlockingQueuedConnection);

null
  •  Tags:  
  • Qt
  • Related