QDataStream in(&file)in >> lbArray;...lbArray += file.readLine();...lbArray = file.readAll();...
#include <QCoreApplication>#include <QImage>#include <QFile>#include <QByteArray>#include <QBuffer>int main(int argc, char *argv[]){ QCoreApplication app(argc, argv); QImage image("test.png"); QByteArray ba; QBuffer buf(&ba); image.save(&buf, "BMP"); QByteArray compressed = qCompress(ba, 1); // better just open file with QFile, load data, compress and toHex? QByteArray hexed = compressed.toHex(); // save to a file QString str(hexed); QFile f("test.hex"); if (f.exists()) f.remove(); if (f.open(QFile::WriteOnly)) { f.write(str.toLatin1()); // holds only 0..f nothing special. } else qDebug("failed to open file \"test.hex\""); f.close(); ////---------- if (f.open(QFile::ReadOnly)) { QByteArray read = f.readAll(); f.close(); QString rStr = QString::fromLatin1(read.data(), read.size()); if (rStr != str) qDebug("Writed and read two different hexed strings."); QByteArray readCompressed = QByteArray::fromHex(rStr.toAscii()); if (readCompressed != compressed) qDebug("bytes before hexing and dehexing _is_ different."); QByteArray readDecompressed = qUncompress(readCompressed); if (readDecompressed != ba) qDebug("bytes before and after compressions are different."); QImage readImg; //QBuffer readBuf(&readDecompressed); readImg.loadFromData(readDecompressed); if (readImg.isNull()) qDebug("The image is null. Something failed."); readImg.save("test.bmp"); } else qDebug("failed to open test.hex file for reading"); return 0;}
#include <QFile>#include <QByteArray>#include <QBitArray>#include <QVariant>#include <IOStream>int main(int argc, char* argv[]){ QFile file("C:/testfile.txt"); if (!file.open(QIODevice::ReadOnly)) { std::cout << "Could not open file" << std::endl; return 1; } QByteArray input = file.readAll(); std::cout << input.size() << std::endl; QDataStream stream(input); QBitArray bita; bita.fill(0,700); for (int i = 0; i < 700; ++i) { std::cout << bita[i]; } stream >> bita; for (int i = 0; i < 700; ++i) { std::cout << bita[i]; } std::cout << std::endl << "Size: " << bita.size() << std::endl; file.close(); return 0;}
while ( !file.atEnd() ){ myArray.append( file.readLine() );}char *fileChar = myArray.data();int lnSize = sizeof( fileChar );
int main(int argc, char** argv){ QFile f(argv[1]); if (!f.open(QIODevice::ReadOnly)) qFatal("file open error"); QByteArray b = f.readAll(); if (b.isEmpty()) qFatal("%s",qPrintable(f.errorString())); return 0;}
main@RCEEE:/media/disk/proof_of_concept$ ./main a.bmpfile size:2677286array size:2677286