PDA

View Full Version : emit Signals



Fastman
22nd August 2007, 12:28
what does not work ???



class CWorkThread : public QThread
{
Q_OBJECT

public:
CWorkThread(QObject *parent);
~CWorkThread();
void run();

public slots:
void FinishProc();

};




void CWorkThread::run()
{
CWorkFiles *files = new CWorkFiles;
connect(files,SIGNAL(finished()),this,SLOT(FinishP roc()));
QApplication::beep();
exec();
}


this block newer running !


void CWorkThread::FinishProc()
{
QApplication::beep();
}


--------------------------



class CWorkFiles : public QFile
{
Q_OBJECT

public:
CWorkFiles(QObject *parent = 0);
~CWorkFiles();

qint16 CopyFile(QString cSrc, QString cDst);
qint16 MoveFile(QString cSrc, QString cDst);
qint16 DeleteFile(QString cPath);
qint16 IsFileExists(QString cPath);

signals:
void finished();

};




qint16 CWorkFiles::CopyFile(QString cSrc, QString cDst)
{
emit finished();
return 1;
}

marcel
22nd August 2007, 12:37
Does CopyFiles ever gets called?

jpn
22nd August 2007, 12:37
I don't see CWorkFiles::CopyFile() getting called anywhere.

PS. You should allocate that CWorkFiles object on stack (without new).

Fastman
22nd August 2007, 12:53
yes, called !


CWorkFiles::CWorkFiles(QObject *parent)
: QFile(parent)
{
CopyFile("d:\\6.2-RELEASE-i386-docs.iso","d:\\tmn.iso");
}

and rewrite:


void CWorkThread::run()
{
CWorkFiles files;
connect(&files,SIGNAL(finished()),this,SLOT(FinishProc()));
QApplication::beep();
exec();
}

but no effect !

marcel
22nd August 2007, 13:02
It is because you make the connection after the function is getting called, in the constructor.

Call it after you make the connection, outside the constructor, or make the connection inside the constructor.

Regards

Fastman
22nd August 2007, 13:14
thx !!! it's work :)