本文整理汇总了C++中QBuffer::close方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::close方法的具体用法?C++ QBuffer::close怎么用?C++ QBuffer::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save
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;
}
示例2: HandshakeSize
TEST_F(ProtocolFactory, SelectFragmented)
{
QBuffer device;
QByteArray data1("TEST");
QByteArray data2("TESTDATA1\nOTHER");
MockProtocol mock1;
MockProtocol mock2;
MockProtocol mockOutput;
EXPECT_CALL(mock1, HandshakeSize()).WillRepeatedly(Return(2));
EXPECT_CALL(mock2, HandshakeSize()).WillRepeatedly(Return(10));
EXPECT_CALL(mock1, ConstructIfSuitable(QByteArray("TE"), nullptr)).InSequence(_seq)
.WillOnce(Return(nullptr));
EXPECT_CALL(mock1, ConstructIfSuitable(QByteArray("TE"), nullptr)).InSequence(_seq)
.WillOnce(Return(nullptr));
EXPECT_CALL(mock2, ConstructIfSuitable(QByteArray("TESTDATA1\n"), nullptr)).InSequence(_seq)
.WillOnce(Return(&mockOutput));
_factory.RegisterProtocol(&mock1);
_factory.RegisterProtocol(&mock2);
device.setBuffer(&data1);
device.open(QIODevice::ReadOnly);
EXPECT_EQ(_factory.CreateProtocol(device), nullptr);
EXPECT_EQ(device.read(15), QByteArray("TEST"));
device.close();
device.setBuffer(&data2);
device.open(QIODevice::ReadOnly);
EXPECT_EQ(_factory.CreateProtocol(device), &mockOutput);
EXPECT_EQ(device.read(5), QByteArray("OTHER"));
device.close();
}
示例3: 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);
}
示例4: tst_invalidFrames
void tst_WebSocketFrame::tst_invalidFrames()
{
QFETCH(int, rsv1);
QFETCH(int, rsv2);
QFETCH(int, rsv3);
QFETCH(quint32, mask);
QFETCH(QWebSocketProtocol::OpCode, opCode);
QFETCH(bool, isFinal);
QFETCH(QByteArray, payload);
QFETCH(QWebSocketProtocol::CloseCode, expectedError);
FrameHelper helper;
helper.setRsv1(rsv1);
helper.setRsv2(rsv2);
helper.setRsv3(rsv3);
helper.setMask(mask);
helper.setOpCode(opCode);
helper.setFinalFrame(isFinal);
helper.setPayload(payload);
QByteArray wireRepresentation = helper.wireRepresentation();
QBuffer buffer;
buffer.setData(wireRepresentation);
buffer.open(QIODevice::ReadOnly);
QWebSocketFrame frame = QWebSocketFrame::readFrame(&buffer);
buffer.close();
QVERIFY(!frame.isValid());
QCOMPARE(frame.closeCode(), expectedError);
}
示例5: writeReadElement
Element* MTest::writeReadElement(Element* element)
{
//
// write element
//
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
Xml xml(&buffer);
xml.header();
element->write(xml);
buffer.close();
//
// read element
//
// printf("%s\n", buffer.buffer().data());
QDomDocument doc;
int line, column;
QString err;
if (!doc.setContent(buffer.buffer(), &err, &line, &column)) {
printf("writeReadElement: error reading paste data at line %d column %d: %s\n",
line, column, qPrintable(err));
printf("%s\n", buffer.buffer().data());
return 0;
}
docName = "--";
QDomElement e = doc.documentElement();
QString tag(e.tagName());
element = Element::name2Element(e.tagName(), score);
element->read(e);
return element;
}
示例6: load
void QLCInputProfile_Test::load()
{
QBuffer buffer;
buffer.open(QIODevice::WriteOnly | QIODevice::Text);
QXmlStreamWriter xmlWriter(&buffer);
xmlWriter.writeStartDocument();
xmlWriter.writeDTD("<!DOCTYPE InputProfile>");
xmlWriter.writeStartElement("InputProfile");
xmlWriter.writeTextElement("Manufacturer", "Behringer");
xmlWriter.writeTextElement("Model", "BCF2000");
xmlWriter.writeStartElement("Channel");
xmlWriter.writeAttribute("Number", "492");
xmlWriter.writeTextElement("Name", "Foobar");
xmlWriter.writeTextElement("Type", "Slider");
xmlWriter.writeEndDocument();
xmlWriter.setDevice(NULL);
buffer.close();
buffer.open(QIODevice::ReadOnly | QIODevice::Text);
QXmlStreamReader xmlReader(&buffer);
QLCInputProfile ip;
QVERIFY(ip.loadXML(xmlReader) == true);
QVERIFY(ip.manufacturer() == "Behringer");
QVERIFY(ip.model() == "BCF2000");
QVERIFY(ip.channels().size() == 1);
QVERIFY(ip.channel(492) != NULL);
QVERIFY(ip.channel(492)->name() == "Foobar");
QVERIFY(ip.channel(492)->type() == QLCInputChannel::Slider);
}
示例7: load
void QLCFixtureHead_Test::load()
{
QBuffer buffer;
buffer.open(QIODevice::WriteOnly | QIODevice::Text);
QXmlStreamWriter xmlWriter(&buffer);
xmlWriter.writeStartElement("Head");
xmlWriter.writeTextElement("Channel", "0");
xmlWriter.writeTextElement("Channel", "1");
xmlWriter.writeTextElement("Channel", "15");
xmlWriter.writeTextElement("Foo", "25");
xmlWriter.writeTextElement("Channel", "42");
xmlWriter.writeEndDocument();
xmlWriter.setDevice(NULL);
buffer.close();
buffer.open(QIODevice::ReadOnly | QIODevice::Text);
QXmlStreamReader xmlReader(&buffer);
xmlReader.readNextStartElement();
QLCFixtureHead head;
QVERIFY(head.loadXML(xmlReader));
QCOMPARE(head.channels().size(), 4);
QVERIFY(head.channels().contains(0));
QVERIFY(head.channels().contains(1));
QVERIFY(head.channels().contains(15));
QVERIFY(head.channels().contains(42));
}
示例8: saveXML
void VCProperties_Test::saveXML()
{
VCProperties p;
p.m_size = QSize(33, 44);
p.m_gmChannelMode = GrandMaster::AllChannels;
p.m_gmValueMode = GrandMaster::Limit;
p.m_gmInputUniverse = 3;
p.m_gmInputChannel = 42;
QBuffer buffer;
buffer.open(QIODevice::WriteOnly | QIODevice::Text);
QXmlStreamWriter xmlWriter(&buffer);
QVERIFY(p.saveXML(&xmlWriter) == true);
xmlWriter.setDevice(NULL);
buffer.close();
buffer.open(QIODevice::ReadOnly | QIODevice::Text);
QXmlStreamReader xmlReader(&buffer);
xmlReader.readNextStartElement();
VCProperties p2;
QVERIFY(p2.loadXML(xmlReader) == true);
QCOMPARE(p2.size(), QSize(33, 44));
QCOMPARE(p2.grandMasterChannelMode(), GrandMaster::AllChannels);
QCOMPARE(p2.grandMasterValueMode(), GrandMaster::Limit);
QCOMPARE(p2.grandMasterInputUniverse(), quint32(3));
QCOMPARE(p2.grandMasterInputChannel(), quint32(42));
}
示例9: modelDataToXML
QByteArray BasketModel::modelDataToXML(bool encrypted)
{
QDomDocument doc;
QDomElement root = doc.createElement( "basket-passwords" );
root.setAttribute(QString("ident"), identifier());
setTimeModified(QDateTime::currentDateTime());
//lastDBModified = QDateTime::currentDateTime();
root.setAttribute(QString("modified"), lastDBModified.toString(DATE_TIME_FORMAT));
doc.appendChild( root );
for ( int i = 0; i < rootItem->childCount(); i++ ) {
QDomElement child = convertBasketItemToDomElement(rootItem->childItemAt(i), doc);
root.appendChild(child);
}
QByteArray clearBuffer;
QBuffer clearFile ( &clearBuffer );
if ( !clearFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
return QByteArray();
QTextStream clearStream(&clearFile);
doc.save(clearStream, 4);
clearFile.close();
if ( !encrypted )
return clearBuffer;
BasketUtils butil;
QByteArray encryptedBuffer = butil.crypt(clearBuffer, hash());
return encryptedBuffer;
}
示例10: serializationTest
void serializationTest()
{
Tgs::Random::instance()->seed(0);
shared_ptr<KernelEstimationInterpolator> di = buildRandom();
KernelEstimationInterpolator& uut = *di;
uut.setStopDelta(0.0001);
uut.setSigma(0.3);
Tgs::Random::instance()->seed(0);
double error = uut.estimateError();
QBuffer buf;
buf.open(QBuffer::WriteOnly);
uut.writeInterpolator(buf);
buf.close();
buf.open(QBuffer::ReadOnly);
KernelEstimationInterpolator copy;
copy.readInterpolator(buf);
Tgs::Random::instance()->seed(0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(error, copy.estimateError(), 0.0001);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.3, copy.getSigma(), 0.0001);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0001, copy.getStopDelta(), 0.0001);
}
示例11: UpdateUserInfo
int CUserInfoXmpp::UpdateUserInfo(const QXmppVCardIq &vCard, QString jid)
{
//if(!vCard.fullName().isEmpty())
// m_szName = vCard.fullName();
m_szNick = vCard.nickName();
m_Birthday = vCard.birthday();
m_szEmail = vCard.email();
m_szDescription = vCard.description();
if(!jid.isEmpty() && m_szJid.isEmpty())
m_szJid = jid;
//保存头像
QByteArray photo = vCard.photo();
QBuffer buffer;
buffer.setData(photo);
buffer.open(QIODevice::ReadOnly);
QImageReader imageReader(&buffer);
m_imgPhoto = imageReader.read();
buffer.close();
//保存头像到本地
QImageWriter imageWriter(CGlobal::Instance()->GetFileUserAvatar(GetId()), "png");
if(!imageWriter.write(GetPhoto()))
LOG_MODEL_ERROR("CUserInfo", "Save avater error, %s", imageWriter.errorString().toStdString().c_str());
return 0;
}
示例12: sendResultXml
/**
* Sends result(s) to the server in xml format.
* Send authentication information in the header.
*/
void HttpClient::sendResultXml(QString category, double result)
{
qDebug() << "_sendResultXml";
qDebug() << category;
QBuffer *xmlbuffer = new QBuffer();
QUrl qurl("http://www.speedfreak-app.com/results/update/" + category);
qDebug() << qurl.toString();
QNetworkRequest request(qurl);
QNetworkReply *currentDownload;
xmlbuffer->open(QBuffer::ReadWrite);
myXmlwriter->writeResult(xmlbuffer, result);
qDebug() << "carmainwindow: xmlbuffer->data(): " << xmlbuffer->data();
QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword();
credentials = "Basic " + credentials.toAscii().toBase64();
request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
currentDownload = netManager->post(request, ("xml=" + xmlbuffer->data()));
connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfResult()));
//connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
//Indicating user
if(myMainw->accstart->accRealTimeDialog->resultDialog)
myMainw->accstart->accRealTimeDialog->resultDialog->setLabelInfoToUser("Sending result to server");
xmlbuffer->close();
}
示例13: writeGlobalGUIState
void Workspace::writeGlobalGUIState()
{
QString default_path = "";
QDir dir;
dir.mkpath(dataPath);
default_path = dataPath + "/workspaces";
dir.mkpath(default_path);
default_path += "/global";
dir.mkpath(default_path);
default_path += "/guistate.xml";
QFile default_guistate (default_path);
default_guistate.open(QIODevice::WriteOnly);
if (!default_guistate.exists()) {
writeFailed(default_path);
return;
}
QBuffer cbuf;
cbuf.open(QIODevice::ReadWrite);
XmlWriter xml(gscore, &cbuf);
xml.setClipboardmode(true);
xml.header();
xml.stag("museScore version=\"" MSC_VERSION "\"");
QByteArray state_64 = mscore->saveState().toBase64();
QString state(state_64);
xml.tag("State", state);
xml.etag();
default_guistate.write(cbuf.data());
cbuf.close();
default_guistate.close();
}
示例14: indexesToXML
QByteArray BasketModel::indexesToXML(const QModelIndexList &indexes) const
{
QDomDocument doc;
QDomElement root = doc.createElement( "basket-passwords-items" );
doc.appendChild( root );
foreach(QModelIndex idx, indexes) {
if ( !idx.isValid() )
continue;
if ( idx.column() != 0 )
continue;
BasketBaseItem *item = static_cast<BasketBaseItem *>(idx.internalPointer());
if ( !item )
continue;
QDomElement child = convertBasketItemToDomElement(item, doc);
root.appendChild(child);
}
QByteArray clearBuffer;
QBuffer clearFile ( &clearBuffer );
if ( !clearFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
return QByteArray();
QTextStream clearStream(&clearFile);
doc.save(clearStream, 4);
clearFile.close();
return clearBuffer;
}
示例15:
bool QInstaller::VerboseWriter::flush(VerboseWriterOutput *output)
{
stream.flush();
if (logFileName.isEmpty()) // binarycreator
return true;
if (!preFileBuffer.isOpen())
return true;
//if the installer installed nothing - there is no target directory - where the logfile can be saved
if (!QFileInfo(logFileName).absoluteDir().exists())
return true;
QString logInfo;
logInfo += QLatin1String("************************************* Invoked: ");
logInfo += currentDateTimeAsString;
logInfo += QLatin1String("\n");
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
buffer.write(logInfo.toLocal8Bit());
buffer.write(preFileBuffer.data());
buffer.close();
if (output->write(logFileName, QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text, buffer.data())) {
preFileBuffer.close();
stream.setDevice(nullptr);
return true;
}
return false;
}