[Solved] QTextStream does not return actual string for copy files with QFile
-
Hi here is the code.
@
QStringList fileList = fileName;
QStringList NameOfFiles = fileList.replaceInStrings(QRegExp("[^/[0-9a-zA-Z_.]$]"),"");
QString files;
QTextStream tmpName;
foreach(files, fileList) {
QList<QString>::const_iterator i;
for (i = NameOfFiles.constBegin(); i != NameOfFiles.constEnd();++i) {
tmpName << *i << endl;
}
QFile::copy(files, outputDir+tmpName.string());}
@
I get always the error overload for 'operator+'
Whats wrong.Thanks
-
Hi,
What is outputDir ?
And what would you like to achieve with your code ?
-
What type is fileName?
You create "QTextStream":http://qt-project.org/doc/qt-5.0/qtcore/qtextstream.html tmpName but never assign QString or QIODevice for it.
You iterate NameOfFiles for every iteration of fileList?
You stream every string in NameOfFiles to QTextStream tmpName which doesn't have anything to write to.
In QFile::copy you are calling QTextStream::string() which returns 0 as you haven't set string for QTextStream. You are adding that 0 to outputDir which is propably QString?What you are propably trying to do here is copy some input files to new destination without any special characters:
@
QStringList files; // add files
QString outputDir; // add outputdirforeach (const QString &fileName, files) { QFileInfo f(fileName); QString filePath = f.absoluteFilePath(); QString newFile = outputDir + f.fileName().replace(QRegExp("[^/[0-9a-zA-Z_.]$]"),""); QFile::copy(filePath, newFile); }
@
-
Ok sorry i had to point out some things, but yeap thanks to Tomma u get it and [SOLVED].