虽然这可行,但我有一种奇怪的感觉,我的 QObject 发出的不是线程安全的,而且它还没有爆炸的事实只是运气。
void LoginController::attemptLogin(QString username, QString password)
{
emit loginAttemptStatus(QString("Connecting to service..."));
QFuture<bool> future = QtConcurrent::run([&](QString username, QString password){
// fake a long running operation
QThread::sleep(1);
emit loginAttemptStatus(QString("Connected to service..."));
// a dumb test login
QString u("asdf");
bool success = username.compare( u ) == 0;
if ( success ) {
emit loginAttemptStatus(QString("Success..."));
} else {
emit loginAttemptStatus(QString("Failure..."));
}
return success;
}, username, password);
this->watchLoginAttempt.setFuture(future);
}
那么,捕获引用this
会导致问题吗?
因为我认为是,但我找不到明确的答案。