PDA

View Full Version : Confusing in thread implementation



santosh.kumar
16th May 2007, 11:07
QDirThread::QDirThread(QObject *parent):QThread(parent)
{
m_bAbort = false;

}
QDirThread::~QDirThread()
{
m_bAbort = true;
m_dirWaitCondition.wakeOne();
wait();
}

void QDirThread::dirThreadView(QString dirPath)
{
QMutexLocker locker(&m_dirMutex);
this->m_strDirPath = dirPath;
this->strErrorMessage = "error in creating directory view";

if (!isRunning()) {
start(LowPriority);
} else {
m_bAbort = true;
m_dirWaitCondition.wakeOne();
}
}
void QDirThread::run()
{
QString strPath = m_strDirPath;
QString strError = strErrorMessage;
QTreeWidgetItem *pItem = NULL;
pItem = new QTreeWidgetItem;
if(!m_bAbort)
{
showDirView(pItem,strPath);
}

}

void QDirThread::showDirView(QTreeWidgetItem* pTreeItem,QString dirViewPath)
{
QDir dirPath(dirViewPath);
QTreeWidgetItem *pFileTree = NULL;
QFileInfoList dirList= dirPath.entryInfoList();
for(int i=0;i<dirList.size();i++)
{
QFileInfo strFileInfo = dirList.at(i);
QString strFileName = strFileInfo.fileName();

if(!(strFileInfo.fileName() == "." || strFileInfo.fileName() == ".."))
{

if(strFileInfo.isDir())
{
m_pTreeItem = new QTreeWidgetItem(pTreeItem);
m_pTreeItem->setText(0,strFileInfo.fileName());
pTreeWidget->expandItem(m_pTreeItem);

QString strFilePath = dirViewPath + "/" + strFileInfo.fileName();
QString fileName = strFileInfo.fileName();
if(!m_bAbort)
{
showDirView(m_pTreeItem,strFilePath);
}
}
else
{
if(!m_bAbort)
{

pFileTree = new QTreeWidgetItem(pTreeItem);
pFileTree->setText(0,strFileInfo.fileName());
pTreeWidget->expandItem(pFileTree);
}
}
}

}
}


How i create this Gui treeWidget in other class...here there is need of treeWidget to recursivly show...if i place this recursive function in other class and call this method using object in run() method it is crashing..

can u give example for this ....