Results 1 to 3 of 3

Thread: Read binary from file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read binary from file

    I need read file which write by spatial hardware..

    I read again http://doc.trolltech.com/4.5/qdatastream.html#details
    I don't understand: can I use it to read this binary format?

    Can I use like http://www.qtcentre.org/forum/p-how-...ostcount9.html some structures and read binary file:

    Qt Code:
    1. QDataStream in(&file);
    2. in >> header >> channelA >>channalB>> channelA >>channalB>> channelA >>channalB;
    To copy to clipboard, switch view to plain text mode 
    Last edited by weldpua2008; 1st April 2009 at 16:09.

  2. #2
    Join Date
    Apr 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read binary from file

    I can read and I use this code:
    Qt Code:
    1. void MdiChild::openFile(QString curFile){
    2. isUntitled = true;
    3. setWindowTitle(curFile + "[*]");
    4. QFile file(curFile);
    5. QApplication::setOverrideCursor(Qt::WaitCursor); //курсор в режим ожидания
    6. if(!file.open(QIODevice::ReadOnly))
    7. {
    8. QMessageBox::warning(this, tr("Spreadsheet"),
    9. tr("Cannot open file %1:\n%2.")
    10. .arg(curFile)
    11. .arg(file.errorString()));
    12. }
    13. else
    14. {
    15. // QDataStream in(&file);
    16. // file_razmer = FileSeek(FH,filec,2);
    17. if (file.read(reinterpret_cast<char*>(&Q.fh), sizeof(Q.fh)) != sizeof(Q.fh))
    18. {
    19. QMessageBox::warning(this, tr("Spreadsheet"),
    20. tr("Cannot read header of file %1:\n%2.")
    21. .arg(curFile)
    22. .arg(file.errorString()));
    23. }
    24. Q.fh2dspp(66000,0,0);
    25. n_vib = (file.size() - (sizeof Q.fh))/(sizeof 4*2*Q.nDSPZ);
    26. QString astr="";
    27. for (i=0;i<16;i++){
    28. astr+= QString::number(i) + ": " + QString::number(Q.fh.syst[i]) + " ";
    29. }
    30. int Naver;
    31. /*if (OF->nAverCB->Checked && n_vib>Naver)
    32.   Naver = StrToInt(OF->nAverEdit->Text);
    33.   else Naver = n_vib;
    34.   */
    35. Naver = n_vib;
    36. QMessageBox::warning(this, tr("Propertis"),
    37. tr("File size %1\n %2:\n sizeof header %3\n sizeof spectr: %4 \n Count of spectra %5 \n Count of chanel DSPZ %6 \n Averaging factor DSPZ: %7 \n %8 \n %9 \n %10 \n Number of spectr for DSP file: %11\n ")
    38. .arg(file.size())
    39. .arg(curFile)
    40. .arg(QString::number(sizeof Q.fh) )
    41. .arg(QString::number(sizeof 4*2*Q.nDSPZ) )
    42. .arg(QString::number(sizeof n_vib) )
    43. .arg(QString::number(sizeof Q.nDSPZ) )
    44. .arg(QString::number(Q.dspp.NAvr) )
    45. .arg(Q.fh.time)
    46. .arg(astr)
    47. .arg(Q.fh.desc)
    48. .arg(QString::number(Naver) )
    49. );
    50. Naver=10;
    51. for(i=0;i<Naver;i++){
    52. file.read(reinterpret_cast<char*>(&Q.spectr), sizeof(4*2*Q.nDSPZ));
    53. //Q.get_spectrAB_prop();
    54. //SeriesShow();
    55. }
    56. }
    57. QApplication::restoreOverrideCursor(); //курсор в нормальный режим
    58. file.close();
    59. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. cannot execute binary file
    By mgturner in forum Installation and Deployment
    Replies: 1
    Last Post: 16th March 2009, 17:04
  2. QFile can't read a file
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2009, 20:24
  3. can`t read a binary data!
    By blm in forum Qt Programming
    Replies: 8
    Last Post: 18th September 2008, 16:56
  4. Read binary file and convert to QString
    By jaca in forum Qt Programming
    Replies: 12
    Last Post: 13th June 2008, 23:05
  5. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18:10

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
  •  
Qt is a trademark of The Qt Company.