本文整理汇总了C++中QFile::pos方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::pos方法的具体用法?C++ QFile::pos怎么用?C++ QFile::pos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFile
的用法示例。
在下文中一共展示了QFile::pos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TellCallback
//static
long SoundSourceOggVorbis::TellCallback(void* datasource) {
QFile* pFile = static_cast<QFile*>(datasource);
if (!pFile) {
return 0;
}
return pFile->pos();
}
示例2: constructing_QFile
//----------------------------------------------------------------------------------
void tst_QIODevice::constructing_QFile()
{
QFile file;
QIODevice *device = &file;
QVERIFY(!device->isOpen());
file.setFileName(SRCDIR "tst_qiodevice.cpp");
QVERIFY(file.open(QFile::ReadOnly));
QVERIFY(device->isOpen());
QCOMPARE((int) device->openMode(), (int) QFile::ReadOnly);
char buf[1024];
memset(buf, 0, sizeof(buf));
qlonglong lineLength = device->readLine(buf, sizeof(buf));
QVERIFY(lineLength > 0);
QCOMPARE(file.pos(), lineLength);
file.seek(0);
char buf2[1024];
memset(buf2, 0, sizeof(buf2));
QCOMPARE(file.readLine(buf2, sizeof(buf2)), lineLength);
char *c1 = buf;
char *c2 = buf2;
while (*c1 && *c2) {
QCOMPARE(*c1, *c2);
++c1;
++c2;
}
QCOMPARE(*c1, *c2);
}
示例3: GetPosCallback
// static
uint32_t SoundSourceWV::GetPosCallback(void *id)
{
QFile* pFile = static_cast<QFile*>(id);
if (!pFile) {
return 0;
}
return pFile->pos();
}
示例4: readFileHeader
void Robotino::readFileHeader(QFile& file)
{
unsigned buflen = 20;
char buffer[buflen];
recordSize = 0;
file.seek(0);
file.readLine(buffer, buflen);
while(!file.atEnd() && strncmp(buffer,"end", strlen("end"))!=0)
{
if(strncmp(buffer,"action:", strlen("action:"))==0)
{
actionOffset = recordSize;
actionSize = atoi(buffer+strlen("action:"));
recordSize += actionSize;
}
else if(strncmp(buffer,"distance:", strlen("distance:"))==0)
{
distanceOffset = recordSize;
distanceSize = atoi(buffer+strlen("distance:"));
recordSize += distanceSize;
}
else if(strncmp(buffer,"accel:", strlen("accel:"))==0)
{
accelOffset = recordSize;
accelSize = atoi(buffer+strlen("accel:"));
recordSize += accelSize;
}
else if(strncmp(buffer,"current:", strlen("current:"))==0)
{
currentOffset = recordSize;
currentSize = atoi(buffer+strlen("current:"));
recordSize += currentSize;
}
else if(strncmp(buffer,"power:", strlen("power:"))==0)
{
powerOffset = recordSize;
powerSize = atoi(buffer+strlen("power:"));
recordSize += powerSize;
}
else if(strncmp(buffer,"bumper:", strlen("bumper:"))==0)
{
bumperOffset = recordSize;
bumperSize = atoi(buffer+strlen("bumper:"));
recordSize += bumperSize;
}
else if(strncmp(buffer,"audio:", strlen("audio:"))==0)
{
audioOffset = recordSize;
audioSize = atoi(buffer+strlen("audio:"));
recordSize += audioSize;
}
file.readLine(buffer, buflen);
}
headerSize = file.pos();
//std::cout << "Fertig" << std::endl;
}
示例5: find
bool ReaderDataBlockHeader::find(DataBlockHeader* outHeader, QFile& fin) {
unsigned char buffer[BUFFER_SIZE];
unsigned int nReadBytes;
while ((nReadBytes = fin.read(reinterpret_cast<char*>(buffer), BUFFER_SIZE)) >
HEADER_SIZE) {
unsigned char* findPos =
std::search(buffer, buffer + nReadBytes + 1, JAA::ARCHIVER_ID,
JAA::ARCHIVER_ID + JAA::ARCHIVER_ID_SIZE);
if (findPos == buffer + nReadBytes + 1) {
fin.seek(-(std::streamoff)(HEADER_SIZE - 1) + fin.pos());
} else {
// found at findPos
if ((BUFFER_SIZE - (findPos - buffer)) > HEADER_SIZE) {
// enough space in buffer
outHeader->setData(findPos);
if (!outHeader->checkCRC()) {
// valid CRC
fin.seek(-(std::streamoff)(nReadBytes - (findPos - buffer) - HEADER_SIZE) + fin.pos());
return false;
} else {
// not valid CRC may be not header?
fin.seek(-static_cast<std::streamoff>(nReadBytes - (findPos - buffer) - 2) + fin.pos());
// try again with offset
}
} else {
// not enough space
fin.seek(-(nReadBytes - (findPos - buffer) - 1) + fin.pos());
}
}
}
return true;
}
示例6: readNullTerminatedString
QString readNullTerminatedString(QFile &file, QTextCodec *codec, qint64 &length)
{
if(codec == NULL)
{
throw std::runtime_error("Codec is NULL");
}
qint64 pos = file.pos();
while (true)
{
quint8 nextSymbol = 0;
if (file.read(reinterpret_cast<char *> (&nextSymbol),
Q_INT64_C(1)) != Q_INT64_C(1))
{
throw std::runtime_error("Unable to read file");
}
if (nextSymbol == 0)
{
break;
}
}
qint64 stringLength = file.pos() - pos;
length = stringLength;
seekFile(file, pos);
QScopedArrayPointer<quint8> stringIn(new quint8[stringLength]);
if (file.read(reinterpret_cast<char *> (stringIn.data()),
stringLength) != stringLength)
{
throw std::runtime_error("Unable to read file");
}
QScopedPointer<QTextDecoder> decoder(codec->makeDecoder());
if (decoder.isNull())
{
throw std::runtime_error("Unable to create text decoder");
}
return decoder->toUnicode(
reinterpret_cast<const char *> (stringIn.data()),
static_cast<int> (stringLength - Q_INT64_C(1)));
}
示例7: ReadCallback
//static
size_t SoundSourceOggVorbis::ReadCallback(void *ptr, size_t size, size_t nmemb,
void *datasource) {
if (!size || !nmemb) {
return 0;
}
QFile* pFile = static_cast<QFile*>(datasource);
if (!pFile) {
return 0;
}
nmemb = math_min<size_t>((pFile->size() - pFile->pos()) / size, nmemb);
pFile->read((char*)ptr, nmemb * size);
return nmemb;
}
示例8: readTransPos
unsigned int FileTrans::readTransPos(QFile &file)
{
unsigned int postemp = file.pos(); //push file pos
file.seek(file.size()-4);
QDataStream str(&file);
str.setByteOrder(QDataStream::LittleEndian);
unsigned int pos ;
str>>pos;
file.seek(postemp); //pop file pos
if(pos<file.size())
return pos;
else
return 0;
}
示例9: writeHeader
void FileWriter::writeHeader(QDataStream & dataStream, QFile & file, AssetInformation & info)
{
if (info.properties().empty())
return;
dataStream << static_cast<quint16>(RawFile::s_signature);
quint64 rawDataOffsetPosition = file.pos();
dataStream << static_cast<quint64>(0);
QMapIterator<QVariantMap::key_type, QVariantMap::mapped_type> iterator(info.properties());
while (iterator.hasNext())
{
iterator.next();
QString key = iterator.key();
QVariant value = iterator.value();
RawFile::PropertyType type = propertyType(value.type());
if (type == RawFile::PropertyType::Unknown)
continue;
dataStream << static_cast<uint8_t>(type);
writeString(dataStream, key);
writeValue(dataStream, value);
}
quint64 rawDataOffset = file.pos();
file.seek(rawDataOffsetPosition);
dataStream << rawDataOffset;
file.seek(rawDataOffset);
}
示例10: saveTablesInfo
void Table_Control::saveTablesInfo(QFile &archivo, int sizeBlock, int HeadSize){
for(int i=0;i<this->metaData.count();i++){
archivo.write(reinterpret_cast<char*>(&this->metaData[i]),sizeof(MetaDataTable));
}
qDebug()<<"Cantidad campo to save:"<<this->campos.count();
QMap<int,Table_Fields>::ConstIterator it;
for(it=this->campos.constBegin();it!=this->campos.constEnd();it++){
Table_Fields tempField=it.value();
archivo.seek(HeadSize+this->metaData.at(it.key()).pointerToFields*sizeBlock);
qDebug()<<archivo.pos();
for(int i=0;i<tempField.campos.count();i++){
qDebug()<<tempField.campos[i].name<<i<<HeadSize+this->metaData.at(it.key()).pointerToFields*sizeBlock+(i*sizeof(Field))<<it.key()<<this->metaData.at(it.key()).pointerToFields*sizeBlock;
archivo.write(reinterpret_cast<char*>(&tempField.campos[i]),sizeof(Field));
}
}
this->campos.clear();
}
示例11: SeekCallback
//static
int SoundSourceOggVorbis::SeekCallback(void *datasource, ogg_int64_t offset,
int whence) {
QFile* pFile = static_cast<QFile*>(datasource);
if (!pFile) {
return 0;
}
switch(whence) {
case SEEK_SET:
return pFile->seek(offset) ? 0 : -1;
case SEEK_CUR:
return pFile->seek(pFile->pos() + offset) ? 0 : -1;
case SEEK_END:
return pFile->seek(pFile->size() + offset) ? 0 : -1;
default:
return -1;
}
}
示例12: qfileSeekCallback
int qfileSeekCallback( void * _udata, ogg_int64_t _offset, int _whence )
{
QFile * f = static_cast<QFile *>( _udata );
if( _whence == SEEK_CUR )
{
f->seek( f->pos() + _offset );
}
else if( _whence == SEEK_END )
{
f->seek( f->size() + _offset );
}
else
{
f->seek( _offset );
}
return 0;
}
示例13: SetPosRelCallback
//static
int SoundSourceWV::SetPosRelCallback(void *id, int delta, int mode)
{
QFile* pFile = static_cast<QFile*>(id);
if (!pFile) {
return 0;
}
switch(mode) {
case SEEK_SET:
return pFile->seek(delta) ? 0 : -1;
case SEEK_CUR:
return pFile->seek(pFile->pos() + delta) ? 0 : -1;
case SEEK_END:
return pFile->seek(pFile->size() + delta) ? 0 : -1;
default:
return -1;
}
}
示例14: loadRaw
qint64 StateImport::loadRaw(State* state, QFile& file)
{
auto size = file.size() - file.pos();
if (size % 8 !=0)
{
state->setErrorMessage(QObject::tr("Warning: file is not multiple of 8. Characters might be incomplete"));
qDebug() << "File size not multiple of 8 (" << size << "). Characters might be incomplete";
}
int toRead = std::min((int)size, State::CHAR_BUFFER_SIZE);
// clean previous memory in case not all the chars are loaded
state->resetCharsetBuffer();
auto total = file.read((char*)state->getCharsetBuffer(), toRead);
Q_ASSERT(total == toRead && "Failed to read file");
return total;
}
示例15: WriteWavHeadToFile
void DecodeAudioFile::WriteWavHeadToFile(QFile &f,int outLen, int sampleRate, int sampleSize, int channel)
{
WAVFMT wavHeader ;
wavHeader.RIFF[0] = 'R';
wavHeader.RIFF[1] = 'I';
wavHeader.RIFF[2] = 'F';
wavHeader.RIFF[3] = 'F';
wavHeader.totalSize = 44 + outLen;
wavHeader.WAVE[0] = 'W';
wavHeader.WAVE[1] = 'A';
wavHeader.WAVE[2] = 'V';
wavHeader.WAVE[3] = 'E';
wavHeader.FMT[0] = 'f';
wavHeader.FMT[1] = 'm';
wavHeader.FMT[2] = 't';
wavHeader.FMT[3] = ' ';
wavHeader.FILTER = 0x00000010;
wavHeader.formatTag = 1;
wavHeader.channels = channel;
wavHeader.sampleRate = sampleRate;
wavHeader.bytesPerSec = sampleRate*sampleSize*channel/8;
wavHeader.bytesInSample = sampleSize/8;
wavHeader.bitsDepth = sampleSize;
wavHeader.DATA[0] = 'd';
wavHeader.DATA[1] = 'a';
wavHeader.DATA[2] = 't';
wavHeader.DATA[3] = 'a';
wavHeader.dataSize = outLen;
int pos = f.pos();
f.seek(0);
f.write((char*)&wavHeader,sizeof(WAVFMT));
f.seek(pos);
f.flush();
}