• 4602阅读
  • 2回复

谁能给个QT读取二进制文件的例子,谢谢 [复制链接]

上一主题 下一主题
离线wy2006
 
只看楼主 正序阅读 楼主  发表于: 2008-10-14
— 本帖被 XChinux 执行加亮操作(2008-10-15) —
谁能给个QT读取二进制文件的例子,用QDataStream,谢谢
离线wy2006
只看该作者 2楼 发表于: 2008-10-15
谢谢
离线lazybone
只看该作者 1楼 发表于: 2008-10-14
Qt Jambi
----------------------------
Example (write binary data to a stream):

        QFile file = new QFile("file.dat");
        QFile.OpenMode mode = new QFile.OpenMode();
        mode.set(QFile.OpenModeFlag.WriteOnly);
        file.open(mode);
        QDataStream out = new QDataStream(file);  // we will serialize the data into the file
        out.writeString("the answer is");  // serialize a string
        out.writeInt(42);        // serialize an integer

Example (read binary data from a stream):

        QFile file = new QFile("file.dat");
        QFile.OpenMode mode = new QFile.OpenMode();
        mode.set(QFile.OpenModeFlag.ReadOnly);
        file.open(mode);
        QDataStream in = new QDataStream(file);    // read the data serialized from the file
        // extract "the answer is" and 42
        String str = in.readString();
        int a = in.readInt();
快速回复
限100 字节
 
上一个 下一个