class Data{ ... Data() { ... } ... QString dataFast; QString dataSlow; bool bIsLoaded;};QVariant QDataListModel::data(const QModelIndex &index, int role) const{ if (!index.isValid()) return QVariant(); if (role == Qt::DisplayRole) { Data* pData = static_cast<Data*>(m_List.at(index.row())); if (index.column() == 0) { return pData->dataFast; } else if (index.column() == 1) { if(pData->bIsLoaded) return pData->dataSlow; else return QVariant(); } } return QVariant();}QVariant QDataListModel::GetData(const QString data){ thread->Stop(); while(!thread->wait()); LoadData(&m_List); thread->start();}QLoaderThread::QLoaderThread(QObject *parent) : QThread(parent){ m_bStop = false;}QLoaderThread::~QLoaderThread(){}void QLoaderThread::run(){ m_mutex.lock(); m_bStop = false; QDataListModel* pModel = qobject_cast<QDataListModel*>(this->parent()); for(int i=0; i<=pModel->m_List.count()-1; i++) { if(m_bStop) { break; } Data* pData = static_cast<Data*>(pModel->m_List[i]); pData->dataSlow = GetSlowData(pData->fastData); pData->bIsLoaded = true; pData = 0; emit pModel->reset(); } pModel = 0; m_mutex.unlock();}void QLoaderThread::Stop(){ m_mutex.lock(); if(!m_bStop) m_bStop = true; m_mutex.unlock();}
mutex.lock();bIsLoaded =TRUE;mutex.unlock();
if(!p->mutex.tryLock () && pData->bIsLoaded) return pData->dataSlow; else return QVariant();
pModel->m_List[i]