Qthread Call the external sub-function how to emit the information

Source: Internet
Author: User
Tags emit

Create a child thread, traverse the folder, and print the information on the main interface.

1. Subclass Qthread can generate a new thread and refactor virtual function run (). A child thread communicates with the main thread using the Signal-slot mechanism, which sends the information through the emit signal ("information") to the main thread

Class Newthread:public Qthread

{Q_object

Public:newthread (const QString strval) {filepath=strval; };

Protected:void run ();

Private:qstring filepath;

Signals:void testsignal (QString);

};

void Newthread::run () {

wchar_t path[260]={0};

Filepath.towchararray (path);

Emit testsignal (filepath); }

2. The thread class is first generated in the main thread and then run, in Connect, to process the received information in the slot function.

Newthread *playthread = new Newthread ((const QString) S.path ());
Playthread->start ();
Connect (Playthread, SIGNAL (testsignal (QString)), this, SLOT (GetInfo (QString)));

3. Call the external sub-function in the child thread, but the emit mechanism is not available in the external function, how to pass the information in the child function to the child thread in the emit? (with a callback function?) )

Qthread Call the external sub-function how to emit the information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.