自定义信号报错问题。
编译总是出现类似报错:
undefined reference to `myThread::RecDir(QString);
RecDir( QString ) 是我自定义的一个信号。
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QThread>
class myThread : public QThread
{
public:
void run() ;
bool FindFile( QString path );
signals:
void RecDir( QString Dir );
void RecFile( QString File );
};
#endif // MYTHREAD_H
void myThread::run()
{
FindFile( path );
}
bool myThread::FindFile(QString path)
{
QDir Dir(path);
if (!Dir.exists())
return false;
Dir.setFilter(QDir::Dirs|QDir::Files);
Dir.setSorting(QDir::DirsFirst);
QFileInfoList list = Dir.entryInfoList();
int i=0;
do{
QFileInfo fileInfo = list.at(i);
if(fileInfo.fileName()=="." || fileInfo.fileName()==".."){
i++;
continue;
}
bool bisDir=fileInfo.isDir();
if(bisDir){
Dirs.push_back( fileInfo.fileName() );
emit RecDir( fileInfo.filePath() );
FindFile(fileInfo.filePath());
}else{
emit RecFile( fileInfo.filePath() );
Files.push_back( fileInfo.filePath() );
}
i++;
}
while(i<list.size());
}
Dir.setSorting(QDir::DirsFirst);
QFileInfoList list = Dir.entryInfoList();
int i=0;
do{
QFileInfo fileInfo = list.at(i);
if(fileInfo.fileName()=="."
[其他解释]
#include <QtGui/QApplication>
#include "widget.h"
#include "myThread.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
myThread th;
th.start();
QObject::connect( &th, SIGNAL(RecDir(QString)), &w, SLOT(slot_RecDir(QString)));
QObject::connect( &th, SIGNAL(RecFile(QString)), &w, SLOT(slot_RecFiles(QString)));
w.show();
return a.exec();
}
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QThread>
class myThread : public QThread
{
Q_OBJECT
public:
myThread();
protected:
void run() ;
bool FindFile( QString path );
signals:
void RecDir( QString Dir );
void RecFile( QString File );
};
#endif // MYTHREAD_H
#include <vector>
#include <QFileDialog>
#include "qdir.h"
#include "myThread.h"
#include "widget.h"
std::vector<QString>Dirs;
std::vector<QString>Files;
myThread::myThread()
{
}
void myThread::run()
{
FindFile( path );
emit RecDir("a");
}
bool myThread::FindFile(QString path)
{
QDir Dir(path);
if (!Dir.exists())
return false;
Dir.setFilter(QDir::Dirs
[其他解释]
fileInfo.fileName()==".."){
i++;
continue;
}
bool bisDir=fileInfo.isDir();
if(bisDir){
Dirs.push_back( fileInfo.fileName() );
//emit RecDir( fileInfo.filePath() );
FindFile(fileInfo.filePath());
}else{
//emit RecFile( fileInfo.filePath() );
Files.push_back( fileInfo.filePath() );
}
i++;
}
while(i<list.size());
}
这是源码,求解
#include <vector>
#include <QFileDialog>
#include "qdir.h"
#include "myThread.h"
#include "widget.h"
std::vector<QString>Dirs;
std::vector<QString>Files;
myThread::myThread()
{
}
void myThread::run()
{
FindFile( path );
}
bool myThread::FindFile(QString path)
{
QDir Dir(path);
if (!Dir.exists())
return false;
Dir.setFilter(QDir::Dirs
[其他解释]
QDir::Files);
Dir.setSorting(QDir::DirsFirst);
QFileInfoList list = Dir.entryInfoList();
int i=0;
do{
QFileInfo fileInfo = list.at(i);
if(fileInfo.fileName()=="."
[其他解释]
fileInfo.fileName()==".."){
i++;
continue;
}
bool bisDir=fileInfo.isDir();
if(bisDir){
Dirs.push_back( fileInfo.fileName() );
emit RecDir( fileInfo.filePath() );
FindFile(fileInfo.filePath());
}else{
emit RecFile( fileInfo.filePath() );
Files.push_back( fileInfo.filePath() );
}
i++;
}
while(i<list.size());
}