本文整理汇总了C++中QBuffer::setBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::setBuffer方法的具体用法?C++ QBuffer::setBuffer怎么用?C++ QBuffer::setBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::setBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void SaveTask::run()
{
if (!m_image.isNull()) {
QBuffer buffer;
if (m_body.isEmpty()) {
buffer.setBuffer(&m_body);
m_image.save(&buffer, "PNG");
}
Thumbnail thumb;
if (m_size.isValid()) {
thumb.image = ImageCrop::crop(m_image, m_size);
buffer.close();
buffer.setBuffer(&thumb.raw);
thumb.image.save(&buffer, "PNG");
}
emit ready(m_id, m_body, thumb);
}
if (!m_fileName.isEmpty() && !m_body.isEmpty()) {
QDir().mkpath(QFileInfo(m_fileName).absolutePath());
QFile file(m_fileName);
if (file.open(QFile::WriteOnly))
file.write(m_body);
}
}
示例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: parse
QVariant LooseJSON::parse(QByteArray data) {
QBuffer buffer;
buffer.setBuffer(&data);
buffer.open(QIODevice::ReadOnly);
QVariant dat = _parse(&buffer);
return dat;
}
示例4: read
bool PSDResourceSection::read(QIODevice* io)
{
quint32 resourceBlockLength = 0;
if (!psdread(io, &resourceBlockLength)) {
error = "Could not read resource block length";
return false;
}
dbgFile << "Resource block length" << resourceBlockLength << "starts at" << io->pos();
QByteArray ba = io->read(resourceBlockLength);
if ((quint32)ba.size() != resourceBlockLength) {
error = "Could not read all resources";
return false;
}
QBuffer buf;
buf.setBuffer(&ba);
buf.open(QBuffer::ReadOnly);
while (!buf.atEnd()) {
PSDResourceBlock* block = new PSDResourceBlock();
if (!block->read(&buf)) {
error = "Error reading block: " + block->error;
return false;
}
dbgFile << "resource block created. Type:" << block->identifier << "size"
<< block->dataSize
<< "," << buf.bytesAvailable() << "bytes to go";
resources[(PSDResourceID)block->identifier] = block;
}
return valid();
}
示例5: 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);
}
示例6: setBuffer_snippet
static void setBuffer_snippet()
{
//! [4]
QByteArray byteArray("abc");
QBuffer buffer;
buffer.setBuffer(&byteArray);
buffer.open(QIODevice::WriteOnly);
buffer.seek(3);
buffer.write("def", 3);
buffer.close();
// byteArray == "abcdef"
//! [4]
}
示例7: pixmap
QPixmap ScreenPacket::pixmap() const{
if(_pixmapGenerated)
return _pixmap;
QBuffer buffer;
const_cast<QByteArray&>(_buffer) = qUncompress(_buffer);
buffer.setBuffer(const_cast<QByteArray*>(&_buffer));
buffer.open(QBuffer::ReadOnly);
QImageReader reader(&buffer, "JPEG");
_pixmap = QPixmap::fromImage(reader.read());
if(_pixmap.isNull()){
QApplication::beep();
}
_pixmapGenerated = true;
return _pixmap;
}
示例8: data
TEST_F(ProtocolFactory, ThrowUnmatched)
{
QByteArray data("TEST");
MockProtocol mock;
EXPECT_CALL(mock, HandshakeSize()).WillRepeatedly(Return(2));
EXPECT_CALL(mock, ConstructIfSuitable(QByteArray("TE"), nullptr)).InSequence(_seq)
.WillOnce(Return(nullptr));
_factory.RegisterProtocol(&mock);
QBuffer device;
device.setBuffer(&data);
device.open(QIODevice::ReadOnly);
EXPECT_THROW(_factory.CreateProtocol(device), Common::Exception);
device.close();
}
示例9: request
/**
* Call method methodName on server side with parameters list
* params. Returns id of request, used in done() and failed()
* signals.
*
* The parameters order is changed in overloaded methods to
* avoid situation when the only parameter is the list.
* \code
* QList<xmlrpc::Variant> parameter;
* ...
* int requestId = client->request( methodName, parameter );
* \endcode
* This leads to this method be called, with parameter treated
* as parameters list. It's possible to fix this with next code:
* \code
* client->request( methodName, xmlrpc::Variant(parameter) );
* \endcode
* but to avoid such kind of bugs, the parameters order in
* overloaded methods was changed.
*/
int Client::request( QList<Variant> params, QString methodName )
{
QBuffer *outBuffer = new QBuffer;
if (use_big_buffer) {
silly_buffer = new QByteArray(700000000, '\0');
outBuffer->setBuffer(silly_buffer);
}
QByteArray data = Request(methodName,params).composeRequest();
QHttpRequestHeader header("POST",d->path);
header.setContentLength( data.size() );
header.setContentType("text/xml");
header.setValue( "User-Agent", d->userAgent );
header.setValue( "Connection", "Keep-Alive");
if ( !d->userName.isEmpty() ) {
QByteArray authData = QString(d->userName + ":" + d->password).toUtf8();
authData = authData.toBase64();
authData = QByteArray("Basic ")+authData;
header.setValue("Authorization", authData.data() );
}
//header.setValue("Connection", "close");
header.setValue("host",d->hostName);
//d->http->setHost( d->hostName, d->port );
int id = d->http->request( header, data, outBuffer );
d->serverResponses[id] = outBuffer;
d->methodNames[id] = methodName;
d->http->close();
#ifdef XMLRPC_DEBUG
qDebug() << "xmlrpc request(" << id << "): " << methodName;
qDebug() << Variant(params).pprint();
#endif
return id;
}
示例10: setImage
void ScreenPacket::setImage(const QImage& image){
/*
QPainter painter;
painter.begin(&image);
painter.fillRect(0, 0, 30, image.height()-10, Qt::white);
painter.setPen(Qt::red);
painter.setFont(QFont("Courier new", 12));
painter.drawText(5, 10, QString::number(QTime::currentTime().second()));
painter.end();
*/
QBuffer buffer;
buffer.setBuffer(&_buffer);
buffer.open(QBuffer::WriteOnly);
buffer.seek(0);
QImageWriter writer(&buffer, "JPEG");
writer.setQuality(32);
writer.setCompression(1);
_pixmapGenerated = writer.write(image);
_buffer = qCompress(_buffer, 9);
//_pixmap = pixmap;
_pixmap = QPixmap::fromImage(image);
}
示例11: stream
QList<QByteArray> CNetworkManager::getPacketsFromBuffer(QByteArray &buffer)
{
QList<QByteArray> ret;
QByteArray packet;
QByteArray endOfFrame;
QDataStream stream(&endOfFrame, QIODevice::WriteOnly);
stream << (quint32) 0xFFFF << (quint32) 0xFFFF;
QBuffer in;
in.setBuffer(&buffer);
in.open(QIODevice::ReadOnly);
do
{
QByteArray c = in.read(1);
packet.append(c);
if (packet.contains(endOfFrame))
{
ret.append(packet);
packet.clear();
}
} while (in.bytesAvailable());
return ret;
}
示例12: capture
void TearScreenCapture::capture()
{
//Remember to delete the frame!
QImage vp = target->grabWindow(0,0,0,1920,1200).toImage();
QByteArray frame_f;
// QDataStream ser(&frame_f,QIODevice::WriteOnly);
// ser << vp;
QBuffer buff;
buff.setBuffer(&frame_f);
buff.open(QIODevice::WriteOnly);
vp.save(&buff,"JPEG");
QByteArray *frame = new QByteArray(qCompress(frame_f,9));
//When the timer is stopped, some frames are redundant.
//We delete these when there are no receivers for the newFrame() signal
//In early releases, this was a blatant memory leak as packets
// are only disposed of *if they are sent* normally.
if( receivers(SIGNAL(newFrame(QByteArray*))) > 0)
newFrame(frame);
else
delete frame;
示例13: 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);
}
//.........这里部分代码省略.........
示例14: grabFramesLoop
void grabFramesLoop(bool &streaming, framebufferinfo &info, QQueue<QByteArray> &queue, QOrientationReading::Orientation &orientation)
{
QImage img(info.scrinfo.xres, info.scrinfo.yres, QImage::Format_RGBA8888);
QBuffer imgBuffer;
QElapsedTimer timer;
timer.start();
int frames = 0;
int old = 0;
int now = 0;
int line = info.fix_scrinfo.line_length / 4;
QByteArray ba;
QTransform transform;
while(streaming) {
for (unsigned int y = 0; y < info.scrinfo.yres; ++y)
{
QRgb *rowData = (QRgb*)img.scanLine(y);
for (unsigned int x = 0; x < info.scrinfo.xres; ++x)
{
rowData[x] = *((unsigned int *)info.fbmmap + ((x + info.scrinfo.xoffset) + (y + info.scrinfo.yoffset) * line));
}
}
imgBuffer.setBuffer(&ba);
imgBuffer.open(QIODevice::WriteOnly);
if(orientation != QOrientationReading::TopUp) {
switch (orientation) {
case QOrientationReading::TopDown:
img = img.transformed(transform.rotate(180));
break;
case QOrientationReading::LeftUp:
img = img.transformed(transform.rotate(90));
break;
case QOrientationReading::RightUp:
img = img.transformed(transform.rotate(-90));
break;
default:
break;
}
img.save(&imgBuffer, "JPG", info.compression);
transform.reset();
// reset to original (correct width x height)
img = QImage(info.scrinfo.xres, info.scrinfo.yres, QImage::Format_RGBA8888);
} else {
img.save(&imgBuffer, "JPG", info.compression);
}
queue.enqueue(ba);
imgBuffer.close();
++frames;
now = timer.elapsed();
if(now > old) {
info.frametime = now - old;
}
old = now;
// get average fps over the last 50 frames
if(frames == 50) {
info.fps = round(50.0 / (timer.restart() / 1000.0));
frames = 0;
}
}
return;
}
示例15: load
void HistoryManager::load()
{
loadSettings();
QFile historyFile(QStandardPaths::writableLocation(QStandardPaths::DataLocation)
+ QLatin1String("/history"));
if (!historyFile.exists())
return;
if (!historyFile.open(QFile::ReadOnly)) {
qWarning() << "Unable to open history file" << historyFile.fileName();
return;
}
QList<HistoryItem> list;
QDataStream in(&historyFile);
// Double check that the history file is sorted as it is read in
bool needToSort = false;
HistoryItem lastInsertedItem;
QByteArray data;
QDataStream stream;
QBuffer buffer;
stream.setDevice(&buffer);
while (!historyFile.atEnd()) {
in >> data;
buffer.close();
buffer.setBuffer(&data);
buffer.open(QIODevice::ReadOnly);
quint32 ver;
stream >> ver;
if (ver != HISTORY_VERSION)
continue;
HistoryItem item;
stream >> item.url;
stream >> item.dateTime;
stream >> item.title;
if (!item.dateTime.isValid())
continue;
if (item == lastInsertedItem) {
if (lastInsertedItem.title.isEmpty() && !list.isEmpty())
list[0].title = item.title;
continue;
}
if (!needToSort && !list.isEmpty() && lastInsertedItem < item)
needToSort = true;
list.prepend(item);
lastInsertedItem = item;
}
if (needToSort)
qSort(list.begin(), list.end());
setHistory(list, true);
// If we had to sort re-write the whole history sorted
if (needToSort) {
m_lastSavedUrl = QString();
m_saveTimer->changeOccurred();
}
}