本文整理汇总了C++中QFile::read方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::read方法的具体用法?C++ QFile::read怎么用?C++ QFile::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFile
的用法示例。
在下文中一共展示了QFile::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
/**
* Load the object data from file.
* The file is expected to be already open for reading.
* The data will be read and the file will not be closed.
* @returns True on success, false on failure
*/
bool UAVObject::load(QFile & file)
{
QMutexLocker locker(mutex);
quint8 buffer[numBytes];
quint8 tmpId[4];
// Read the object ID
if (file.read((char *)tmpId, 4) != 4) {
return false;
}
// Check that the IDs match
if (qFromLittleEndian<quint32>(tmpId) != objID) {
return false;
}
// Read the instance ID
if (file.read((char *)tmpId, 2) != 2) {
return false;
}
// Check that the IDs match
if (qFromLittleEndian<quint16>(tmpId) != instID) {
return false;
}
// Read and unpack the data
if (file.read((char *)buffer, numBytes) != numBytes) {
return false;
}
unpack(buffer);
// Done
return true;
}
示例2: fromFile
bool ccObject::fromFile(QFile& in, short dataVersion)
{
assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));
if (dataVersion<20)
return CorruptError();
//DGM: if we are here, we assume the class ID has already been read!
//Call ccObject::readClassIDFromFile if necessary
////class ID (dataVersion>=20)
//uint32_t classID = 0;
//if (in.read((char*)&classID,4)<0)
// return ReadError();
//unique ID (dataVersion>=20)
//DGM: this ID will be usefull to recreate dynamic links between entities!
uint32_t uniqueID = 0;
if (in.read((char*)&uniqueID,4)<0)
return ReadError();
m_uniqueID = (unsigned)uniqueID;
//name (dataVersion>=20)
if (in.read(m_name,256)<0)
return ReadError();
//flags (dataVersion>=20)
uint32_t flags = 0;
if (in.read((char*)&flags,4)<0)
return ReadError();
m_flags = (unsigned)flags;
return true;
}
示例3: load
void QAniTransferFunctionInstance::load(QFile & file) {
file.read((char *)&m_resolution, 4);
file.read((char *)&m_tfResolutionChange, 4);
m_tfDrawArrayChange = new float[m_resolution];
file.read((char *)m_tfDrawArrayChange, 4 * m_resolution);
int size;
file.read((char *)&size, 4);
for (int i = 0; i < size; ++i) {
double mean,sigma,height;
file.read((char *)&mean, 8);
file.read((char *)&sigma, 8);
file.read((char *)&height, 8);
GaussianObjectChange goc(mean, sigma, height);
m_gaussianObjectChange.push_back(goc);
}
file.read((char *)&size, 4);
for (int i = 0; i < size; ++i) {
float x;
Vector4 color;
file.read((char *)&x, 4);
file.read((char *)((double*)color), 32);
ColorTickChange ctc(x, color);
m_tfColorTickChange.push_back(ctc);
}
}
示例4: fromFile_MeOnly
bool ccGenericPointCloud::fromFile_MeOnly(QFile& in, short dataVersion)
{
if (!ccHObject::fromFile_MeOnly(in, dataVersion))
return false;
if (dataVersion<20)
return CorruptError();
//'coordinates shift' (dataVersion>=20)
if (in.read((char*)m_originalShift,sizeof(double)*3)<0)
return ReadError();
//'visibility' array (dataVersion>=20)
bool hasVisibilityArray = false;
if (in.read((char*)&hasVisibilityArray,sizeof(bool))<0)
return ReadError();
if (hasVisibilityArray)
{
if (!m_visibilityArray)
{
m_visibilityArray = new VisibilityTableType();
m_visibilityArray->link();
}
if (!ccSerializationHelper::GenericArrayFromFile(*m_visibilityArray,in,dataVersion))
{
unallocateVisibilityArray();
return false;
}
}
return true;
}
示例5: fromFile_MeOnly
bool ccGenericMesh::fromFile_MeOnly(QFile& in, short dataVersion, int flags)
{
if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags))
return false;
//'show wired' state (dataVersion>=20)
if (in.read((char*)&m_showWired,sizeof(bool))<0)
return ReadError();
//'per-triangle normals shown' state (dataVersion>=29))
if (dataVersion >= 29)
{
if (in.read((char*)&m_triNormsShown,sizeof(bool))<0)
return ReadError();
//'materials shown' state (dataVersion>=29))
if (in.read((char*)&m_materialsShown,sizeof(bool))<0)
return ReadError();
//'polygon stippling' state (dataVersion>=29))
if (in.read((char*)&m_stippling,sizeof(bool))<0)
return ReadError();
}
return true;
}
示例6: fromFile
bool ccObject::fromFile(QFile& in, short dataVersion, int flags)
{
assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));
if (dataVersion<20)
return CorruptError();
//DGM: if we are here, we assume the class ID has already been read!
//Call ccObject::readClassIDFromFile if necessary
////class ID (dataVersion>=20)
//uint32_t classID = 0;
//if (in.read((char*)&classID,4) < 0)
// return ReadError();
//unique ID (dataVersion>=20)
//DGM: this ID will be usefull to recreate dynamic links between entities!
uint32_t uniqueID = 0;
if (in.read((char*)&uniqueID,4) < 0)
return ReadError();
m_uniqueID = (unsigned)uniqueID;
//name
if (dataVersion < 22) //old style
{
char name[256];
if (in.read(name,256) < 0)
return ReadError();
setName(name);
}
else //(dataVersion>=22)
{
QDataStream inStream(&in);
inStream >> m_name;
}
//flags (dataVersion>=20)
uint32_t objFlags = 0;
if (in.read((char*)&objFlags,4) < 0)
return ReadError();
m_flags = (unsigned)objFlags;
//meta data (dataVersion>=30)
if (dataVersion >= 30)
{
//count
uint32_t metaDataCount = 0;
if (in.read((char*)&metaDataCount,4) < 0)
return ReadError();
//"key + value" pairs
for (uint32_t i=0; i<metaDataCount; ++i)
{
QDataStream inStream(&in);
QString key;
QVariant value;
inStream >> key;
inStream >> value;
setMetaData(key,value);
}
}
示例7: fromFile
bool ccHObject::fromFile(QFile& in, short dataVersion)
{
assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));
//read 'ccObject' header
if (!ccObject::fromFile(in,dataVersion))
return false;
//read own data
if (!fromFile_MeOnly(in,dataVersion))
return false;
//(serializable) child count (dataVersion>=20)
uint32_t serializableCount = 0;
if (in.read((char*)&serializableCount,4)<0)
return ReadError();
//read serializable children (if any)
for (uint32_t i=0; i<serializableCount; ++i)
{
//read children class ID
unsigned classID=0;
if (!ReadClassIDFromFile(classID, in, dataVersion))
return false;
//create corresponding child object
ccHObject* child = New(classID);
assert(child && child->isSerializable());
if (child)
{
if (child->fromFile(in,dataVersion))
{
addChild(child,child->getFlagState(CC_FATHER_DEPENDANT));
}
else
{
delete child;
return false;
}
}
else
{
return CorruptError();
}
}
//write current selection behavior (dataVersion>=23)
if (dataVersion>=23)
{
if (in.read((char*)&m_selectionBehavior,sizeof(SelectionBehavior))<0)
return ReadError();
}
else
{
m_selectionBehavior = SELECTION_AA_BBOX;
}
return true;
}
示例8: fromFile_MeOnly
bool ccPolyline::fromFile_MeOnly(QFile& in, short dataVersion, int flags)
{
if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags))
return false;
if (dataVersion<28)
return false;
//as the associated cloud (=vertices) can't be saved directly (as it may be shared by multiple polylines)
//we only store its unique ID (dataVersion>=28) --> we hope we will find it at loading time (i.e. this
//is the responsibility of the caller to make sure that all dependencies are saved together)
uint32_t vertUniqueID = 0;
if (in.read((char*)&vertUniqueID,4) < 0)
return ReadError();
//[DIRTY] WARNING: temporarily, we set the vertices unique ID in the 'm_associatedCloud' pointer!!!
*(uint32_t*)(&m_theAssociatedCloud) = vertUniqueID;
//number of points (references to) (dataVersion>=28)
uint32_t pointCount = 0;
if (in.read((char*)&pointCount,4) < 0)
return ReadError();
if (!reserve(pointCount))
return false;
//points (references to) (dataVersion>=28)
for (uint32_t i=0; i<pointCount; ++i)
{
uint32_t pointIndex = 0;
if (in.read((char*)&pointIndex,4) < 0)
return ReadError();
addPointIndex(pointIndex);
}
QDataStream inStream(&in);
//Closing state (dataVersion>=28)
inStream >> m_isClosed;
//RGB Color (dataVersion>=28)
inStream >> m_rgbColor[0];
inStream >> m_rgbColor[1];
inStream >> m_rgbColor[2];
//2D mode (dataVersion>=28)
inStream >> m_mode2D;
//Foreground mode (dataVersion>=28)
inStream >> m_foreground;
//Width of the line (dataVersion>=31)
if (dataVersion >= 31)
ccSerializationHelper::CoordsFromDataStream(inStream,flags,&m_width,1);
else
m_width = 0;
return true;
}
示例9: fromFile_MeOnly
bool ccGenericPointCloud::fromFile_MeOnly(QFile& in, short dataVersion, int flags)
{
if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags))
return false;
if (dataVersion < 20)
return CorruptError();
if (dataVersion < 33)
{
//'coordinates shift' (dataVersion>=20)
if (in.read((char*)m_globalShift.u,sizeof(double)*3) < 0)
return ReadError();
m_globalScale = 1.0;
}
else
{
//'global shift & scale' (dataVersion>=33)
if (!loadShiftInfoFromFile(in))
return ReadError();
}
//'visibility' array (dataVersion>=20)
bool hasVisibilityArray = false;
if (in.read((char*)&hasVisibilityArray,sizeof(bool)) < 0)
return ReadError();
if (hasVisibilityArray)
{
if (!m_pointsVisibility)
{
m_pointsVisibility = new VisibilityTableType();
m_pointsVisibility->link();
}
if (!ccSerializationHelper::GenericArrayFromFile(*m_pointsVisibility,in,dataVersion))
{
unallocateVisibilityArray();
return false;
}
}
//'point size' (dataVersion>=24)
if (dataVersion >= 24)
{
if (in.read((char*)&m_pointSize,1) < 0)
return WriteError();
}
else
{
m_pointSize = 0; //= follows default setting
}
return true;
}
示例10: loadShiftInfoFromFile
bool ccShiftedObject::loadShiftInfoFromFile(QFile& in)
{
//'coordinates shift'
if (in.read((char*)m_globalShift.u,sizeof(double)*3) < 0)
return ccSerializableObject::ReadError();
//'global scale'
if (in.read((char*)&m_globalScale,sizeof(double)) < 0)
return ccSerializableObject::ReadError();
return true;
}
示例11: fromFile
bool ccColorScale::fromFile(QFile& in, short dataVersion, int flags)
{
if (dataVersion < 27) //structure appeared at version 27!
return false;
QDataStream inStream(&in);
//name (dataVersion>=27)
inStream >> m_name;
//UUID (dataVersion>=27)
inStream >> m_uuid;
//relative state (dataVersion>=27)
if (in.read((char*)&m_relative,sizeof(bool)) < 0)
return ReadError();
//Absolute min value (dataVersion>=27)
if (in.read((char*)&m_absoluteMinValue,sizeof(double)) < 0)
return ReadError();
//Absolute range (dataVersion>=27)
if (in.read((char*)&m_absoluteRange,sizeof(double)) < 0)
return ReadError();
//locked state (dataVersion>=27)
if (in.read((char*)&m_locked,sizeof(bool)) < 0)
return ReadError();
//steps list (dataVersion>=27)
{
//steps count
uint32_t stepCount = 0;
if (in.read((char*)&stepCount,4) < 0)
return ReadError();
//read each step
m_steps.clear();
for (uint32_t i=0; i<stepCount; ++i)
{
double relativePos = 0.0;
QColor color(Qt::white);
inStream >> relativePos;
inStream >> color;
m_steps.push_back(ccColorScaleElement(relativePos,color));
}
update();
}
return true;
}
示例12: readMatrix
bool Matrix::readMatrix(QFile &file)
{
releaseData();
file.read((char *)&nRow,sizeof(int));
file.read((char *)&nCol,sizeof(int));
if(nRow*nCol>0)
{
allocate(nRow,nCol);
if(file.read((char *)pData,sizeof(double)*nRow*nCol)!=sizeof(double)*nRow*nCol)
return false;
}
return true;
}
示例13: skipUselessChucks
void skipUselessChucks( WavFileHeader& header, QFile& file )
{
// We only care about the 'data' chuck
while ( memcmp( header.dataChuckID, "data", 4 ) != 0 )
{
int skipByteCount = header.dataSize;
std::vector<char> skipData( skipByteCount );
file.read( skipData.data(), skipByteCount );
file.read( (char*)&header.dataChuckID, 4 );
file.read( (char*)&header.dataSize, 4 );
}
}
示例14: readVector
bool Vector::readVector(QFile &file)
{
releaseData();
file.read((char *)&nDim,sizeof(int));
if(nDim<0)
return false;
if(nDim>0)
{
allocate(nDim);
if(file.read((char *)pData,sizeof(double)*nDim)!=sizeof(double)*nDim)
return false;
}
return true;
}
示例15: read_MAT_MAPNAME_chunk
QString read_MAT_MAPNAME_chunk( QFile &src )
{
TA3D_3DS_CHUNK_DATA chunk;
src.read( (char*)&chunk.ID, 2 );
src.read( (char*)&chunk.length, 4 );
switch( chunk.ID )
{
case MAT_MAPNAME:
return read_ASCIIZ( src );
default:
src.read( chunk.length - 6 );
};
return NULL;
}