本文整理汇总了C++中QBuffer::data方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::data方法的具体用法?C++ QBuffer::data怎么用?C++ QBuffer::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
void WriteSharedMemory::write( )
{
QString text = read();
QBuffer buffer;
text = text + "C://project//projectFile" + QString::number(num) + ".txt;";
buffer.open( QBuffer::ReadWrite );
QDataStream out( &buffer );
out << text;
int size = buffer.size();
if(sharedMem.size()<size)
{
qDebug() << "¹²ÏíÄÚ´æ¿Õ¼ä²»¹»£¡";
return ;
}
num++;
freeSystemSem.acquire();
// Write into the shared memory
sharedMem.lock();
char *to = (char*)sharedMem.data();
const char *from = buffer.data().data();
memcpy( to, from, qMin( sharedMem.size(), size ) );
sharedMem.unlock();
usedSystemSem.release();
ui.textEdit_2->append(text);
qDebug() << "WriteSharedMemory:: Write:" << text;
}
示例2: getHeadImage
// Tool fucntions
QByteArray getHeadImage(QString name)
{
QImage img(name);
QBuffer buffer;
img.save(&buffer,"png");
return buffer.data();
}
示例3: 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();
}
示例4: get
QJsonDocument Api::get(const QString& path, CancellationToken cancellationToken) const
{
qInfo() << "Executing GET " << path;
ApiConnectionSettings connectionSettings = defaultConnectionSettings();
ApiConnectionStrategy strategy(connectionSettings, Config::minConnectionTimeoutMsec, Config::maxConnectionTimeoutMsec);
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
if (!strategy.execute(m_dataSource, path, buffer, cancellationToken))
{
throw ApiConnectionError("Failed to connect to the api.");
}
auto data = buffer.data();
QJsonParseError parseError;
auto doc = QJsonDocument::fromJson(data, &parseError);
if (parseError.error != QJsonParseError::NoError)
{
throw InvalidFormatException(parseError.errorString());
}
return doc;
}
示例5: save
void RunnerView::save()
{
if (m_socket->isWritable()) {
QImage image(grabFramebuffer());
QBuffer buffer;
buffer.open(QBuffer::WriteOnly);
QDataStream out(&buffer);
out << image;
int size(buffer.size());
if (m_shared->isAttached()) {
if (m_shared->size() < size && !m_shared->detach()) {
return;
}
}
if (!m_shared->isAttached()) {
if (!m_shared->create(size)) {
qWarning("RunnerView::save - m_shared create error");
return;
}
}
m_shared->lock();
char* to((char*)m_shared->data());
const char* from(buffer.data().data());
memcpy(to, from, qMin(m_shared->size(), size));
m_shared->unlock();
buffer.close();
Message message(m_appUid, MessageType::Update);
message.write(m_socket);
}
}
示例6: out
void
CollectionScanner::ScanningState::writeFull()
{
if( !isValid() )
return;
QBuffer buffer;
QDataStream out(&buffer);
m_sharedMemory->lock();
buffer.open(QBuffer::WriteOnly);
out << m_lastDirectory;
out << m_directories;
out << m_badFiles;
m_lastFilePos = buffer.pos();
out << m_lastFile;
int size = buffer.size();
if( size < m_sharedMemory->size() )
{
char *to = (char*)m_sharedMemory->data();
const char *from = buffer.data().data();
memcpy(to, from, size);
}
m_sharedMemory->unlock();
}
示例7: loadHalfPreview
bool KDcraw::loadHalfPreview(QByteArray& imgData, const QBuffer& inBuffer)
{
QString rawFilesExt(KDcrawIface::KDcraw::rawFiles());
LibRaw raw;
QByteArray inData = inBuffer.data();
int ret = raw.open_buffer((void*) inData.data(), (size_t) inData.size());
if (ret != LIBRAW_SUCCESS)
{
kDebug() << "LibRaw: failed to run dcraw_make_mem_image: " << libraw_strerror(ret);
raw.recycle();
return false;
}
QImage image;
if (!Private::loadHalfPreview(image, raw))
{
kDebug() << "KDcraw: failed to get half preview: " << libraw_strerror(ret);
return false;
}
QBuffer buffer(&imgData);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "JPG");
return true;
}
示例8: writeGlobalMenuBar
void Workspace::writeGlobalMenuBar(QMenuBar* mb)
{
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 += "/menubar.xml";
QFile default_menubar (default_path);
default_menubar.open(QIODevice::WriteOnly);
if (!default_menubar.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 "\"");
writeMenuBar(xml, mb);
xml.etag();
default_menubar.write(cbuf.data());
cbuf.close();
default_menubar.close();
}
示例9: tryGetCountryCode
QString Api::tryGetCountryCode(CancellationToken cancellationToken) const
{
qInfo() << "Getting the country code";
try
{
ApiConnectionSettings connectionSettings(Config::geolocationApiUrl, QStringList());
ApiConnectionStrategy strategy(connectionSettings, Config::geolocationTimeout, Config::geolocationTimeout);
QString path = "v1/country";
QBuffer buffer;
if (!strategy.execute(m_dataSource, path, buffer, cancellationToken))
{
throw ApiConnectionError("Failed to connect to the api.");
}
auto document = QJsonDocument::fromBinaryData(buffer.data());
return document.object()["country"].toString();
}
catch (ApiConnectionError&)
{
return QString();
}
}
示例10: writeMapping
QByteArray FSTReader::writeMapping(const QVariantHash& mapping) {
static const QStringList PREFERED_ORDER = QStringList() << NAME_FIELD << TYPE_FIELD << SCALE_FIELD << FILENAME_FIELD
<< TEXDIR_FIELD << JOINT_FIELD << FREE_JOINT_FIELD
<< BLENDSHAPE_FIELD << JOINT_INDEX_FIELD;
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
for (auto key : PREFERED_ORDER) {
auto it = mapping.find(key);
if (it != mapping.constEnd()) {
if (key == FREE_JOINT_FIELD) { // writeVariant does not handle strings added using insertMulti.
for (auto multi : mapping.values(key)) {
buffer.write(key.toUtf8());
buffer.write(" = ");
buffer.write(multi.toByteArray());
buffer.write("\n");
}
} else {
writeVariant(buffer, it);
}
}
}
for (auto it = mapping.constBegin(); it != mapping.constEnd(); it++) {
if (!PREFERED_ORDER.contains(it.key())) {
writeVariant(buffer, it);
}
}
return buffer.data();
}
示例11: replyFromSlave
void CyclopsMaster::replyFromSlave(int id, bool error) {
// should identify which request we're replying to
QTcpSocket* client = _slaveToClient.take(id);
QBuffer* slaveBuffer = _slaveReplies.take(id);
QByteArray slaveReply = slaveBuffer->data();
// we can now clear all the connection setup for this (slave, request)
delete slaveBuffer;
QHttp* slaveRequest = (QHttp*)sender();
slaveRequest->deleteLater();
if (error) {
// should get the error string from the QHttp pointer...
clog() << "There seems to be problem with one of the slaves... Exiting...";
emit quit();
return;
}
_pendingRequests[client].replies.append(yaml::load(slaveReply).mapping());
// if we're the last of the slaves to respond, we need to send back the answer to the client
sendReadyReply(client);
}
示例12: dumpImage
static void dumpImage(const QImage& image)
{
QBuffer buffer;
buffer.open(QBuffer::WriteOnly);
image.save(&buffer, "PNG");
buffer.close();
const QByteArray& data = buffer.data();
printf("Content-Type: %s\n", "image/png");
printf("Content-Length: %lu\n", static_cast<unsigned long>(data.length()));
const quint32 bytesToWriteInOneChunk = 1 << 15;
quint32 dataRemainingToWrite = data.length();
const char* ptr = data.data();
while (dataRemainingToWrite) {
quint32 bytesToWriteInThisChunk = qMin(dataRemainingToWrite, bytesToWriteInOneChunk);
quint32 bytesWritten = fwrite(ptr, 1, bytesToWriteInThisChunk, stdout);
if (bytesWritten != bytesToWriteInThisChunk)
break;
dataRemainingToWrite -= bytesWritten;
ptr += bytesWritten;
}
fflush(stdout);
}
示例13: ConvertImageToByteArray
QByteArray CChecksumList::ConvertImageToByteArray(QImage aImage) {
QBuffer vBuffer;
QImageWriter vWriter(&vBuffer, "JPG");
vWriter.write(aImage); // unikniecie vWriter.write(*(*vIterator));
return vBuffer.data();
}
示例14: loadFromFile
//! [1]
void Dialog::loadFromFile()
{
if (sharedMemory.isAttached())
detach();
ui.label->setText(tr("Select an image file"));
QString fileName = QFileDialog::getOpenFileName(0, QString(), QString(),
tr("Images (*.png *.xpm *.jpg)"));
QImage image;
if (!image.load(fileName)) {
ui.label->setText(tr("Selected file is not an image, please select another."));
return;
}
ui.label->setPixmap(QPixmap::fromImage(image));
//! [1] //! [2]
// load into shared memory
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
QDataStream out(&buffer);
out << image;
int size = buffer.size();
if (!sharedMemory.create(size)) {
ui.label->setText(tr("Unable to create shared memory segment."));
return;
}
sharedMemory.lock();
char *to = (char*)sharedMemory.data();
const char *from = buffer.data().data();
memcpy(to, from, qMin(sharedMemory.size(), size));
sharedMemory.unlock();
}
示例15: loadFromFile
void Dialog::loadFromFile()
{
if (sharedMemory.isAttached())
detach();
ui->label->setText(tr("选择一个图片文件!"));
QString fileName = QFileDialog::getOpenFileName(0, QString(), QString(),
tr("Images (*.png *.jpg)"));
QImage image;
if (!image.load(fileName)) {
ui->label->setText(tr("选择的文件不是图片,请选择图片文件!"));
return;
}
ui->label->setPixmap(QPixmap::fromImage(image));
// 将图片加载到共享内存
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
QDataStream out(&buffer);
out << image;
int size = buffer.size();
if (!sharedMemory.create(size)) {
ui->label->setText(tr("无法创建共享内存段!"));
return;
}
sharedMemory.lock();
char *to = (char*)sharedMemory.data();
const char *from = buffer.data().data();
memcpy(to, from, qMin(sharedMemory.size(), size));
sharedMemory.unlock();
}