本文整理汇总了C++中ImageProcessor::moveToThread方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageProcessor::moveToThread方法的具体用法?C++ ImageProcessor::moveToThread怎么用?C++ ImageProcessor::moveToThread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageProcessor
的用法示例。
在下文中一共展示了ImageProcessor::moveToThread方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onReplyFinished
void ImageLoader::onReplyFinished()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray data(reply->readAll());
// Setup the image processing thread
ImageProcessor *imageProcessor = new ImageProcessor(data);
m_thread = new QThread(this);
// Move the image processor to the worker thread
imageProcessor->moveToThread(m_thread);
// Invoke ImageProcessor's start() slot as soon as the worker thread has started
connect(m_thread, SIGNAL(started()), imageProcessor, SLOT(start()));
// Delete the worker thread automatically after it has finished
connect(m_thread, SIGNAL(finished()), m_thread, SLOT(deleteLater()));
/*
* Invoke our onProcessingFinished slot after the processing has finished.
* Since imageProcessor and 'this' are located in different threads we use 'QueuedConnection' to
* allow a cross-thread boundary invocation. In this case the QImage parameter is copied in a thread-safe way
* from the worker thread to the main thread.
*/
connect(imageProcessor, SIGNAL(finished(QImage)), this, SLOT(onImageProcessingFinished(QImage)), Qt::QueuedConnection);
// Terminate the thread after the processing has finished
connect(imageProcessor, SIGNAL(finished(QImage)), m_thread, SLOT(quit()));
m_thread->start();
}
} else {
m_label = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
emit labelChanged();
m_loading = false;
emit loadingChanged();
}
reply->deleteLater();
} else {
m_label = tr("Download failed. Check internet connection");
emit labelChanged();
m_loading = false;
emit loadingChanged();
}
}