本文整理汇总了C++中QBuffer::size方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::size方法的具体用法?C++ QBuffer::size怎么用?C++ QBuffer::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::size方法的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: 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();
}
示例3: 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();
}
示例4: 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();
}
示例5: jpegDecodingQtWebkitStyle
void tst_jpeg::jpegDecodingQtWebkitStyle()
{
// QtWebkit currently calls size() to get the image size for layouting purposes.
// Then when it is in the viewport (we assume that here) it actually gets decoded.
QString testFile = QFINDTESTDATA("n900.jpeg");
QVERIFY2(!testFile.isEmpty(), "cannot find test file n900.jpeg!");
QFile inputJpeg(testFile);
QVERIFY(inputJpeg.exists());
inputJpeg.open(QIODevice::ReadOnly);
QByteArray imageData = inputJpeg.readAll();
QBuffer buffer;
buffer.setData(imageData);
buffer.open(QBuffer::ReadOnly);
QCOMPARE(buffer.size(), qint64(19016));
QBENCHMARK{
for (int i = 0; i < 50; i++) {
QImageReader reader(&buffer, "jpeg");
QSize size = reader.size();
QVERIFY(!size.isNull());
QByteArray format = reader.format();
QVERIFY(!format.isEmpty());
QImage img = reader.read();
QVERIFY(!img.isNull());
buffer.reset();
}
}
}
示例6: write
bool MdlFileFormat::write(const chemkit::MoleculeFile *file, std::ostream &output)
{
QBuffer buffer;
buffer.open(QBuffer::WriteOnly);
bool ok = write(file, &buffer);
if(!ok){
return false;
}
output.write(buffer.data().constData(), buffer.size());
return true;
}
示例7: toString
QString OsmWriter::toString(const ConstOsmMapPtr& map)
{
OsmWriter writer;
// this will be deleted by the _fp auto_ptr
QBuffer* buf = new QBuffer();
writer._fp.reset(buf);
if (!writer._fp->open(QIODevice::WriteOnly | QIODevice::Text))
{
throw InternalErrorException(QObject::tr("Error opening QBuffer for writing. Odd."));
}
writer.write(map);
return QString::fromUtf8(buf->data(), buf->size());
}
示例8: ds
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<typename T> qint64
GetSize()
{
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
QDataStream ds(&buffer);
T obj;
ds << obj;
return buffer.size();
}
示例9: oStream
// +-----------------------------------------------------------
bool f3::LogControl::setLogLevel(const QString &sAppName, const QtMsgType eLevel)
{
// Try to lock the shared memory
if(!m_pSharedMemory->lock())
return false;
// First Read the map from the shared memory
QBuffer oBuffer;
QDataStream oStream(&oBuffer);
oBuffer.setData((char *) m_pSharedMemory->constData(), m_pSharedMemory->size());
oBuffer.open(QBuffer::ReadOnly);
QMap<QString, int> mApps;
oStream >> mApps;
// Then update the value in the map with the new log level (if needed)
int iLevel = mApps[sAppName];
int iNewLevel = ((int) eLevel) + 1;
// And save the map data to the shared memory
if(iLevel == 0 || iLevel != iNewLevel)
{
mApps[sAppName] = iNewLevel;
QBuffer oNewBuffer;
oNewBuffer.open(QBuffer::ReadWrite);
QDataStream oNewStream(&oNewBuffer);
oNewStream << mApps;
int iSize = oNewBuffer.size();
if(iSize < SHARED_MEMORY_SIZE)
{
char *sDataTo = (char *) m_pSharedMemory->data();
const char *sDataFrom = oNewBuffer.data().data();
memset(sDataTo, '\0', SHARED_MEMORY_SIZE);
memcpy(sDataTo, sDataFrom, iSize);
}
else // Oops! Not enough space in the shared memory
{
// Unlock the shared memory before returning failure
m_pSharedMemory->unlock();
return false;
}
}
// Unlock the shared memory before returning
m_pSharedMemory->unlock();
return true;
}
示例10: write
qint64 THttpSocket::write(const THttpHeader *header, QIODevice *body)
{
T_TRACEFUNC("");
if (body && !body->isOpen()) {
if (!body->open(QIODevice::ReadOnly)) {
tWarn("open failed");
return -1;
}
}
// Writes HTTP header
QByteArray hdata = header->toByteArray();
qint64 total = writeRawData(hdata.data(), hdata.size());
if (total < 0) {
return -1;
}
if (body) {
QBuffer *buffer = qobject_cast<QBuffer *>(body);
if (buffer) {
if (writeRawData(buffer->data().data(), buffer->size()) != buffer->size()) {
return -1;
}
total += buffer->size();
} else {
QByteArray buf(WRITE_BUFFER_LENGTH, 0);
qint64 readLen = 0;
while ((readLen = body->read(buf.data(), buf.size())) > 0) {
if (writeRawData(buf.data(), readLen) != readLen) {
return -1;
}
total += readLen;
}
}
}
return total;
}
示例11: playCry
void QtBattleSounds::playCry(QBuffer &buffer) {
qDebug() << "deleting old";
const float volume = cry->volume();
cry->deleteLater();
qDebug() << "constructing new";
cry = new QAudioOutput(readWavHeader(&buffer), this);
cry->setBufferSize(buffer.size());
cry->setVolume(volume);
connect(cry, &QAudioOutput::stateChanged,
this, &QtBattleSounds::cryStateChanged);
qDebug() << "starting to play";
cry->start(&buffer);
}
示例12: saveData
// called from the collection
bool KoImageDataPrivate::saveData(QIODevice &device)
{
// if we have a temp file save that to the store. This is needed as to not loose data when
// saving lossy formats. Also wrinting out gif is not supported by qt so saving temp file
// also fixes the problem that gif images are empty after saving-
if (temporaryFile) {
if (!temporaryFile->open()) {
kWarning(30006) << "Read file from temporary store failed";
return false;
}
char buf[4096];
while (true) {
temporaryFile->waitForReadyRead(-1);
qint64 bytes = temporaryFile->read(buf, sizeof(buf));
if (bytes <= 0)
break; // done!
do {
qint64 nWritten = device.write(buf, bytes);
if (nWritten == -1) {
temporaryFile->close();
return false;
}
bytes -= nWritten;
} while (bytes > 0);
}
temporaryFile->close();
return true;
}
switch (dataStoreState) {
case KoImageDataPrivate::StateEmpty:
return false;
case KoImageDataPrivate::StateNotLoaded:
// we should not reach this state as above this will already be saved.
Q_ASSERT(temporaryFile);
return true;
case KoImageDataPrivate::StateImageLoaded:
case KoImageDataPrivate::StateImageOnly: {
// save image
QBuffer buffer;
QImageWriter writer(&buffer, suffix.toLatin1());
bool result = writer.write(image);
device.write(buffer.data(), buffer.size());
return result;
}
}
return false;
}
示例13: testGroupListRoundTrip
void ContactGroupTest::testGroupListRoundTrip()
{
// TODO should also test empty list
ContactGroup::List list;
ContactGroup group1( QLatin1String( "TestGroup1" ) );
group1.append( ContactGroup::ContactReference( QLatin1String( "Xggdjetw" ) ) );
group1.append( ContactGroup::Data( QLatin1String( "Tobias Koenig" ),
QLatin1String( "[email protected]" ) ) );
group1.append( ContactGroup::Data( QLatin1String( "Kevin Krammer" ),
QLatin1String( "[email protected]" ) ) );
list.append( group1 );
ContactGroup group2( QLatin1String( "TestGroup2" ) );
group2.append( ContactGroup::ContactReference( QLatin1String( "Xggdjetw" ) ) );
group2.append( ContactGroup::Data( QLatin1String( "Tobias Koenig" ),
QLatin1String( "[email protected]" ) ) );
group2.append( ContactGroup::Data( QLatin1String( "Kevin Krammer" ),
QLatin1String( "[email protected]" ) ) );
list.append( group2 );
QBuffer buffer;
buffer.open( QIODevice::WriteOnly );
QString errorMessage;
bool result = ContactGroupTool::convertToXml( list, &buffer, &errorMessage );
QVERIFY( result );
QVERIFY( errorMessage.isEmpty() );
buffer.close();
QVERIFY( buffer.size() > 0 );
buffer.open( QIODevice::ReadOnly );
ContactGroup::List list2;
result = ContactGroupTool::convertFromXml( &buffer, list2, &errorMessage );
QVERIFY( result );
QVERIFY( errorMessage.isEmpty() );
QVERIFY( list2.size() == 2 );
QCOMPARE( list2[0], group1 );
QCOMPARE( list2[1], group2 );
}
示例14: convert
void
TestRun::test() {
inputFilePath = KDESRCDIR "data/diagram.ppt";
referenceDirPath = KDESRCDIR "data/diagram_odp/";
const KoStore::Backend backend = KoStore::Tar;
QBuffer buffer;
convert(buffer, backend);
qDebug() << buffer.isOpen();
buffer.close();
qDebug() << buffer.size();
KoStore* input = KoStore::createStore(&buffer, KoStore::Read,
KoOdf::mimeType(KoOdf::Presentation),
backend);
compareFiles(input, "content.xml");
compareFiles(input, "styles.xml");
compareFiles(input, "meta.xml");
compareFiles(input, "settings.xml");
compareFiles(input, "META-INF/manifest.xml");
}
示例15: testParseMagicFile
void KMimeTypeTest::testParseMagicFile()
{
QFETCH(QString, testData);
//kDebug() << QTest::currentDataTag();
QFETCH(QString, expected);
QBuffer testBuffer;
testBuffer.setData(testData.toLatin1());
QVERIFY(testBuffer.open(QIODevice::ReadOnly));
const qint64 testBufferSize = testBuffer.size();
QString found;
QByteArray beginning;
Q_FOREACH(const KMimeMagicRule& rule, m_rules) {
if (rule.match(&testBuffer, testBufferSize, beginning)) {
found = rule.mimetype();
break;
}
}
QCOMPARE(found, expected);
testBuffer.close();
}