merry
5th January 2009, 09:20
Hi All
Working on Qt4.4.3, using my intel mac machine. What I am trying to do is,
I am selecting a file/folder using QFileDialog, and open that file in read write mode and writing that file with some other text, For this process I am using thread, I am selecting file in one class, and after selection i called thread , Using thread , I called some other class for writing on that selected file . For writing on the file, i want to run progressBar, till the writing completes, but its not working, i dont know why,
void ClassWrite::fnWriteFile(FILE *fp, int nFillWith)
{
unsigned long value = 0;
int iProgressCounter = 0;
long long llSizeRead = 0;
unsigned long SizetoRead =0;
long long SizeRead = 0;
QFileInfo filename(m_FileName);
llSizeRead = filename.size();
QString strMessage = "";
unsigned char *pBuffer = NULL;
unsigned long dwBufferValue = 4*1024*1024;
pBuffer = (unsigned char *)calloc(dwBufferValue,sizeof(unsigned char));
if(pBuffer == NULL)
return;
strMessage = "WritingFile " + m_FileName;
emit ProgressMaximumValue(100);
qApp->processEvents();
while(llSizeRead>0)
{
if(bStopFlag)
break;
if(llSizeRead>dwBufferValue)
{
SizetoRead = dwBufferValue;
value = ((SizetoRead/llSizeRead)*100);
if(iProgressCounter == 0 || iProgressCounter == 100)
{
emit SetProgressValue(strMessage,value);
qApp->processEvents();
memset(pBuffer,nFillWith,SizetoRead);
fseek(fp, 0+SizeRead, SEEK_CUR);
fwrite((void*)pBuffer,SizetoRead,1,fp);
llSizeRead-=SizetoRead;
SizeRead = SizetoRead;
iProgressCounter = 0;
}
iProgressCounter++;
}
else
{
SizetoRead = llSizeRead;
value = ((SizetoRead/llSizeRead)*100);
if(iProgressCounter == 0 || iProgressCounter == 100)
{
emit SetProgressValue(strMessage,value);
qApp->processEvents();
memset(pBuffer,nFillWith,SizetoRead);
fseek(fp, 0+SizeRead, SEEK_CUR);
fwrite((void*)pBuffer,SizetoRead,1,fp);
llSizeRead-=SizetoRead;
SizeRead = SizetoRead;
iProgressCounter = 0;
}
iProgressCounter++;
}
}
fflush(fp);
if(pBuffer)
{
free(pBuffer);
pBuffer = NULL;
}
}
Pls suggest me something
Working on Qt4.4.3, using my intel mac machine. What I am trying to do is,
I am selecting a file/folder using QFileDialog, and open that file in read write mode and writing that file with some other text, For this process I am using thread, I am selecting file in one class, and after selection i called thread , Using thread , I called some other class for writing on that selected file . For writing on the file, i want to run progressBar, till the writing completes, but its not working, i dont know why,
void ClassWrite::fnWriteFile(FILE *fp, int nFillWith)
{
unsigned long value = 0;
int iProgressCounter = 0;
long long llSizeRead = 0;
unsigned long SizetoRead =0;
long long SizeRead = 0;
QFileInfo filename(m_FileName);
llSizeRead = filename.size();
QString strMessage = "";
unsigned char *pBuffer = NULL;
unsigned long dwBufferValue = 4*1024*1024;
pBuffer = (unsigned char *)calloc(dwBufferValue,sizeof(unsigned char));
if(pBuffer == NULL)
return;
strMessage = "WritingFile " + m_FileName;
emit ProgressMaximumValue(100);
qApp->processEvents();
while(llSizeRead>0)
{
if(bStopFlag)
break;
if(llSizeRead>dwBufferValue)
{
SizetoRead = dwBufferValue;
value = ((SizetoRead/llSizeRead)*100);
if(iProgressCounter == 0 || iProgressCounter == 100)
{
emit SetProgressValue(strMessage,value);
qApp->processEvents();
memset(pBuffer,nFillWith,SizetoRead);
fseek(fp, 0+SizeRead, SEEK_CUR);
fwrite((void*)pBuffer,SizetoRead,1,fp);
llSizeRead-=SizetoRead;
SizeRead = SizetoRead;
iProgressCounter = 0;
}
iProgressCounter++;
}
else
{
SizetoRead = llSizeRead;
value = ((SizetoRead/llSizeRead)*100);
if(iProgressCounter == 0 || iProgressCounter == 100)
{
emit SetProgressValue(strMessage,value);
qApp->processEvents();
memset(pBuffer,nFillWith,SizetoRead);
fseek(fp, 0+SizeRead, SEEK_CUR);
fwrite((void*)pBuffer,SizetoRead,1,fp);
llSizeRead-=SizetoRead;
SizeRead = SizetoRead;
iProgressCounter = 0;
}
iProgressCounter++;
}
}
fflush(fp);
if(pBuffer)
{
free(pBuffer);
pBuffer = NULL;
}
}
Pls suggest me something