我从工作线程收到一个信号,并通过C ++ Singleton(CTaskManager)重新发送到qml。
void CTaskManager::runAsync(CTask* task)
{
Q_CHECK_PTR(task);
QThread* thread = new QThread();
task->moveToThread(thread);
connect(this , SIGNAL(canceled()) , task , SLOT(cancel()) , Qt::DirectConnection);
connect(task , SIGNAL(progressChanged(float)) , this , SLOT(setProgress(float)) , Qt::DirectConnection);
connect(task , SIGNAL(finished(bool,unsigned int, const QVariantMap&)) , this , SLOT(setFinished(bool,unsigned int, const QVariantMap&)) , Qt::DirectConnection);
connect(thread , SIGNAL(started()) , task , SLOT(run()));
connect(task , SIGNAL(finished(bool,unsigned int, const QVariantMap&)) , thread, SLOT(quit()));
connect(thread , SIGNAL(finished()) , task , SLOT(deleteLater()));
connect(thread , SIGNAL(finished()) , thread, SLOT(deleteLater()));
thread->start();
}
void CTaskManager::setFinished(bool canceled, unsigned int error, const QVariantMap& args)
{
emit this->finished(canceled, error, args);
}
这适用于LINUX下的Qt Creator 4.6.1。当我在Windows下运行相同的项目时,我在qml信号连接中只得到未定义的参数。
Connections
{
target: TaskManager
onFinished:
{
}
}
有什么想法吗?
答案 0 :(得分:0)
这似乎是Qt 5.11中的一个已知的错误。