本文整理汇总了C++中QBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer类的具体用法?C++ QBuffer怎么用?C++ QBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: style
QString SCPageLayout::saveOdf(KoPASavingContext &context) const
{
KOdfGenericStyle style(KOdfGenericStyle::PresentationPageLayoutStyle);
style.addAttribute("style:display-name", m_name);
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
KXmlWriter elementWriter(&buffer);
QList<SCPlaceholder *>::const_iterator it(m_placeholders.begin());
for (; it != m_placeholders.end(); ++it) {
(*it)->saveOdf(elementWriter);
}
QString placeholders = QString::fromUtf8(buffer.buffer(), buffer.buffer().size());
style.addChildElement("placeholders", placeholders);
// return the style name so we can save the ptr -> style in the saving context so the pages can use it during saving
return context.mainStyles().insert(style, "pl");
}
示例2: json
// Example how to get json using shared memory. Not tested :-D
std::pair<bool, QString> json() {
QSharedMemory sharedMemory;
if (!sharedMemory.attach()) {
return std::make_pair<bool, QString>(false, QString());
}
QBuffer buffer;
QDataStream in(&buffer);
QString json;
sharedMemory.lock();
buffer.setData((char*)sharedMemory.constData(), sharedMemory.size());
buffer.open(QBuffer::ReadOnly);
in >> json;
sharedMemory.unlock();
sharedMemory.detach();
return std::make_pair<bool, QString>(false, QString());
}
示例3: in
void Dialog::loadFromMemory()
{
if (!sharedMemory.attach()) {
ui->label->setText(tr("无法连接到共享内存段,\n"
"请先加载一张图片!"));
return;
}
QBuffer buffer;
QDataStream in(&buffer);
QImage image;
sharedMemory.lock();
buffer.setData((char*)sharedMemory.constData(), sharedMemory.size());
buffer.open(QBuffer::ReadOnly);
in >> image;
sharedMemory.unlock();
sharedMemory.detach();
ui->label->setPixmap(QPixmap::fromImage(image));
}
示例4: writeVariant
void FSTReader::writeVariant(QBuffer& buffer, QVariantHash::const_iterator& it) {
QByteArray key = it.key().toUtf8() + " = ";
QVariantHash hashValue = it.value().toHash();
if (hashValue.isEmpty()) {
buffer.write(key + it.value().toByteArray() + "\n");
return;
}
for (QVariantHash::const_iterator second = hashValue.constBegin(); second != hashValue.constEnd(); second++) {
QByteArray extendedKey = key + second.key().toUtf8();
QVariantList listValue = second.value().toList();
if (listValue.isEmpty()) {
buffer.write(extendedKey + " = " + second.value().toByteArray() + "\n");
continue;
}
buffer.write(extendedKey);
for (QVariantList::const_iterator third = listValue.constBegin(); third != listValue.constEnd(); third++) {
buffer.write(" = " + third->toByteArray());
}
buffer.write("\n");
}
}
示例5: in
//! [3]
void Dialog::loadFromMemory()
{
if (!sharedMemory.attach()) {
ui.label->setText(tr("Unable to attach to shared memory segment.\n" \
"Load an image first."));
return;
}
QBuffer buffer;
QDataStream in(&buffer);
QImage image;
sharedMemory.lock();
buffer.setData((char*)sharedMemory.constData(), sharedMemory.size());
buffer.open(QBuffer::ReadOnly);
in >> image;
sharedMemory.unlock();
sharedMemory.detach();
ui.label->setPixmap(QPixmap::fromImage(image));
}
示例6: switch
void XMLHttpRequest::send(const QString &body) {
Logger::log("XMLHttpRequest::send(): Body: " + body);
switch (readyState()) {
case HEADERS_RECEIVED:
case LOADING:
return;
default:
break;
}
m_redirects = 0;
QBuffer *buffer = new QBuffer;
buffer->setData(body.toUtf8());
buffer->open(QBuffer::ReadOnly);
m_reply = networkAccessManager()->sendCustomRequest(m_request, m_method, buffer);
buffer->setParent(m_reply);
connect(m_reply, SIGNAL(metaDataChanged()), this, SLOT(onReplyMetaDataChanged()));
connect(m_reply, SIGNAL(readyRead()), this, SLOT(onReplyReadyRead()));
connect(m_reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));
}
示例7: 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();
}
示例8: stream
void tst_QNetworkCacheMetaData::stream()
{
QNetworkCacheMetaData data;
data.setUrl(QUrl(EXAMPLE_URL));
QNetworkCacheMetaData::RawHeaderList headers;
headers.append(QNetworkCacheMetaData::RawHeader("foo", "Bar"));
data.setRawHeaders(headers);
data.setLastModified(QDateTime::currentDateTime());
data.setExpirationDate(QDateTime::currentDateTime());
data.setSaveToDisk(false);
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
QDataStream stream(&buffer);
stream << data;
buffer.seek(0);
QNetworkCacheMetaData data2;
stream >> data2;
QCOMPARE(data2, data);
}
示例9: buffer
/**
* \warning The caller has to delete the archive's underlying device
*/
KTar* ModelManager::archiveFromBuffer(const QByteArray& input)
{
// safely remove the const qualifier as the buffer is only opened read-only
QBuffer buffer(const_cast<QByteArray*>(&input));
if (!buffer.open(QIODevice::ReadOnly))
return 0;
QIODevice *uncompressed = KFilterDev::device(&buffer, "application/x-gzip", false);
if (!uncompressed || !uncompressed->open(QIODevice::ReadOnly))
return 0;
//seeking doesn't work properly in kfilterdevs, which trips up KTar. Instead, decompress
//completely before passing it on to KTar
QBuffer *uncompressedBuffer = new QBuffer;
if (!uncompressedBuffer->open(QIODevice::ReadWrite))
return 0;
uncompressedBuffer->write(uncompressed->readAll());
uncompressedBuffer->seek(0);
delete uncompressed;
return new KTar(uncompressedBuffer);
}
示例10: parseHeaders
static HeadersMap parseHeaders(const QByteArray& headerData)
{
HeadersMap headersMap;
QBuffer sourceBuffer;
sourceBuffer.setData(headerData);
sourceBuffer.open(QIODevice::ReadOnly);
// The first line is special, it's the GET or POST line
const QList<QByteArray> firstLine = sourceBuffer.readLine().split(' ');
if (firstLine.count() < 3) {
qDebug() << "Malformed HTTP request:" << firstLine;
return headersMap;
}
const QByteArray requestType = firstLine.at(0);
const QByteArray path = QDir::cleanPath(QString::fromLatin1(firstLine.at(1).constData())).toLatin1();
const QByteArray httpVersion = firstLine.at(2);
headersMap.insert("_requestType", requestType);
headersMap.insert("_path", path);
headersMap.insert("_httpVersion", httpVersion);
while (!sourceBuffer.atEnd()) {
const QByteArray line = sourceBuffer.readLine();
const int pos = line.indexOf(':');
if (pos == -1)
qDebug() << "Malformed HTTP header:" << line;
const QByteArray header = line.left(pos).toLower(); // RFC2616 section 4.2 "Field names are case-insensitive"
const QByteArray value = line.mid(pos+1).trimmed(); // remove space before and \r\n after
//qDebug() << "HEADER" << header << "VALUE" << value;
headersMap.insert(header, value);
}
return headersMap;
}
示例11: _DBG_FILE
/*!
* Store contact
*/
CArrayFixFlat<TUid>* CNsmlContactsDataStoreExtensionPrivate::ImportContactsL( const TDesC8 &contactbufbase )
{
_DBG_FILE("CNsmlContactsDataStoreExtensionPrivate::ImportContactsL: BEGIN");
DBG_DUMP((void*)contactbufbase.Ptr(), contactbufbase.Length(),
_S8("CNsmlContactsDataStoreExtensionPrivate::ImportContactsL: To DB :"));
TBool ret( ETrue );
CArrayFixFlat<TUid>* contactItems = new(ELeave) CArrayFixFlat<TUid>(4);
QBuffer contactsbuf;
contactsbuf.open(QBuffer::ReadWrite);
QByteArray bytearray((char*)contactbufbase.Ptr());
contactsbuf.write(bytearray);
contactsbuf.seek(0);
mReader->setDevice(&contactsbuf);
if (mReader->startReading() && mReader->waitForFinished())
{
DBG_ARGS(_S("CNsmlContactsDataStoreExtensionPrivate::Buffer Count: %d"), mReader->results().count() );
QList<QContact> contacts;
if ( mImporter->importDocuments( mReader->results() ) )
{
contacts = mImporter->contacts();
QMap<int, QContactManager::Error> errorMap;
ret = mContactManager->saveContacts( &contacts, &errorMap );
DBG_ARGS(_S("CNsmlContactsDataStoreExtensionPrivate::Import Status: %d"), ret );
}
if( ret )
{
foreach (QContact contact, contacts )
{
TUint contactid = contact.id().localId();
DBG_ARGS(_S("CNsmlContactsDataStoreExtensionPrivate::Contact ID: %d"), contactid );
contactItems->AppendL( TUid::Uid( contactid ) );
}
}
示例12: qCWarning
bool FileExporterXSLT::save(QIODevice *iodevice, const QSharedPointer<const Element> element, const File *bibtexfile, QStringList *errorLog)
{
if (!iodevice->isWritable() && !iodevice->open(QIODevice::WriteOnly)) {
qCWarning(LOG_KBIBTEX_IO) << "Output device not writable";
return false;
}
m_cancelFlag = false;
XSLTransform xsltransformer(m_xsltFilename);
FileExporterXML xmlExporter;
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
if (xmlExporter.save(&buffer, element, bibtexfile, errorLog)) {
buffer.close();
buffer.open(QIODevice::ReadOnly);
const QString xml = QString::fromUtf8(buffer.readAll().constData());
buffer.close();
const QString html = xsltransformer.transform(xml);
if (!html.isEmpty()) {
iodevice->write(html.toUtf8());
iodevice->close();
return !m_cancelFlag;
}
}
iodevice->close();
return false;
}
示例13: file
void
StationsPluginSimple::saveDiskCache()
{
QDomDocument doc;
QFile file(diskCache());
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
buffer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
buffer.write("<cache>\n");
buffer.write(" <stations>\n");
foreach (Station *station, stations) {
QString data =
" <station id=\"%1\">\n"
" <name>%2</name>\n"
" <description>%3</description>\n"
" <latitude>%4</latitude>\n"
" <longitude>%5</longitude>\n"
" </station>\n";
buffer.write(data.arg(station->id())
.arg(station->name())
.arg(station->description())
.arg(station->pos().x())
.arg(station->pos().y())
.toUtf8());
}
示例14: QBuffer
void Usage::registerUsage() {
if (! g.s.bUsage || g.s.bFirstTime)
return;
QDomDocument doc;
QDomElement root=doc.createElement(QLatin1String("usage"));
doc.appendChild(root);
QDomElement tag;
QDomText t;
OSInfo::fillXml(doc, root);
tag=doc.createElement(QLatin1String("in"));
root.appendChild(tag);
t=doc.createTextNode(g.s.qsAudioInput);
tag.appendChild(t);
tag=doc.createElement(QLatin1String("out"));
root.appendChild(tag);
t=doc.createTextNode(g.s.qsAudioOutput);
tag.appendChild(t);
tag=doc.createElement(QLatin1String("lcd"));
root.appendChild(tag);
t=doc.createTextNode(QString::number(g.lcd->hasDevices() ? 1 : 0));
tag.appendChild(t);
QBuffer *qb = new QBuffer();
qb->setData(doc.toString().toUtf8());
qb->open(QIODevice::ReadOnly);
QNetworkRequest req(QUrl(QLatin1String("http://mumble.info/usage.cgi")));
req.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml"));
QNetworkReply *rep = g.nam->post(req, qb);
qb->setParent(rep);
connect(rep, SIGNAL(finished()), rep, SLOT(deleteLater()));
}
示例15: parseHeaders
static HeadersMap parseHeaders(const QByteArray& headerData) {
HeadersMap headersMap;
QBuffer sourceBuffer;
sourceBuffer.setData(headerData);
sourceBuffer.open(QIODevice::ReadOnly);
// The first line is special, it's the GET or POST line
const QList<QByteArray> firstLine = sourceBuffer.readLine().split(' ');
if (firstLine.count() < 3) {
qDebug() << "Malformed HTTP request:" << firstLine;
return headersMap;
}
const QByteArray request = firstLine[0];
const QByteArray path = firstLine[1];
const QByteArray httpVersion = firstLine[2];
if (request != "GET" && request != "POST") {
qDebug() << "Unknown HTTP request:" << firstLine;
return headersMap;
}
headersMap.insert("_path", path);
headersMap.insert("_httpVersion", httpVersion);
while (!sourceBuffer.atEnd()) {
const QByteArray line = sourceBuffer.readLine();
const int pos = line.indexOf(':');
if (pos == -1)
qDebug() << "Malformed HTTP header:" << line;
const QByteArray header = line.left(pos);
const QByteArray value = line.mid(pos+1).trimmed(); // remove space before and \r\n after
//qDebug() << "HEADER" << header << "VALUE" << value;
headersMap.insert(header, value);
}
return headersMap;
}