• 16963阅读
  • 4回复

【提问】QT3.3.4下5GB以上的大文件读写???求救呀 [复制链接]

上一主题 下一主题
离线room502
 

只看楼主 倒序阅读 楼主  发表于: 2005-07-30
qt3.3.2
如何进行qfile类的使用?at的offset如何设置?
条件编译
#if defined(QT_ABI_QT4)
typedef Q_LLONG Offset;
#else
typedef Q_ULONG Offset;
#endif

如何使用呀?
[ 此贴被XChinux在2005-08-02 09:11重新编辑 ]
离线XChinux

只看该作者 1楼 发表于: 2005-07-30
用C语言怎么读就怎么读。
C语言的FILE结构进行读取文件没问题的吧。。。
同样,有C++里的fstream


老天,不是吧,读5GB大的文件?与文件系统的限制有关吧。
反正一次就把它读进去不好说的吧。
可以读点丢点读点丢点,
不好意思,对这方面没有专门研究过。。。。。。

那个条件编译,是定义Offset的类型的吧。
[ 此贴被XChinux在2005-08-01 09:02重新编辑 ]
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线XChinux

只看该作者 2楼 发表于: 2005-08-01
从QT Assistant里找到
Example (write binary data to a stream):

  QFile file("file.dat");
  file.open(QIODevice::WriteOnly);
  QDataStream out(&file);   // we will serialize the data into the file
  out << "the answer is";   // serialize a string
  out << (qint32)42;     // serialize an integer

Example (read binary data from a stream):

  QFile file("file.dat");
  file.open(QIODevice::ReadOnly);
  QDataStream in(&file);   // read the data serialized from the file
  QString str;
  qint32 a;
  in >> str >> a;       // extract "the answer is" and 42



QDataStream's binary format has evolved since Qt 1.0, and is likely to continue evolving to reflect changes done in Qt. When inputting or outputting complex types, it's very important to make sure that the same version of the stream (version()) is used for reading and writing. If you need both forward and backward compatibility, you can hardcode the version number in the application:

  stream.setVersion(QDataStream::Qt_4_0);

If you are producing a new binary data format, such as a file format for documents created by your application, you could use a QDataStream to write the data in a portable format. Typically, you would write a brief header containing a magic string and a version number to give yourself room for future expansion. For example:

  QFile file("file.xxx");
  file.open(QIODevice::WriteOnly);
  QDataStream out(&file);

  // Write a header with a "magic number" and a version
  out << (quint32)0xA0B0C0D0;
  out << (qint32)123;

  out.setVersion(QDataStream::Qt_4_0);

  // Write the data
  out << lots_of_interesting_data;

Then read it in with:

  QFile file("file.xxx");
  file.open(QIODevice::ReadOnly);
  QDataStream in(&file);

  // Read and check the header
  quint32 magic;
  in >> magic;
  if (magic != 0xA0B0C0D0)
    return XXX_BAD_FILE_FORMAT;

  // Read the version
  qint32 version;
  in >> version;
  if (version < 100)
    return XXX_BAD_FILE_TOO_OLD;
  if (version > 123)
    return XXX_BAD_FILE_TOO_NEW;

  if (version <= 110)
    in.setVersion(QDataStream::Qt_3_2);
  else
    in.setVersion(QDataStream::Qt_4_0);

  // Read the data
  in >> lots_of_interesting_data;
  if (version >= 120)
    in >> data_new_in_XXX_version_1_2;
  in >> other_interesting_data;

You can select which byte order to use when serializing data. The default setting is big endian (MSB first). Changing it to little endian breaks the portability (unless the reader also changes to little endian). We recommend keeping this setting unless you have special requirements.
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线XChinux

只看该作者 3楼 发表于: 2005-08-02
我在QTForum.org上面问的这个问题,人家回答说:
chickenblood:

Reconfigure Qt with:
configure -largefile -D QT_LARGEFILE_SUPPORT -D QT_ABI_QT4

Then recompile Qt.



也就是说:重新配置QT选项,然后再编译QT一下。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线room502

只看该作者 4楼 发表于: 2005-08-19
谢谢,版主,ok
快速回复
限100 字节
 
上一个 下一个