qthread中的睡眠调用阻止了UI线程
|
你好
我正在QT 4.6.2中实现一个简单的线程GUI应用程序。我正在使用QThread而不对其进行子类化。我在start()函数中调用了usleep()函数,但这导致GUI冻结。我该如何解决。下面是代码
#ifndef ECGREADER_H
#define ECGREADER_H
#include<QObject>
class ecgreader : public QObject
{
Q_OBJECT
public:
ecgreader(QObject *parent=0);
~ecgreader();
public Q_SLOTS:
void start();
Q_SIGNALS:
void finished();
};
#endif // ECGREADER_H
下面是start()函数
void ecgreader::start()
{
int i= system(\"ls>output.txt\");
SLEEP(10000);
if(i==0)
{
emit finished();
}
}
终于在这里打起电话了
void Application::onbtnclicked()
{
QThread* thread=new QThread;
ecgreader* reader=new ecgreader;
reader->moveToThread(thread);
connect(thread,SIGNAL(started()),reader,SLOT(start()));
connect(reader,SIGNAL(finished()),thread,SLOT(quit()));
connect(reader,SIGNAL(finished()),reader,SLOT(deleteLater()));
connect(reader,SIGNAL(finished()),thread,SLOT(deleteLater()));
reader->start();
}
请帮忙
没有找到相关结果
已邀请:
1 个回复
邪罗逢确胃