本文整理汇总了C++中QBuffer::pos方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::pos方法的具体用法?C++ QBuffer::pos怎么用?C++ QBuffer::pos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::pos方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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);
}
示例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: onIpcData
void ScProcess::onIpcData()
{
mIpcData.append(mIpcSocket->readAll());
while (mIpcData.size()) {
QBuffer receivedData ( &mIpcData );
receivedData.open ( QIODevice::ReadOnly );
QDataStream in ( &receivedData );
in.setVersion ( QDataStream::Qt_4_6 );
QString selector, message;
in >> selector;
if ( in.status() != QDataStream::Ok )
return;
in >> message;
if ( in.status() != QDataStream::Ok )
return;
mIpcData.remove ( 0, receivedData.pos() );
onResponse(selector, message);
emit response(selector, message);
}
}
示例4: out
void
CollectionScanner::ScanningState::writeFull()
{
if( !isValid() )
return;
QBuffer buffer;
QDataStream out(&buffer);
m_sharedMemory->lock();
buffer.open(QBuffer::WriteOnly);
out << m_lastDirectory;
out << m_directories;
out << m_badFiles;
m_lastFilePos = buffer.pos();
out << m_lastFile;
int size = buffer.size();
if( size < m_sharedMemory->size() )
{
char *to = (char*)m_sharedMemory->data();
const char *from = buffer.data().data();
memcpy(to, from, size);
}
m_sharedMemory->unlock();
}
示例5: 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);
}
示例6: in
void
CollectionScanner::ScanningState::readFull()
{
if( !isValid() )
return;
QBuffer buffer;
QDataStream in(&buffer);
m_sharedMemory->lock();
buffer.setData((char*)m_sharedMemory->constData(), m_sharedMemory->size());
buffer.open(QBuffer::ReadOnly);
in >> m_lastDirectory;
in >> m_directories;
in >> m_badFiles;
m_lastFilePos = buffer.pos();
in >> m_lastFile;
m_sharedMemory->unlock();
}
示例7: unget
//--------------------------------------------------------------------
void tst_QIODevice::unget()
{
#if defined(Q_OS_WINCE) && defined(WINCE_EMULATOR_TEST)
QSKIP("Networking tests in a WinCE emulator are unstable", SkipAll);
#endif
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
buffer.write("ZXCV");
buffer.seek(0);
QCOMPARE(buffer.read(4), QByteArray("ZXCV"));
QCOMPARE(buffer.pos(), qint64(4));
buffer.ungetChar('a');
buffer.ungetChar('b');
buffer.ungetChar('c');
buffer.ungetChar('d');
QCOMPARE(buffer.pos(), qint64(0));
char buf[6];
QCOMPARE(buffer.readLine(buf, 5), qint64(4));
QCOMPARE(buffer.pos(), qint64(4));
QCOMPARE(static_cast<const char*>(buf), "dcba");
buffer.ungetChar('a');
buffer.ungetChar('b');
buffer.ungetChar('c');
buffer.ungetChar('d');
QCOMPARE(buffer.pos(), qint64(0));
for (int i = 0; i < 5; ++i) {
buf[0] = '@';
buf[1] = '@';
QTest::ignoreMessage(QtWarningMsg,
"QIODevice::readLine: Called with maxSize < 2");
QCOMPARE(buffer.readLine(buf, 1), qint64(-1));
QCOMPARE(buffer.readLine(buf, 2), qint64(i < 4 ? 1 : -1));
switch (i) {
case 0:
QCOMPARE(buf[0], 'd');
break;
case 1:
QCOMPARE(buf[0], 'c');
break;
case 2:
QCOMPARE(buf[0], 'b');
break;
case 3:
QCOMPARE(buf[0], 'a');
break;
case 4:
QCOMPARE(buf[0], '\0');
break;
}
QCOMPARE(buf[1], i < 4 ? '\0' : '@');
}
buffer.ungetChar('\n');
QCOMPARE(buffer.readLine(), QByteArray("\n"));
buffer.seek(1);
buffer.readLine(buf, 3);
QCOMPARE(static_cast<const char*>(buf), "XC");
buffer.seek(4);
buffer.ungetChar('Q');
QCOMPARE(buffer.readLine(buf, 3), qint64(1));
for (int i = 0; i < 2; ++i) {
QTcpSocket socket;
QIODevice *dev;
QByteArray result;
const char *lineResult;
if (i == 0) {
dev = &buffer;
result = QByteArray("ZXCV");
lineResult = "ZXCV";
} else {
socket.connectToHost(QtNetworkSettings::serverName(), 80);
socket.write("GET / HTTP/1.0\r\n\r\n");
QVERIFY(socket.waitForReadyRead());
dev = &socket;
result = QByteArray("HTTP");
lineResult = "Date";
}
char ch, ch2;
dev->seek(0);
dev->getChar(&ch);
dev->ungetChar(ch);
QCOMPARE(dev->peek(4), result);
dev->getChar(&ch);
dev->getChar(&ch2);
dev->ungetChar(ch2);
dev->ungetChar(ch);
QCOMPARE(dev->read(1), result.left(1));
QCOMPARE(dev->read(3), result.right(3));
if (i == 0)
//.........这里部分代码省略.........
示例8: loadMetaInfo
bool loadMetaInfo()
{
LOG("mFormatHint" << mFormatHint);
QBuffer buffer;
buffer.setBuffer(&mData);
buffer.open(QIODevice::ReadOnly);
#ifdef KDCRAW_FOUND
if (KDcrawIface::KDcraw::rawFilesList().contains(QString(mFormatHint))) {
QByteArray previewData;
// if the image is in format supported by dcraw, fetch its embedded preview
mJpegContent.reset(new JpegContent());
// use KDcraw for getting the embedded preview
// KDcraw functionality cloned locally (temp. solution)
bool ret = KDcrawIface::KDcraw::loadEmbeddedPreview(previewData, buffer);
QImage originalImage;
if (!ret || !originalImage.loadFromData(previewData) || qMin(originalImage.width(), originalImage.height()) < MIN_PREV_SIZE) {
// if the embedded preview loading failed or gets just a small image, load
// half preview instead. That's slower but it works even for images containing
// small (160x120px) or none embedded preview.
if (!KDcrawIface::KDcraw::loadHalfPreview(previewData, buffer)) {
qWarning() << "unable to get half preview for " << q->document()->url().fileName();
return false;
}
}
buffer.close();
// now it's safe to replace mData with the jpeg data
mData = previewData;
// need to fill mFormat so gwenview can tell the type when trying to save
mFormat = mFormatHint;
} else {
#else
{
#endif
QImageReader reader(&buffer, mFormatHint);
mImageSize = reader.size();
if (!reader.canRead()) {
qWarning() << "QImageReader::read() using format hint" << mFormatHint << "failed:" << reader.errorString();
if (buffer.pos() != 0) {
qWarning() << "A bad Qt image decoder moved the buffer to" << buffer.pos() << "in a call to canRead()! Rewinding.";
buffer.seek(0);
}
reader.setFormat(QByteArray());
// Set buffer again, otherwise QImageReader won't restart from scratch
reader.setDevice(&buffer);
if (!reader.canRead()) {
qWarning() << "QImageReader::read() without format hint failed:" << reader.errorString();
return false;
}
qWarning() << "Image format is actually" << reader.format() << "not" << mFormatHint;
}
mFormat = reader.format();
if (mFormat == "jpg") {
// if mFormatHint was "jpg", then mFormat is "jpg", but the rest of
// Gwenview code assumes JPEG images have "jpeg" format.
mFormat = "jpeg";
}
}
LOG("mFormat" << mFormat);
GV_RETURN_VALUE_IF_FAIL(!mFormat.isEmpty(), false);
Exiv2ImageLoader loader;
if (loader.load(mData)) {
mExiv2Image = loader.popImage();
}
if (mFormat == "jpeg" && mExiv2Image.get()) {
mJpegContent.reset(new JpegContent());
}
if (mJpegContent.get()) {
if (!mJpegContent->loadFromData(mData, mExiv2Image.get()) &&
!mJpegContent->loadFromData(mData)) {
qWarning() << "Unable to use preview of " << q->document()->url().fileName();
return false;
}
// Use the size from JpegContent, as its correctly transposed if the
// image has been rotated
mImageSize = mJpegContent->size();
mCmsProfile = Cms::Profile::loadFromExiv2Image(mExiv2Image.get());
}
LOG("mImageSize" << mImageSize);
if (!mCmsProfile) {
mCmsProfile = Cms::Profile::loadFromImageData(mData, mFormat);
}
//.........这里部分代码省略.........
示例9: riceviMessaggio
void Server::riceviMessaggio()
{
QTcpSocket* socket;
QBuffer* buffer;
QByteArray line;
socket = (QTcpSocket*)(sender());
buffer = buffers.value(socket);
qint64 bytes = buffer->write(socket->readAll()); //Per la ricezione del messaggio.
buffer->seek(buffer->pos() - bytes);
while (buffer->canReadLine()) //Leggo fino a quando sono presenti linee di testo.
{
line = buffer->readLine();
if(line.startsWith('#')) //Richiesta di autenticazione.
{
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("./users.sqldb");
if (!db.open()) {
socket->write("#false");
}
QSqlQuery s;
QString nome;
QString password;
QList<QByteArray> nomepassword;
nomepassword = line.split('/');
nome = nomepassword[1];
password = nomepassword[2];
password = password.remove("\n");
s.prepare("SELECT Username FROM Utenti WHERE Username = '" + nome + "' AND Password = '" + password +"'");
s.exec();
s.next();
QString username = s.value(0).toString();
if(username != "")
{
socket->write("#true\n");
}
else
{
socket->write("#false\n");
}
db.close();
}
else if(line.startsWith('!')) //Richiesta di iscrizione.
{
QString nome;
QString password;
QList<QByteArray> nomepassword = line.split('/');
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("./users.sqldb");
db.open();
QSqlQuery s;
nome = nomepassword[1];
password = nomepassword[2];
password = password.remove("\n");
s.prepare("INSERT INTO Utenti VALUES ('" + nome + "', '" + password + "')");
s.exec();
db.close();
}
else
foreach (QTcpSocket* connection, connections)
{
connection->write(line); //Invio il testo ricevuto a un'altra connessione.
}
}