Qt-interest Archive, May 2008
QFileInfo returns false for isReadable() on second invocation
Message 1 in thread
Hi,
I am using the following piece of code:
foreach (QString fileName, m_inputFiles) {
qDebug() << "Parsing" << fileName;
QFileInfo info(fileName);
if (!info.isReadable()) {
emit error("File not readable: " + fileName, false);
qDebug() << "File not readable: " << fileName;
} else {
parseFile(fileName);
}
}
m_inputFiles is a QStringList with file names, one per line. The result is
that parseFile() is only called for the first item in the list, while for
the rest I get the "File not readable" on the debug output. No matter in
what order the files are: only the first is reported as readable by
QFileInfo. Can anyone point me to where I am going wrong with this? As far
as I understand it, the QFileInfo instances should not interfere with each
other between loops of the foreach; it should be within the scope of one run
of the loop. Am I overlooking something?
Thanks,
André
--
[ signature omitted ]
Message 2 in thread
Hi,
It seems to work for me with the current Qt 4.4 branch on Linux:
$ cat foo.cpp
#include <QFileInfo>
#include <QStringList>
#include <QtDebug>
int main() {
QStringList m_inputFiles;
m_inputFiles << "foo.cpp";
m_inputFiles << "foo.o";
m_inputFiles << "foo";
foreach (QString fileName, m_inputFiles) {
qDebug() << "Parsing " << fileName;
QFileInfo info(fileName);
if (!info.isReadable()) {
qDebug() << "File not readable: " << fileName;
} else {
qDebug() << "File readable: " << fileName;
}
}
}
$
$ qmake
$ make
[...]
$ ./foo
Parsing "foo.cpp"
File readable: "foo.cpp"
Parsing "foo.o"
File readable: "foo.o"
Parsing "foo"
File readable: "foo"
$
--
[ signature omitted ]
Message 3 in thread
Hi,
> of the loop. Am I overlooking something?
I'd take a look if the m_inputFiles happen to have
some control characters like line feeds that don't
print but will break the file name.
--
[ signature omitted ]
Message 4 in thread
Hi,
"Taipale, Eero" <Eero.Taipale@xxxxxxxxxxxx> schreef in bericht
news:8589D0AD450A0D4CB6CC66ED3AF4FF6C051B36A8@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
>> of the loop. Am I overlooking something?
>
> I'd take a look if the m_inputFiles happen to have
> some control characters like line feeds that don't
> print but will break the file name.
Yes, thank you. I have found the cause, and indeed the problem was that from
the second line onwards I got some unwanted control characters ending up in
the string. Sorry, I should have spotted this myself.
André
--
[ signature omitted ]