当前位置: 首页>>代码示例>>C++>>正文


C++ QBuffer::size方法代码示例

本文整理汇总了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;
}
开发者ID:JustFFunny,项目名称:WorkSpace,代码行数:34,代码来源:WriteSharedMemory.cpp

示例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();
}
开发者ID:Rookiee,项目名称:Qt_Codes,代码行数:31,代码来源:dialog.cpp

示例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();
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:34,代码来源:dialog.cpp

示例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();
}
开发者ID:ErrAza,项目名称:amarok,代码行数:28,代码来源:CollectionScanner.cpp

示例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();
        }
    }
}
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:29,代码来源:jpeg.cpp

示例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;
}
开发者ID:armando-2011,项目名称:chemkit,代码行数:12,代码来源:mdlfileformat.cpp

示例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());
}
开发者ID:giserh,项目名称:hootenanny,代码行数:13,代码来源:OsmWriter.cpp

示例8: ds

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<typename T> qint64
GetSize()
{
    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly);

    QDataStream ds(&buffer);

    T obj;
    ds << obj;

    return buffer.size();
}
开发者ID:silverjam,项目名称:SimpleImageShare,代码行数:14,代码来源:commanddata.cpp

示例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;
}
开发者ID:luigivieira,项目名称:F3,代码行数:52,代码来源:logcontrol.cpp

示例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;
}
开发者ID:skipbit,项目名称:treefrog-framework,代码行数:38,代码来源:thttpsocket.cpp

示例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);
}
开发者ID:lamperi,项目名称:pokemon-online,代码行数:14,代码来源:qtbattlesounds.cpp

示例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;
}
开发者ID:abhishekmurthy,项目名称:Calligra,代码行数:49,代码来源:KoImageData_p.cpp

示例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 );
}
开发者ID:lenggi,项目名称:kcalcore,代码行数:45,代码来源:contactgrouptest.cpp

示例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");
}
开发者ID:crayonink,项目名称:calligra-2,代码行数:19,代码来源:TestPPT.cpp

示例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();
}
开发者ID:vasi,项目名称:kdelibs,代码行数:20,代码来源:kmimetypetest.cpp


注:本文中的QBuffer::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。