Results 1 to 10 of 10

Thread: writing huge binary data

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Nov 2015
    Posts
    128
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    70

    Default Re: writing huge binary data

    @anda_skoa, thanks. I found an amazing thing happens here. for data[m][n] (double (*data)[n]; data = double[m][n]) when m>n it gives me right myfile.txt but when m<n it gives a file in size of zero!!! for example when m=599 and n=600 it gives me a file in size of zero and returns:"The program has unexpectedly finished." but when m=601 and n=600 it gives me a file in size of 2,344kB

    even when m is so larger than n, there is no false but if n is only one bigger that m, its not ok!!!

    for example:
    Qt Code:
    1. #include <QApplication>
    2. #include <QFile>
    3. #include <QDebug>
    4. #include <QDataStream>
    5.  
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10.  
    11. QFile myfile("d:/test.txt");
    12.  
    13. if(!myfile.open(QIODevice::WriteOnly))
    14. {
    15. qDebug() << "can not open to write";
    16. return 1;
    17. }
    18.  
    19. double (*data)[600];
    20. data = new double[599][600];//now is not ok but if i define data = new double[601][600] it gives me right file!!!
    21.  
    22. for(int i=0; i<599; i++)
    23. {
    24. for(int j=0; i<600; i++)
    25. {
    26. data[i][j] = (i+1)*(j+1);
    27. }
    28. myfile.write((char *)(&(data[i][600])), sizeof(double));
    29. }
    30.  
    31. //myfile.write((char *)(&(data[0][0])), 599*600*sizeof(double)); when m>n this is true also
    32.  
    33. myfile.flush();
    34. myfile.close();
    35.  
    36. return 0;
    37. }
    To copy to clipboard, switch view to plain text mode 

    You are right I need no QDataStrem and I can use QFile directly.

    thanks for anymore help
    Last edited by Alex22; 12th December 2015 at 15:33.

Similar Threads

  1. qt binary file writing and reading
    By seniorc in forum Newbie
    Replies: 9
    Last Post: 18th December 2013, 00:03
  2. How to handle huge data with QSqlQueryModel?
    By alizadeh91 in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2013, 16:31
  3. Writing my own object to a binary file.
    By 8Observer8 in forum Newbie
    Replies: 1
    Last Post: 1st December 2013, 09:15
  4. How to store huge data in a Qt software
    By Momergil in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2012, 23:43
  5. Reading/writing data to binary file
    By DiamonDogX in forum Qt Programming
    Replies: 3
    Last Post: 23rd July 2009, 20:24

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.