本文整理汇总了C++中QBuffer::readAll方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::readAll方法的具体用法?C++ QBuffer::readAll怎么用?C++ QBuffer::readAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::readAll方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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()));
}
示例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: loadFromString
bool CodeEditor::loadFromString(const QByteArray &source, bool meetLineNumbers)
{
QBuffer buf;
buf.setData(source);
buf.open( QIODevice::ReadOnly );
if( DisAss::isLuaBinary( &buf ) )
{
// Binres Lua-File
DisAss d;
if( !d.disassemble( &buf ) )
{
clear();
appendPlainText( tr("-- Binary Lua file with error:") );
appendPlainText( tr("-- '%1'").arg( d.getError().data() ) );
}else
setText( d.toString(meetLineNumbers,!meetLineNumbers,!meetLineNumbers) );
}else
setText( QString::fromLatin1( buf.readAll() ) );
document()->setModified( false );
return true;
}
示例5: writeBinaries
void KdbxXmlWriter::writeBinaries()
{
m_xml.writeStartElement("Binaries");
QHash<QByteArray, int>::const_iterator i;
for (i = m_idMap.constBegin(); i != m_idMap.constEnd(); ++i) {
m_xml.writeStartElement("Binary");
m_xml.writeAttribute("ID", QString::number(i.value()));
QByteArray data;
if (m_db->compressionAlgorithm() == Database::CompressionGZip) {
m_xml.writeAttribute("Compressed", "True");
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
QtIOCompressor compressor(&buffer);
compressor.setStreamFormat(QtIOCompressor::GzipFormat);
compressor.open(QIODevice::WriteOnly);
qint64 bytesWritten = compressor.write(i.key());
Q_ASSERT(bytesWritten == i.key().size());
Q_UNUSED(bytesWritten);
compressor.close();
buffer.seek(0);
data = buffer.readAll();
} else {
data = i.key();
}
if (!data.isEmpty()) {
m_xml.writeCharacters(QString::fromLatin1(data.toBase64()));
}
m_xml.writeEndElement();
}
m_xml.writeEndElement();
}
示例6: callback_read_file
size_t callback_read_file(void *ptr, size_t size, size_t nmemb, void *userp)
{
// qDebug()<<__FILE__<<__LINE__<<__FUNCTION__<<size<<nmemb<<userp;
size_t tlen = size * nmemb, rlen = 0;
QBuffer strbuf;
QByteArray line;
int n = 0, wlen = 0;
CurlFtp *ftp = static_cast<CurlFtp*>(userp);
QLocalSocket *router = ftp->getDataSock2();
strbuf.setData((const char*)ptr, tlen);
strbuf.open(QBuffer::ReadOnly);
// Q_ASSERT(strbuf.canReadLine()); // ???
rlen = 0;
while (!strbuf.atEnd()) {
if (strbuf.canReadLine()) {
line = strbuf.readLine();
} else {
line = strbuf.readAll();
}
rlen += line.length();
wlen = router->write(line);
// qDebug()<<"Line: "<<n++<<line.length()<<wlen;
// fprintf(stdout, "%s", ".");
// fflush(stdout);
Q_ASSERT(line.length() == wlen);
// break;
}
strbuf.close();
router->flush();
// qDebug()<<"can rw:"<<router->isReadable()<<router->isWritable()<<router->isOpen();
// fprintf(stdout, "route read file:. %p %d %s", router, router->bytesAvailable(), "\n");
fflush(stdout);
return rlen;
return 0;
}
示例7: executeKernelRequest
void SchedulerServiceThread::executeKernelRequest(KernelRequest *req){
QString event = QString();
if(req->type() == KernelRequest::ServerShutdown)
event = "shutdown";
if(req->type() == KernelRequest::ServerRestart)
event = "restart";
if(req->type() == KernelRequest::ProcessStart)
event = "processtart:"+req->propertyValue(KernelRequest::ProcessToStart).toString();
if(req->type() == KernelRequest::ProcessStopByName)
event = "processstop:"+req->propertyValue(KernelRequest::ProcessToStop).toString();
if(req->type() == KernelRequest::ProcessStopByPID)
event = "processstop";
if(req->type() == KernelRequest::IndexerFinished)
event = "indexerfinished:"+req->propertyValue(KernelRequest::AffectedDatabase).toString();
if(event.isEmpty())
return;
QStringList keys = this->_instructions->keys();
for(int i = 0; i < keys.length();++i){
SchedulerServiceThread::Task *t = this->_instructions->value(keys.at(i));
if(t->event == event){
Parser::QMathParser *parser = new Parser::QMathParser(this);
Parser::QBoolParser::removeInstance();
QBuffer *buffer = new QBuffer();
parser->setVariable("SystemDefaultConsole",reinterpret_cast<qlonglong>(buffer));
parser->setVariable("console","SystemDefaultConsole");
Parser::QScriptBlock block(parser);
block.exec(QString::fromUtf8(QByteArray::fromHex(t->scriptCode.toUtf8())));
Log::add(QString::fromUtf8(buffer->readAll()),Log::Debug);
delete buffer;
}
}
}
示例8: transformToString
bool XSLTProcessor::transformToString(Node* sourceNode, String&, String& resultString, String&)
{
bool success = false;
RefPtr<XSLStyleSheet> stylesheet = m_stylesheet;
if (!stylesheet && m_stylesheetRootNode) {
Node* node = m_stylesheetRootNode.get();
stylesheet = XSLStyleSheet::createForXSLTProcessor(node->parent() ? node->parent() : node,
node->document()->url().string(),
node->document()->url()); // FIXME: Should we use baseURL here?
// According to Mozilla documentation, the node must be a Document node, an xsl:stylesheet or xsl:transform element.
// But we just use text content regardless of node type.
stylesheet->parseString(createMarkup(node));
}
if (!stylesheet || stylesheet->sheetString().isEmpty())
return success;
RefPtr<Document> ownerDocument = sourceNode->document();
bool sourceIsDocument = (sourceNode == ownerDocument.get());
QXmlQuery query(QXmlQuery::XSLT20);
XSLTMessageHandler messageHandler(ownerDocument.get());
XSLTUriResolver uriResolver(ownerDocument.get());
query.setMessageHandler(&messageHandler);
XSLTProcessor::ParameterMap::iterator end = m_parameters.end();
for (XSLTProcessor::ParameterMap::iterator it = m_parameters.begin(); it != end; ++it)
query.bindVariable(QString(it->first), QXmlItem(QVariant(it->second)));
QString source;
if (sourceIsDocument && ownerDocument->transformSource())
source = ownerDocument->transformSource()->platformSource();
if (!sourceIsDocument || source.isEmpty())
source = createMarkup(sourceNode);
QBuffer inputBuffer;
QBuffer styleSheetBuffer;
QBuffer outputBuffer;
inputBuffer.setData(source.toUtf8());
styleSheetBuffer.setData(QString(stylesheet->sheetString()).toUtf8());
inputBuffer.open(QIODevice::ReadOnly);
styleSheetBuffer.open(QIODevice::ReadOnly);
outputBuffer.open(QIODevice::ReadWrite);
query.setFocus(&inputBuffer);
query.setQuery(&styleSheetBuffer, QUrl(stylesheet->href()));
query.setUriResolver(&uriResolver);
success = query.evaluateTo(&outputBuffer);
outputBuffer.reset();
resultString = QString::fromUtf8(outputBuffer.readAll()).trimmed();
if (m_stylesheet) {
m_stylesheet->clearDocuments();
m_stylesheet = 0;
}
return success;
}
示例9: callCalback
void HttpTaskRunnable::callCalback()
{
Server::CallBackType& callback = m_errorCallback ;
if (m_isSuccessful &&
!m_calbacks[m_request->method()].isEmpty())
{
QString path = m_request->url().path();
for (auto iter = m_calbacks[m_request->method()].begin();
iter != m_calbacks[m_request->method()].end();
++iter)
{
if (path == iter.key())
{
callback = iter.value();
break;
}
}
}
QBuffer outBuff;
outBuff.open(QIODevice::ReadWrite);
QTextStream outStream(&outBuff);
Response response(outStream);
bool isExcept = false;
try
{
callback(*m_request.get(), response);
} catch (const std::exception& exc)
{
qDebug() << "Caught std::exception:" << exc.what();
outBuff.reset();
outStream.seek(0);
isExcept = true;
printStdException(*m_request.get(), response, exc);
} catch (...)
{
isExcept = true;
printUnknownException(*m_request.get(), response);
qDebug() << "Caught unknown exception";
}
outStream.flush();
outBuff.seek(0);
QByteArray outData;
if (response.type() == Response::Text)
{
outData = outBuff.readAll();
}
else
{
outData = isExcept ? QByteArray() : response.outBinaryDat();
}
{
QTextStream stream(m_tcpSocket.get());
stream << "HTTP/1.1 " << response.status() << " OK" << "\r\n";
stream<<response.header();
if (outData.size())
{
stream << "Content-Length: " << outData.size() << "\r\n";
}
stream << "\r\n";
}
if (outData.size())
{
m_tcpSocket->write(outData);
}
m_tcpSocket->waitForBytesWritten();
}