本文整理汇总了C++中QByteArray::detach方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::detach方法的具体用法?C++ QByteArray::detach怎么用?C++ QByteArray::detach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::detach方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qstrlen
// Code taken from QCString::insert, but trailing nul removed
void KMail::Util::insert(QByteArray &that, uint index, const char *s)
{
int len = qstrlen(s);
if(len == 0)
return;
uint olen = that.size();
int nlen = olen + len;
if(index >= olen) // insert after end of string
{
that.detach();
if(that.resize(nlen + index - olen, QByteArray::SpeedOptim))
{
memset(that.data() + olen, ' ', index - olen);
memcpy(that.data() + index, s, len);
}
}
else
{
that.detach();
if(that.resize(nlen, QByteArray::SpeedOptim)) // normal insert
{
memmove(that.data() + index + len, that.data() + index, olen - index);
memcpy(that.data() + index, s, len);
}
}
}
示例2: setProperty
void DynamicPropertyData::setProperty(const char *name, const QVariant &value,
const QList<QByteArray> &gNames,
const QList<Setter> &gSetters)
{
QByteArray prop = QByteArray::fromRawData(name, strlen(name));
int id = gNames.indexOf(prop);
if (id < 0) {
id = names.indexOf(prop);
if (!value.isValid()) {
if(id < 0)
return;
names.removeAt(id);
values.removeAt(id);
} else {
if (id < 0) {
prop.detach();
names.append(prop);
values.append(value);
} else {
values[id] = value;
}
}
} else {
(this->*gSetters.at(id))(value);
}
}
示例3: memcpy
void KMail::Util::append(QByteArray &that, const QCString &str)
{
that.detach();
uint len1 = that.size();
uint len2 = str.size() - 1;
if(that.resize(len1 + len2, QByteArray::SpeedOptim))
memcpy(that.data() + len1, str.data(), len2);
}
示例4: getSymbolForLabel
TextSymbol* OgrFileImport::getSymbolForLabel(OGRStyleToolH tool, const QByteArray&)
{
Q_ASSERT(OGR_ST_GetType(tool) == OGRSTCLabel);
int is_null;
auto label_string = OGR_ST_GetParamStr(tool, OGRSTLabelTextString, &is_null);
if (is_null)
return nullptr;
auto color_string = OGR_ST_GetParamStr(tool, OGRSTLabelFColor, &is_null);
auto font_size_string = OGR_ST_GetParamStr(tool, OGRSTLabelSize, &is_null);
// Don't use the style string as a key: The style contains the label.
QByteArray key;
key.reserve(qstrlen(color_string) + qstrlen(font_size_string) + 1);
key.append(color_string);
key.append(font_size_string);
auto text_symbol = static_cast<TextSymbol*>(text_symbols.value(key));
if (!text_symbol)
{
text_symbol = static_cast<TextSymbol*>(default_text_symbol->duplicate());
auto color = makeColor(tool, color_string);
if (color)
text_symbol->setColor(color);
else
text_symbol->setHidden(true);
auto font_size = OGR_ST_GetParamDbl(tool, OGRSTLabelSize, &is_null);
if (!is_null && font_size > 0.0)
text_symbol->scale(font_size / text_symbol->getFontSize());
key.detach();
text_symbols.insert(key, text_symbol);
map->addSymbol(text_symbol, map->getNumSymbols());
}
auto anchor = qBound(1, OGR_ST_GetParamNum(tool, OGRSTLabelAnchor, &is_null), 12);
if (is_null)
anchor = 1;
auto angle = OGR_ST_GetParamDbl(tool, OGRSTLabelAngle, &is_null);
if (is_null)
angle = 0.0;
QString description;
description.reserve(qstrlen(label_string) + 100);
description.append(QString::number(100 + anchor));
description.append(QString::number(angle, 'g', 1));
description.append(QLatin1Char(' '));
description.append(label_string);
text_symbol->setDescription(description);
return text_symbol;
}
示例5: _replyFinished
void _replyFinished()
{
Q_Q( NetworkAccessManagerProxy );
QNetworkReply *reply = static_cast<QNetworkReply*>( q->sender() );
KUrl url = reply->request().url();
QList<CallBackData*> callbacks = urlMap.values( url );
urlMap.remove( url );
QByteArray data = reply->readAll();
data.detach(); // detach so the bytes are not deleted before methods are invoked
foreach( const CallBackData *cb, callbacks )
{
// There may have been a redirect.
KUrl redirectUrl = q->getRedirectUrl( reply );
// Check if there's no redirect.
if( redirectUrl.isEmpty() )
{
QByteArray sig = QMetaObject::normalizedSignature( cb->method );
sig.remove( 0, 1 ); // remove first char, which is the member code (see qobjectdefs.h)
// and let Qt's meta object system handle the rest.
if( cb->receiver )
{
bool success( false );
const QMetaObject *mo = cb->receiver.data()->metaObject();
int methodIndex = mo->indexOfSlot( sig );
if( methodIndex != -1 )
{
Error err = { reply->error(), reply->errorString() };
QMetaMethod method = mo->method( methodIndex );
success = method.invoke( cb->receiver.data(),
cb->type,
Q_ARG( KUrl, reply->request().url() ),
Q_ARG( QByteArray, data ),
Q_ARG( NetworkAccessManagerProxy::Error, err ) );
}
if( !success )
{
debug() << QString( "Failed to invoke method %1 of %2" )
.arg( QString(sig) ).arg( mo->className() );
}
}
}
else
{
debug() << "the server is redirecting the request to: " << redirectUrl;
// Let's try to fetch the data again, but this time from the new url.
QNetworkReply *newReply = q->getData( redirectUrl, cb->receiver.data(), cb->method, cb->type );
emit q->requestRedirected( url, redirectUrl );
emit q->requestRedirected( reply, newReply );
}
}
示例6: wireRepresentation
QByteArray FrameHelper::wireRepresentation()
{
quint8 byte = 0x00;
QByteArray wireRep;
quint64 payloadLength = m_payload.length();
//FIN, opcode
byte = static_cast<quint8>((m_opCode & 0x0F) | (m_isFinalFrame ? 0x80 : 0x00)); //FIN, opcode
//RSV1-3
byte |= static_cast<quint8>(((m_rsv1 & 0x01) << 6) | ((m_rsv2 & 0x01) << 5) |
((m_rsv3 & 0x01) << 4));
wireRep.append(static_cast<char>(byte));
byte = 0x00;
if (m_mask != 0)
{
byte |= 0x80;
}
if (payloadLength <= 125)
{
byte |= static_cast<quint8>(payloadLength);
wireRep.append(static_cast<char>(byte));
}
else if (payloadLength <= 0xFFFFU)
{
byte |= 126;
wireRep.append(static_cast<char>(byte));
quint16 swapped = qToBigEndian<quint16>(static_cast<quint16>(payloadLength));
wireRep.append(static_cast<const char *>(static_cast<const void *>(&swapped)), 2);
}
else
{
byte |= 127;
wireRep.append(static_cast<char>(byte));
quint64 swapped = qToBigEndian<quint64>(payloadLength);
wireRep.append(static_cast<const char *>(static_cast<const void *>(&swapped)), 8);
}
//Write mask
if (m_mask != 0)
{
wireRep.append(static_cast<const char *>(static_cast<const void *>(&m_mask)),
sizeof(quint32));
}
QByteArray tmpData = m_payload;
if (m_mask)
{
tmpData.detach();
QWebSocketProtocol::mask(&tmpData, m_mask);
}
wireRep.append(tmpData);
return wireRep;
}
示例7: qstrlen
static ExtensionNode *ensureNode(const QMetaObject *meta)
{
QByteArray id = QByteArray::fromRawData(meta->className(), qstrlen(meta->className()));
ExtensionNodeHash::Iterator it = d->nodes.find(id);
if (it != d->nodes.end())
return it.value();
ExtensionNode *parent = meta->superClass() ? ensureNode(meta->superClass()) : 0;
id.detach();
ExtensionNode *node = d->nodes.insert(id, new ExtensionNode).value();
if (parent)
parent->children << node;
return node;
}
示例8: fetch
bool NoSqlDatabase::fetch(const QString &key, QByteArray &data)
{
qDebug() << "Fetching data" << key;
::std::string value;
if( ! m_db->Get(leveldb::ReadOptions(), key.toStdString(), &value).ok() ) {
qDebug() << "Data not found" << key;
return false;
}
data.setRawData(value.c_str(), value.size());
data.detach();
return true;
}
示例9: ShortLoad
/** Load a QByteArray from a stream with only one leading byte instead of 4. */
void ShortLoad (QDataStream &s, QByteArray &str)
{
str.detach();
quint8 len;
s >> len; // read size of string
if ( len == 0 || s.atEnd() ) { // end of file reached
str.resize( 0 );
return;
}
str.resize( len );
s.readRawData( str.data(), len );
return;
}
示例10: _readDtmData
static QByteArray _readDtmData( QgsRasterDataProvider *provider, const QgsRectangle &extent, int res )
{
QElapsedTimer t;
t.start();
// TODO: use feedback object? (but GDAL currently does not support cancelation anyway)
QgsRasterBlock *block = provider->block( 1, extent, res, res );
QByteArray data;
if ( block )
{
block->convert( Qgis::Float32 ); // currently we expect just floats
data = block->data();
data.detach(); // this should make a deep copy
delete block;
}
return data;
}
示例11: renderSynchronously
QByteArray QgsDemHeightMapGenerator::renderSynchronously( int x, int y, int z )
{
// extend the rect by half-pixel on each side? to get the values in "corners"
QgsRectangle extent = mTilingScheme.tileToExtent( x, y, z );
float mapUnitsPerPixel = extent.width() / mResolution;
extent.grow( mapUnitsPerPixel / 2 );
// but make sure not to go beyond the full extent (returns invalid values)
QgsRectangle fullExtent = mTilingScheme.tileToExtent( 0, 0, 0 );
extent = extent.intersect( &fullExtent );
QgsRasterBlock *block = mDtm->dataProvider()->block( 1, extent, mResolution, mResolution );
QByteArray data;
if ( block )
{
block->convert( Qgis::Float32 ); // currently we expect just floats
data = block->data();
data.detach(); // this should make a deep copy
delete block;
}
return data;
}
示例12: parseBuffer
void ProtocolDecoder::parseBuffer(QByteArray buffer)
{
for (int i=0;i<buffer.size();i++)
{
if (static_cast<unsigned char>(buffer.at(i)) == START_BYTE)
{
if (m_isInPacket)
{
//Bad start
QLOG_DEBUG() << "Bad Start";
}
m_isInPacket = true;
m_isInEscape = false;
m_currMsg.clear();
}
else if (static_cast<unsigned char>(buffer.at(i)) == STOP_BYTE)
{
if (!m_isInPacket)
{
//Bad stop
QLOG_DEBUG() << "Bad Stop";
continue;
}
m_isInPacket = false;
QByteArray toemit = m_currMsg;
toemit.detach();
emit newPacket(toemit);
m_currMsg.clear();
}
else if (m_isInPacket)
{
if (m_isInEscape)
{
if (static_cast<unsigned char>(buffer.at(i)) == ESCAPE_START)
{
m_currMsg.append(START_BYTE);
}
else if (static_cast<unsigned char>(buffer.at(i)) == ESCAPE_ESCAPE)
{
m_currMsg.append(ESCAPE_BYTE);
}
else if (static_cast<unsigned char>(buffer.at(i)) == ESCAPE_STOP)
{
m_currMsg.append(STOP_BYTE);
}
else
{
//Bad escape character
QLOG_DEBUG() << "Bad Escape char";
}
m_isInEscape = false;
}
else if (static_cast<unsigned char>(buffer.at(i)) == ESCAPE_BYTE)
{
m_isInEscape = true;
}
else
{
m_currMsg.append(buffer.at(i));
}
}
else
{
//Out of packet bytes.
QLOG_DEBUG() << "Out of packet bytes" << QString::number(buffer.at(i),16);
}
}
}