Results 1 to 2 of 2

Thread: problem with reading text files

  1. #1
    Join Date
    Apr 2008
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem with reading text files

    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:
    Qt Code:
    1. loadDir
    2. dir1
    3. data/data.txt
    4. info/info.txt
    5. preview/preview.jpeg
    6. dir2
    7. ...
    8. ...
    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:
    Qt Code:
    1. data.txt:
    2. ...
    3. 33 84
    4. 34 83
    5. 35 82
    6. 36 81
    7. 37 80
    8. 38 79
    9. ...
    10. info.txt:
    11. Hans
    12. scan_of_cos
    13. 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:
    Qt Code:
    1. QDir dir;
    2. dir.cd(loadDir);
    3. QStringList dirList = dir.entryList(); //make list of directories
    4. QStringListIterator dirListIterator(dirList);
    5. while(dirListIterator.hasNext())
    6. {
    7. QFile dataFile(loadDir + "\\" +
    8. dirListIterator.peekNext() + "\\" +
    9. dataDir + "\\" + "data.txt");
    10. if (dataFile.open(QIODevice::ReadOnly))
    11. {
    12. QTextStream inData(&dataFile);
    13. while(!dataFile.atEnd())
    14. {
    15. inData >> onePoint.x >> onePoint.y;
    16. point.push_back(onePoint);
    17. endl(inData);
    18. }
    19. oneScan.dataVector = point;
    20. }
    21. dataFile.close();
    22. QFile infoFile(... + "info.txt");
    23. if(infoFile.open(QIODevice::ReadOnly))
    24. {
    25. QTextStream inInfo(&infoFile);
    26. inInfo >> oneScan.author;
    27. inInfo >> oneScan.scanName;
    28. inInfo >> oneScan.date;
    29. }
    30. infoFile.close();
    31. QFile previewFile(... + "preview.jpeg");
    32. if(previewFile.open(QIODevice::ReadOnly))
    33. {
    34. QPixmap *pixmap = new QPixmap(setName + "\\" +
    35. dirListIterator.peekNext() + "\\" +
    36. infoDir + "\\" +
    37. "preview.jpeg");
    38. oneScan.previewImage = *pixmap;
    39. }
    40. dataContainer.push_back(oneScan);
    41. point.clear();
    42. dirListIterator.next();
    43. }
    To copy to clipboard, switch view to plain text mode 
    But it does not work.

    Where my mistake?

    Thanks.
    Last edited by Axsis; 25th April 2008 at 11:42.

  2. #2
    Join Date
    Apr 2008
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with reading text files

    I made some tests and it seems that QStringList dirList = dir.entryList(); return only one last directory. Why?

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 15:36
  3. compiling problem / Qt DLL files
    By ht1 in forum Newbie
    Replies: 1
    Last Post: 5th January 2008, 18:58
  4. Replies: 1
    Last Post: 30th November 2007, 11:03
  5. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 21:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.