Hi,
I have met a problem with reading text and jpeg files. Below the code and some comments are shown. All data was created by this application and now I try to made a load function.
All files are placed in this way:
loadDir
dir1
data/data.txt
info/info.txt
preview/preview.jpeg
dir2
...
...
loadDir
dir1
data/data.txt
info/info.txt
preview/preview.jpeg
dir2
...
...
To copy to clipboard, switch view to plain text mode
The quantity of dir1, dir2, ... , dirN directories can be any. Name of all directories exepting dir1, dir2, ... , dirN are known. I need to read all text files and jpeg. The structure of text files:
data.txt:
...
33 84
34 83
35 82
36 81
37 80
38 79
...
info.txt:
Hans
scan_of_cos
66.32.2124
data.txt:
...
33 84
34 83
35 82
36 81
37 80
38 79
...
info.txt:
Hans
scan_of_cos
66.32.2124
To copy to clipboard, switch view to plain text mode
data.txt can contain any quantity of lines and number of lines in info.txt data is predetermined.
I use following code for reading the data:
dir.cd(loadDir);
QStringList dirList
= dir.
entryList();
//make list of directories QStringListIterator dirListIterator(dirList);
while(dirListIterator.hasNext())
{
QFile dataFile
(loadDir
+ "\\" + dirListIterator.peekNext() + "\\" +
dataDir + "\\" + "data.txt");
{
while(!dataFile.atEnd())
{
inData >> onePoint.x >> onePoint.y;
point.push_back(onePoint);
endl(inData);
}
oneScan.dataVector = point;
}
dataFile.close();
QFile infoFile
(...
+ "info.txt");
{
inInfo >> oneScan.author;
inInfo >> oneScan.scanName;
inInfo >> oneScan.date;
}
infoFile.close();
QFile previewFile
(...
+ "preview.jpeg");
{
dirListIterator.peekNext() + "\\" +
infoDir + "\\" +
"preview.jpeg");
oneScan.previewImage = *pixmap;
}
dataContainer.push_back(oneScan);
point.clear();
dirListIterator.next();
}
QDir dir;
dir.cd(loadDir);
QStringList dirList = dir.entryList(); //make list of directories
QStringListIterator dirListIterator(dirList);
while(dirListIterator.hasNext())
{
QFile dataFile(loadDir + "\\" +
dirListIterator.peekNext() + "\\" +
dataDir + "\\" + "data.txt");
if (dataFile.open(QIODevice::ReadOnly))
{
QTextStream inData(&dataFile);
while(!dataFile.atEnd())
{
inData >> onePoint.x >> onePoint.y;
point.push_back(onePoint);
endl(inData);
}
oneScan.dataVector = point;
}
dataFile.close();
QFile infoFile(... + "info.txt");
if(infoFile.open(QIODevice::ReadOnly))
{
QTextStream inInfo(&infoFile);
inInfo >> oneScan.author;
inInfo >> oneScan.scanName;
inInfo >> oneScan.date;
}
infoFile.close();
QFile previewFile(... + "preview.jpeg");
if(previewFile.open(QIODevice::ReadOnly))
{
QPixmap *pixmap = new QPixmap(setName + "\\" +
dirListIterator.peekNext() + "\\" +
infoDir + "\\" +
"preview.jpeg");
oneScan.previewImage = *pixmap;
}
dataContainer.push_back(oneScan);
point.clear();
dirListIterator.next();
}
To copy to clipboard, switch view to plain text mode
But it does not work.
Where my mistake?
Thanks.
Bookmarks