本文整理汇总了C++中QBuffer::open方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::open方法的具体用法?C++ QBuffer::open怎么用?C++ QBuffer::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
virtual QIODevice *data(const QUrl &/*url*/)
{
if (cachedData.isEmpty())
return 0;
QBuffer *buffer = new QBuffer;
buffer->setData(cachedData);
buffer->open(QIODevice::ReadOnly);
return buffer;
}
示例2: Serialize
QByteArray CommandlineOptions::Serialize() const {
QBuffer buf;
buf.open(QIODevice::WriteOnly);
QDataStream s(&buf);
s << *this;
buf.close();
return buf.data();
}
示例3: testSendWithoutSerializer
void testSendWithoutSerializer() {
QBuffer dev;
dev.open(QIODevice::ReadWrite);
mManager->setSerializer(0);
mManager->addDevice(&dev);
// Sending message to dev
QVERIFY( dev.data().isEmpty() );
mService->boolSignal(false);
QVERIFY( dev.data().isEmpty() );
}
示例4: save
void QLCFixtureHead_Test::save()
{
QLCFixtureHead head;
head.addChannel(0);
head.addChannel(1);
head.addChannel(2);
head.addChannel(3);
QBuffer buffer;
buffer.open(QIODevice::WriteOnly | QIODevice::Text);
QXmlStreamWriter xmlWriter(&buffer);
QVERIFY(head.saveXML(&xmlWriter));
xmlWriter.setDevice(NULL);
buffer.close();
buffer.open(QIODevice::ReadOnly | QIODevice::Text);
QXmlStreamReader xmlReader(&buffer);
xmlReader.readNextStartElement();
QCOMPARE(xmlReader.name().toString(), QString("Head"));
int ch = 0;
while (xmlReader.readNextStartElement())
{
if (xmlReader.name() == "Channel")
{
QString chNum = xmlReader.readElementText();
QVERIFY(chNum.toInt() == 0 || chNum.toInt() == 1 ||
chNum.toInt() == 2 || chNum.toInt() == 3);
ch++;
}
else
{
QFAIL(QString("Unexpected tag: %1").arg(xmlReader.name().toString()).toUtf8().constData());
xmlReader.skipCurrentElement();
}
}
QCOMPARE(ch, 4);
}
示例5: sSave
void imageview::sSave()
{
XSqlQuery newImage;
if (_mode == cNew)
{
if (!__imageview.isNull())
{
XSqlQuery imageid("SELECT NEXTVAL('image_image_id_seq') AS _image_id");
if (imageid.first())
_imageviewid = imageid.value("_image_id").toInt();
// ToDo
QImageWriter imageIo;
QBuffer imageBuffer;
QString imageString;
imageBuffer.open(QIODevice::ReadWrite);
imageIo.setDevice(&imageBuffer);
imageIo.setFormat("PNG");
if (!imageIo.write(__imageview))
{
// ToDo - should issue an error here
reject();
return;
}
imageBuffer.close();
imageString = QUUEncode(imageBuffer);
newImage.prepare( "INSERT INTO image "
"(image_id, image_name, image_descrip, image_data) "
"VALUES "
"(:image_id, :image_name, :image_descrip, :image_data);" );
newImage.bindValue(":image_id", _imageviewid);
newImage.bindValue(":image_name", _name->text());
newImage.bindValue(":image_descrip", _descrip->toPlainText());
newImage.bindValue(":image_data", imageString);
}
}
else if (_mode == cEdit)
{
newImage.prepare( "UPDATE image "
"SET image_name=:image_name, image_descrip=:image_descrip "
"WHERE (image_id=:image_id);" );
newImage.bindValue(":image_id", _imageviewid);
newImage.bindValue(":image_name", _name->text());
newImage.bindValue(":image_descrip", _descrip->toPlainText());
}
newImage.exec();
done(_imageviewid);
}
示例6: 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);
}
示例7: 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);
}
示例8: merge
void merge( const QString& newname, const QString& oldname,
const QString& resname )
{
QFile f1(newname);
if ( !f1.open( IO_ReadOnly) )
return;
QFile f2(oldname);
if ( !f2.open( IO_ReadOnly) )
return;
QBuffer fout;
fout.open(IO_WriteOnly);
QTextStream in1( &f1 );
QTextStream in2( &f2 );
QTextStream out( &fout );
QString buf1 = in1.readLine().stripWhiteSpace();
QString buf2 = in2.readLine().stripWhiteSpace();
Item i1 = getItem( in1, buf1 );
Item i2 = getItem( in2, buf2 );
while ( !i1.isNull() || !i2.isNull() ) {
Status s = compare( i1, i2 );
if ( s == Equal ) {
writemerge(out,i1,i2);
i1 = getItem( in1, buf1 );
i2 = getItem( in2, buf2 );
} else if ( s == First ) {
writenew( out, i1 );
i1 = getItem( in1, buf1 );
} else if ( s == FirstJunk ) {
//solitary comment
writejunk( out, i1 );
i1 = getItem( in1, buf1 );
} else if ( s == Second ) {
writeold( out, i2 );
i2 = getItem( in2, buf2 );
} else if ( s == SecondJunk ) {
//solitary comment
writejunk( out, i2 );
i2 = getItem( in2, buf2 );
}
}
f1.close();
f2.close();
fout.close();
QFile fileout(resname);
if ( !fileout.open( IO_WriteOnly | IO_Translate ) )
return;
fileout.writeBlock(fout.buffer());
fileout.close();
}
示例9: sendData
bool sendData(const T & output)
{
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
QDataStream serializer(&buffer);
serializer << output;
writeArray = buffer.data();
emit pulseSendSerialized();
return true;
}
示例10: sendForward
void KMessageClient::sendForward (const QByteArray &msg, const QList <quint32> &clients)
{
QByteArray sendBuffer;
QBuffer buffer (&sendBuffer);
buffer.open (QIODevice::WriteOnly);
QDataStream stream (&buffer);
stream << static_cast<quint32>( KMessageServer::REQ_FORWARD ) << clients;
buffer.QIODevice::write (msg);
sendServerMessage (sendBuffer);
}
示例11: sendBroadcast
void KMessageClient::sendBroadcast (const QByteArray &msg)
{
QByteArray sendBuffer;
QBuffer buffer (&sendBuffer);
buffer.open (QIODevice::WriteOnly);
QDataStream stream (&buffer);
stream << static_cast<quint32> ( KMessageServer::REQ_BROADCAST );
buffer.QIODevice::write (msg);
sendServerMessage (sendBuffer);
}
示例12: defaultTranslator
const KeyboardTranslator* KeyboardTranslatorManager::defaultTranslator()
{
qDebug() << "Loading default translator from text";
QBuffer textBuffer;
textBuffer.setData( defaultTranslatorText, strlen( defaultTranslatorText ) );
if ( !textBuffer.open( QIODevice::ReadOnly ) )
return 0;
return loadTranslator( &textBuffer, "fallback" );
}
示例13: prepareRequestBuffer
QBuffer* KDSoapClientInterfacePrivate::prepareRequestBuffer(const QString& method, const KDSoapMessage& message, const KDSoapHeaders& headers)
{
KDSoapMessageWriter msgWriter;
msgWriter.setMessageNamespace(m_messageNamespace);
msgWriter.setVersion(m_version);
const QByteArray data = msgWriter.messageToXml(message, (m_style == KDSoapClientInterface::RPCStyle) ? method : QString(), headers, m_persistentHeaders, m_version);
QBuffer* buffer = new QBuffer;
buffer->setData(data);
buffer->open(QIODevice::ReadOnly);
return buffer;
}
示例14: t
QWidget * FLManagerModules::createUI( const QString & n, QObject * connector,
QWidget * parent, const char *name ) {
QBuffer b;
b.open( IO_ReadWrite );
QTextStream t( &b );
t.setEncoding( QTextStream::Latin1 );
t << contentCached( n );
b.reset();
QWidget * w = QWidgetFactory::create( &b, connector, parent, name );
return w;
}
示例15: contentsAsByteArray
QByteArray CopyHelper::contentsAsByteArray() const
{
QBuffer result;
result.open(QIODevice::WriteOnly);
QDataStream os(&result);
os << m_locations.size();
foreach (const TextLocation &location, m_locations) {
os << location.position();
os << location.length();
}