Thank you wysota and anda_skoa for you help.
@Wysota, I have made my decryt() re-entrant.
{
decryptedContent.clear();
string srcFile=sourceFile.toUtf8().constData();
ifstream ffin;
ffin.open(srcFile.c_str(),ios_base::in|ios_base::binary);
char keyToEncryption= keystring.toLatin1();
if(ffin.is_open())
{
char ch;
while(!(ffin.read(&ch,1).eof()))
{
ch ^= keyToEncryption;
decryptedContent.append(ch);
}
}
ffin.close();
return decryptedContent;
}
{
_decrptedResStr.clear();
string srcFile=sourceFile.toUtf8().constData();
ifstream ffin;
ffin.open(srcFile.c_str(),ios_base::in|ios_base::binary);
char keyToEncryption= keystring.toLatin1();
if(ffin.is_open())
{
char ch;
while(!(ffin.read(&ch,1).eof()))
{
ch ^= keyToEncryption;
_decrptedResStr.append(ch);
}
}
ffin.close();
return _decrptedResStr;
}
QString Decrypt::decryptFile(QString sourceFile)
{
QString decryptedContent;
decryptedContent.clear();
string srcFile=sourceFile.toUtf8().constData();
ifstream ffin;
ffin.open(srcFile.c_str(),ios_base::in|ios_base::binary);
QChar keystring = 'A';
char keyToEncryption= keystring.toLatin1();
if(ffin.is_open())
{
char ch;
while(!(ffin.read(&ch,1).eof()))
{
ch ^= keyToEncryption;
decryptedContent.append(ch);
}
}
ffin.close();
return decryptedContent;
}
QString Decrypt::decryptFile(QString sourceFile,QChar keystring)
{
_decrptedResStr.clear();
string srcFile=sourceFile.toUtf8().constData();
ifstream ffin;
ffin.open(srcFile.c_str(),ios_base::in|ios_base::binary);
char keyToEncryption= keystring.toLatin1();
if(ffin.is_open())
{
char ch;
while(!(ffin.read(&ch,1).eof()))
{
ch ^= keyToEncryption;
_decrptedResStr.append(ch);
}
}
ffin.close();
return _decrptedResStr;
}
To copy to clipboard, switch view to plain text mode
I didn't realise what you were telling. Only upon pondering what's wrong got the issue. Now have modified to the first function above. Earlier it was of type 2nd function.
Thank you so much
Added after 16 minutes:
@anda_skoa : Thank you so much. You have pointed out exactly. It works now.
QFuture<QString> decryptedContent = QtConcurrent::mapped(fileList,DecryptMap('A'));
struct DecryptMap {
DecryptMap
(const QChar &key
) : m_key
(key
) {}
{
Decrypt *decrypt = new Decrypt();
return decrypt->decryptFile(item,'A');
}
};
QFuture<QString> decryptedContent = QtConcurrent::mapped(fileList,DecryptMap('A'));
struct DecryptMap {
DecryptMap(const QChar &key) : m_key(key) {}
typedef QString result_type;
QString operator()(const QString &item)
{
Decrypt *decrypt = new Decrypt();
return decrypt->decryptFile(item,'A');
}
QChar m_key;
};
To copy to clipboard, switch view to plain text mode
Bookmarks