本文整理汇总了C++中QBuffer::seek方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::seek方法的具体用法?C++ QBuffer::seek怎么用?C++ QBuffer::seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadXMLInput
void VCProperties_Test::loadXMLInput()
{
QBuffer buffer;
buffer.open(QIODevice::ReadWrite | QIODevice::Text);
QXmlStreamWriter xmlWriter(&buffer);
xmlWriter.writeStartElement("Input");
xmlWriter.writeAttribute("Universe", "3");
xmlWriter.writeAttribute("Channel", "78");
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
xmlWriter.setDevice(NULL);
buffer.seek(0);
QXmlStreamReader xmlReader(&buffer);
xmlReader.readNextStartElement();
quint32 universe = 0;
quint32 channel = 0;
QVERIFY(VCProperties::loadXMLInput(xmlReader, &universe, &channel) == true);
QCOMPARE(universe, quint32(3));
QCOMPARE(channel, quint32(78));
buffer.close();
QByteArray bData = buffer.data();
bData.replace("<Input", "<Inputt");
buffer.setData(bData);
buffer.open(QIODevice::ReadOnly | QIODevice::Text);
buffer.seek(0);
xmlReader.setDevice(&buffer);
xmlReader.readNextStartElement();
universe = channel = 0;
QVERIFY(VCProperties::loadXMLInput(xmlReader, &universe, &channel) == false);
QCOMPARE(universe, quint32(0));
QCOMPARE(channel, quint32(0));
QBuffer buffer2;
buffer2.open(QIODevice::ReadWrite | QIODevice::Text);
xmlWriter.setDevice(&buffer2);
xmlWriter.writeStartElement("Input");
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
xmlWriter.setDevice(NULL);
buffer2.seek(0);
xmlReader.setDevice(&buffer2);
xmlReader.readNextStartElement();
universe = channel = 0;
QVERIFY(VCProperties::loadXMLInput(xmlReader, &universe, &channel) == false);
QCOMPARE(universe, InputOutputMap::invalidUniverse());
QCOMPARE(channel, QLCChannel::invalid());
}
示例2: load
bool QSvgIOHandlerPrivate::load(QIODevice *device)
{
if (loaded)
return true;
if (q->format().isEmpty())
q->canRead();
// # The SVG renderer doesn't handle trailing, unrelated data, so we must
// assume that all available data in the device is to be read.
bool res = false;
QBuffer *buf = qobject_cast<QBuffer *>(device);
if (buf) {
const QByteArray &ba = buf->data();
res = r.load(QByteArray::fromRawData(ba.constData() + buf->pos(), ba.size() - buf->pos()));
buf->seek(ba.size());
} else if (q->format() == "svgz") {
res = r.load(device->readAll());
} else {
xmlReader.setDevice(device);
res = r.load(&xmlReader);
}
if (res) {
defaultSize = QSize(r.viewBox().width(), r.viewBox().height());
loaded = true;
}
return loaded;
}
示例3: loadXMLSad
void VCProperties_Test::loadXMLSad()
{
QBuffer buffer;
buffer.open(QIODevice::ReadWrite | QIODevice::Text);
QXmlStreamWriter xmlWriter(&buffer);
xmlWriter.writeStartElement("VirtualConsole");
xmlWriter.writeStartElement("Properties");
xmlWriter.writeEndElement();
xmlWriter.writeStartElement("Frame");
xmlWriter.writeEndElement();
xmlWriter.writeStartElement("Foo");
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
xmlWriter.setDevice(NULL);
buffer.seek(0);
QXmlStreamReader xmlReader(&buffer);
xmlReader.readNextStartElement();
VCProperties p;
QVERIFY(p.loadXML(xmlReader) == false);
}
示例4: parse
QVariant QJson::parse(const QByteArray& jsonString, bool* ok) {
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
buffer.write(jsonString);
buffer.seek(0);
return parse (&buffer, ok);
}
示例5: scanTokens
void TestScanner::scanTokens() {
QFETCH(QByteArray, input);
QFETCH(bool, allowSpecialNumbers);
QFETCH(bool, skipFirstToken);
QFETCH(int, expectedResult);
QFETCH(QVariant, expectedYylval);
QFETCH(int, expectedLocationBeginLine);
QFETCH(int, expectedLocationBeginColumn);
QFETCH(int, expectedLocationEndLine);
QFETCH(int, expectedLocationEndColumn);
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
buffer.write(input);
buffer.seek(0);
JSonScanner scanner(&buffer);
scanner.allowSpecialNumbers(allowSpecialNumbers);
QVariant yylval;
yy::position position(YY_NULL, 1, 0);
yy::location location(position, position);
int result = scanner.yylex(&yylval, &location);
if (skipFirstToken) {
result = scanner.yylex(&yylval, &location);
}
QCOMPARE(result, expectedResult);
QCOMPARE(yylval, expectedYylval);
QCOMPARE(location.begin.line, (uint)expectedLocationBeginLine);
QCOMPARE(location.begin.column, (uint)expectedLocationBeginColumn);
QCOMPARE(location.end.line, (uint)expectedLocationEndLine);
QCOMPARE(location.end.column, (uint)expectedLocationEndColumn);
}
示例6: QVERIFY
void TestKeePass1Reader::reopenDatabase(Database* db, const QString& password, const QString& keyfileName)
{
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
KeePass2Writer writer;
writer.writeDatabase(&buffer, db);
QVERIFY(!writer.hasError());
QVERIFY(buffer.seek(0));
CompositeKey key;
if (!password.isNull()) {
key.addKey(PasswordKey(password));
}
if (!keyfileName.isEmpty()) {
FileKey fileKey;
QVERIFY(fileKey.load(keyfileName));
key.addKey(fileKey);
}
KeePass2Reader reader;
Database* newDb = reader.readDatabase(&buffer, key);
QVERIFY(newDb);
QVERIFY(!reader.hasError());
delete newDb;
}
示例7: saveAndLoadMap
Map* FileFormatTest::saveAndLoadMap(Map* input, const FileFormat* format)
{
try {
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
Exporter* exporter = format->createExporter(&buffer, input, NULL);
if (!exporter)
return NULL;
exporter->doExport();
delete exporter;
buffer.seek(0);
Map* out = new Map;
Importer* importer = format->createImporter(&buffer, out, NULL);
if (!importer)
return NULL;
importer->doImport(false);
importer->finishImport();
delete importer;
buffer.close();
return out;
}
catch (std::exception& e)
{
return NULL;
}
}
示例8:
void sendDataToDev2(const QByteArray& data) {
qint64 pos = mDevice2.pos();
mDevice2.write(data);
mDevice2.seek(pos);
// Return to qt event loop to allow it process asincronious signals
QTest::qWait(1);
}
示例9: flacStreamEncoderMetadataCallback
void flacStreamEncoderMetadataCallback( const FLAC__StreamEncoder *,
const FLAC__StreamMetadata * _metadata,
void * _client_data )
{
QBuffer * b = static_cast<QBuffer *>( _client_data );
b->seek( 0 );
b->write( (const char *) _metadata, sizeof( *_metadata ) );
}
示例10: registerRecord
/*!
Registers the SDP service record \a record for this Bluetooth service
and returns the service record handle of the newly registered service.
Returns zero if the registration failed.
\sa unregisterRecord()
*/
quint32 QBluetoothAbstractService::registerRecord(const QBluetoothSdpRecord &record)
{
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
QSdpXmlGenerator::generate(record, &buffer);
buffer.seek(0);
return m_data->registerRecord(QString::fromUtf8(buffer.readAll()));
}
示例11: writeData
qint64 Request::writeData(const char* data, qint64 maxSize)
{
if(m_responseState == WaitingForResponseHeaders)
{
m_headerBuffer.append(data, maxSize);
// We need to buffer the headers, so we can use the STATUS header appropriately
QBuffer buffer;
buffer.setData(m_headerBuffer);
buffer.open(QIODevice::ReadOnly);
buffer.seek(m_headerBufferPosition);
while(buffer.canReadLine())
{
const QByteArray line = buffer.readLine().trimmed();
if(line.isEmpty())
{
Q_ASSERT(m_responseHeaders.contains("STATUS"));
Q_ASSERT(m_requestHeaders.contains("SERVER_PROTOCOL"));
m_responseState = WaitingForResponseBody;
const QByteArray status = m_responseHeaders.take("STATUS");
m_socket->write(m_requestHeaders.value("SERVER_PROTOCOL"));
m_socket->write(" ", 1);
m_socket->write(status);
m_socket->write("\r\n", 2);
//qDebug() << Q_FUNC_INFO << m_requestHeaders << m_responseHeaders;
for(
HeaderMap::ConstIterator it = m_responseHeaders.constBegin();
it != m_responseHeaders.constEnd();
++it
)
{
m_socket->write(it.key());
m_socket->write(": ");
m_socket->write(it.value());
m_socket->write("\r\n");
}
m_socket->write("\r\n");
m_socket->write(buffer.readAll());
buffer.close();
m_headerBuffer.clear();
return maxSize;
}
const int lengthOfName = line.indexOf(':');
const QByteArray name = line.left(lengthOfName);
const QByteArray value = line.mid(lengthOfName + 2); // ": " after the name == 2 chars
m_responseHeaders.insertMulti(name, value);
}
m_headerBufferPosition = buffer.pos();
buffer.close();
return maxSize;
}
Q_ASSERT(m_responseState == WaitingForResponseBody);
return m_socket->write(data, maxSize);
}
示例12: play
void TSoundOutputDeviceImp::play(const TSoundTrackP &st, TINT32 s0, TINT32 s1,
bool loop, bool scrubbing) {
if (!doSetStreamFormat(st->getFormat())) return;
MyData *myData = new MyData();
myData->imp = shared_from_this();
myData->totalPacketCount = s1 - s0;
myData->fileByteCount = (s1 - s0) * st->getSampleSize();
myData->entireFileBuffer = new char[myData->fileByteCount];
memcpy(myData->entireFileBuffer, st->getRawData() + s0 * st->getSampleSize(),
myData->fileByteCount);
m_isPlaying = true;
myData->isLooping = loop;
QAudioFormat format;
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
format.setSampleSize(st->getBitPerSample());
format.setCodec("audio/pcm");
format.setChannelCount(st->getChannelCount());
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(st->getFormat().m_signedSample
? QAudioFormat::SignedInt
: QAudioFormat::UnSignedInt);
format.setSampleRate(st->getSampleRate());
QList<QAudioFormat::Endian> sbos = info.supportedByteOrders();
QList<int> sccs = info.supportedChannelCounts();
QList<int> ssrs = info.supportedSampleRates();
QList<QAudioFormat::SampleType> sstypes = info.supportedSampleTypes();
QList<int> ssss = info.supportedSampleSizes();
QStringList supCodes = info.supportedCodecs();
if (!info.isFormatSupported((format))) {
format = info.nearestFormat(format);
int newChannels = format.channelCount();
int newBitsPerSample = format.sampleSize();
int newSampleRate = format.sampleRate();
QAudioFormat::SampleType newSampleType = format.sampleType();
QAudioFormat::Endian newBo = format.byteOrder();
}
int test = st->getSampleCount() / st->getSampleRate();
QByteArray *data =
new QByteArray(myData->entireFileBuffer, myData->fileByteCount);
QBuffer *newBuffer = new QBuffer;
newBuffer->setBuffer(data);
newBuffer->open(QIODevice::ReadOnly);
newBuffer->seek(0);
if (m_audioOutput == NULL) {
m_audioOutput = new QAudioOutput(format, NULL);
}
m_audioOutput->start(newBuffer);
m_audioOutput->setVolume(m_volume);
}
示例13: scanSpecialNumbers
void TestScanner::scanSpecialNumbers() {
QFETCH(QByteArray, input);
QFETCH(bool, isInfinity);
QFETCH(bool, isNegative);
QFETCH(bool, isNan);
QFETCH(int, expectedLocationBeginLine);
QFETCH(int, expectedLocationBeginColumn);
QFETCH(int, expectedLocationEndLine);
QFETCH(int, expectedLocationEndColumn);
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
buffer.write(input);
buffer.seek(0);
JSonScanner scanner(&buffer);
scanner.allowSpecialNumbers(true);
QVariant yylval;
yy::position position(YY_NULL, 1, 0);
yy::location location(position, position);
int result = scanner.yylex(&yylval, &location);
QCOMPARE(result, TOKEN(NUMBER));
QVERIFY(yylval.type() == QVariant::Double);
double doubleResult = yylval.toDouble();
#if defined(Q_OS_SYMBIAN) || defined(Q_OS_ANDROID) || defined(Q_OS_BLACKBERRY)
QCOMPARE(bool(isinf(doubleResult)), isInfinity);
#else
// skip this test for MSVC, because there is no "isinf" function.
#ifndef Q_CC_MSVC
QCOMPARE(bool(std::isinf(doubleResult)), isInfinity);
#endif
#endif
QCOMPARE(doubleResult<0, isNegative);
#if defined(Q_OS_SYMBIAN) || defined(Q_OS_ANDROID) || defined(Q_OS_BLACKBERRY)
QCOMPARE(bool(isnan(doubleResult)), isNan);
#else
// skip this test for MSVC, because there is no "isinf" function.
#ifndef Q_CC_MSVC
QCOMPARE(bool(std::isnan(doubleResult)), isNan);
#endif
#endif
QCOMPARE(location.begin.line, (uint)expectedLocationBeginLine);
QCOMPARE(location.begin.column, (uint)expectedLocationBeginColumn);
QCOMPARE(location.end.line, (uint)expectedLocationEndLine);
QCOMPARE(location.end.column, (uint)expectedLocationEndColumn);
}
示例14: completeExample
void completeExample()
{
// Create the input vCard
//! [Complete example - create]
QBuffer input;
input.open(QBuffer::ReadWrite);
QByteArray inputVCard =
"BEGIN:VCARD\r\nVERSION:2.1\r\nFN:John Citizen\r\nN:Citizen;John;Q;;\r\nEND:VCARD\r\n";
input.write(inputVCard);
input.seek(0);
//! [Complete example - create]
// Parse the input into QVersitDocuments
//! [Complete example - read]
// Note: we could also use the more convenient QVersitReader(QByteArray) constructor.
QVersitReader reader;
reader.setDevice(&input);
reader.startReading(); // Remember to check the return value
reader.waitForFinished();
QList<QVersitDocument> inputDocuments = reader.results();
//! [Complete example - read]
// Convert the QVersitDocuments to QContacts
//! [Complete example - import]
QVersitContactImporter importer;
if (!importer.importDocuments(inputDocuments))
return;
QList<QContact> contacts = importer.contacts();
// Note that the QContacts are not saved yet.
// Use QContactManager::saveContacts() for saving if necessary
//! [Complete example - import]
// Export the QContacts back to QVersitDocuments
//! [Complete example - export]
QVersitContactExporter exporter;
if (!exporter.exportContacts(contacts, QVersitDocument::VCard30Type))
return;
QList<QVersitDocument> outputDocuments = exporter.documents();
//! [Complete example - export]
// Encode the QVersitDocument back to a vCard
//! [Complete example - write]
// Note: we could also use the more convenient QVersitWriter(QByteArray*) constructor.
QBuffer output;
output.open(QBuffer::ReadWrite);
QVersitWriter writer;
writer.setDevice(&output);
writer.startWriting(outputDocuments); // Remember to check the return value
writer.waitForFinished();
// output.buffer() now contains a vCard
//! [Complete example - write]
}
示例15: setBuffer_snippet
static void setBuffer_snippet()
{
//! [4]
QByteArray byteArray("abc");
QBuffer buffer;
buffer.setBuffer(&byteArray);
buffer.open(QIODevice::WriteOnly);
buffer.seek(3);
buffer.write("def", 3);
buffer.close();
// byteArray == "abcdef"
//! [4]
}