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


C++ QByteArray::data_ptr方法代码示例

本文整理汇总了C++中QByteArray::data_ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::data_ptr方法的具体用法?C++ QByteArray::data_ptr怎么用?C++ QByteArray::data_ptr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QByteArray的用法示例。


在下文中一共展示了QByteArray::data_ptr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: readFromStreamLX

void readFromStreamLX(QMimeData* aData,RReadStream& aStream)
{
    // This function both leaves and throws exceptions. There must be no destructor
    // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects.
    TCardinality mimeTypeCount;
    aStream >> mimeTypeCount;
    for (int i = 0; i< mimeTypeCount;i++)
    {
        // mime type
        TCardinality mimeTypeSize;
        aStream >> mimeTypeSize;
        HBufC* mimeTypeBuf = HBufC::NewLC(aStream,mimeTypeSize);
        QString mimeType = QString::fromUtf16(mimeTypeBuf->Des().Ptr(),mimeTypeBuf->Length());
        CleanupStack::PopAndDestroy(mimeTypeBuf);
        // mime data
        TCardinality dataSize;
        aStream >> dataSize;
        QByteArray ba;
        ba.reserve(dataSize);
        aStream.ReadL(reinterpret_cast<uchar*>(ba.data_ptr()->data),dataSize);
        ba.data_ptr()->size = dataSize;
        qDebug() << "paste from clipboard mime: " << mimeType << " data: " << ba;
        aData->setData(mimeType,ba);
    }
}
开发者ID:Nacto1,项目名称:qt-everywhere-opensource-src-4.6.2,代码行数:25,代码来源:qclipboard_s60.cpp

示例2: test_setFromRawData

	void test_setFromRawData()
	{
		char rawData[] = "hello world!";

		QByteArray ba;
		QByteArray::DataPtr oldDataPtr = ba.data_ptr();
		ba.setRawData(rawData, 5);
		QVERIFY(oldDataPtr != ba.data_ptr());
		oldDataPtr = ba.data_ptr();
		ba.setRawData(rawData + 6, 5);
		// Start using QByteArray::setRawData directly if the following QVERIFY fails.
		// This would mean that the QByteArray::setRawData behavior has been changed to the
		// desired one where switching from one raw data to another does not cause a
		// QByteArray data block reallocation. Qt5 maybe?
		QVERIFY(oldDataPtr != ba.data_ptr());

		// Go ahead and do tests on our replacement setFromRawData.
		ba = QByteArray();
		oldDataPtr = ba.data_ptr();
		QVERIFY(ba.data_ptr()->ref > 1); // Should be the multi-referenced shared null.
		Pillow::ByteArrayHelpers::setFromRawData(ba, rawData, 0, 5);
		QVERIFY(ba.data_ptr() != oldDataPtr);
		QVERIFY(ba.data_ptr()->ref == 1);
		QVERIFY(rawData[5] != '\0');
		QCOMPARE(ba, QByteArray("hello"));

		// Calling out setFromRawData on a string that is already detached should not reallocate the
		// QByteArray data block, as opposed to QByteArray::setRawData.
		oldDataPtr = ba.data_ptr();
		Pillow::ByteArrayHelpers::setFromRawData(ba, rawData, 6, 5);
		QVERIFY(ba.data_ptr() == oldDataPtr);
		QVERIFY(ba.data_ptr()->ref == 1);
		QVERIFY(rawData[11] != '\0');
		QCOMPARE(ba, QByteArray("world"));
	}
开发者ID:xiaowentao99,项目名称:pillow,代码行数:35,代码来源:ByteArrayHelpersTest.cpp


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