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