本文整理汇总了C++中QBitArray::isNull方法的典型用法代码示例。如果您正苦于以下问题:C++ QBitArray::isNull方法的具体用法?C++ QBitArray::isNull怎么用?C++ QBitArray::isNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBitArray
的用法示例。
在下文中一共展示了QBitArray::isNull方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PropertyObserver
PropertyObserver *DataModel::createPropertyObserver(QDomElement &observerElement)
{
bool ok;
quint32 internalId = observerElement.attribute(InternalPropertyId).toUInt(&ok);
if (!internalId) {
ConfiguratorHelper::elementError(observerElement, InternalPropertyId);
return 0;
}
//we are creating a subject. If there is InternalPropertyTypeAttribute it has to have "subject" value
QString str = observerElement.attribute(InternalPropertyTypeAttribute);
if ( ("" != str) && (ObserverAttributeValue != str) ) {
ConfiguratorHelper::elementError(observerElement, InternalPropertyTypeAttribute, "Creating observer, and attribute says something else.");
Q_ASSERT(false);
return 0;
}
//get type of observer
str = observerElement.attribute(InternalConverterType);
//! \todo Maybe some mapping of name to ConverterTypes would be nice
PropertySubject *observerSubject = propertySubjectForId_helper(internalId);
if (0 == observerSubject) {
qDebug("%s : Couldn't get propery Subject for id: %d", __PRETTY_FUNCTION__, internalId);
return 0;
}
if ("" == str || InternalConverterNoneValue == str)
return new PropertyObserver(0, observerSubject);
else {
//get type for converter. It's obligatory
QVariant::Type type = (QVariant::Type)QMetaType::type(observerElement.attribute(InternalVariantType).toLatin1());
if (QVariant::Invalid == type) {
ConfiguratorHelper::elementError(observerElement, InternalVariantType);
Q_ASSERT(false);
//we don't delete observerSubject, we don't own it.
return 0;
}
if (InternalConverterUniversalValue == str) { //universal conversion is needed
return new DataModelNS::PropertyWithConversionObserver(0, observerSubject, type, 0); //zero converter means using UniversalConverter by default. Thanks to that, we spare some memory
} else if (InternalConverterScalingValue == str) { //conversion with scaling factor. We need the factor as well - it's obligatory.
float factor = observerElement.attribute(InternalConverterScalingFactor).toFloat(&ok);
if (!ok || 0 == factor) {
ConfiguratorHelper::elementError(observerElement, InternalConverterScalingFactor);
return 0;
}
return new DataModelNS::PropertyWithConversionObserver(0, observerSubject, type, new DataModelNS::PropertyScalerConverter(factor));
} else if (InternalConverterBitmaskValue == str) {
QString mask = observerElement.attribute(InternalConverterBitmaskMask);
QBitArray bitMask;
if (!mask.isEmpty())
bitMask = ConfiguratorHelper::bitArrayFromString(mask, &ok);
if (!ok || bitMask.isNull()) {
ConfiguratorHelper::elementError(observerElement, InternalConverterBitmaskMask);
return 0;
}
return new DataModelNS::PropertyWithConversionObserver(0, observerSubject, type, new DataModelNS::PropertyBitmaskConverter(bitMask));
}
}
return 0;
}
示例2: processPendingMulticastDatagrams
void UDPListener::processPendingMulticastDatagrams()
{
while (this->multicastSocket.hasPendingDatagrams())
{
QHostAddress peerAddress;
const Common::MessageHeader& header = UDPListener::readDatagramToBuffer(this->multicastSocket, peerAddress);
if (header.isNull())
continue;
switch (header.getType())
{
case Common::MessageHeader::CORE_IM_ALIVE:
{
Protos::Core::IMAlive IMAliveMessage;
const bool readOk = IMAliveMessage.ParseFromArray(this->bodyBuffer, header.getSize());
if (!readOk)
{
L_WARN(QString("Unable to read the IMAlive message from peer %1 %2").arg(header.getSenderID().toStr()).arg(peerAddress.toString()));
break;
}
else if (IMAliveMessage.version() != PROTOCOL_VERSION) // If the protocol version doesn't match we don't add the peer.
{
L_WARN(
QString("The peer %1 %2 %3 doesn't have the same protocol version (%4) as us (%5). It will be ignored.")
.arg(Common::ProtoHelper::getStr(IMAliveMessage, &Protos::Core::IMAlive::nick))
.arg(header.getSenderID().toStr())
.arg(peerAddress.toString())
.arg(IMAliveMessage.version())
.arg(PROTOCOL_VERSION)
);
break;
}
this->peerManager->updatePeer(
header.getSenderID(),
peerAddress,
IMAliveMessage.port(),
Common::ProtoHelper::getStr(IMAliveMessage, &Protos::Core::IMAlive::nick),
IMAliveMessage.amount(),
Common::ProtoHelper::getStr(IMAliveMessage, &Protos::Core::IMAlive::core_version)
);
if (IMAliveMessage.chunk_size() > 0)
{
QList<Common::Hash> hashes;
hashes.reserve(IMAliveMessage.chunk_size());
for (int i = 0; i < IMAliveMessage.chunk_size(); i++)
hashes << IMAliveMessage.chunk(i).hash();
QBitArray bitArray = this->fileManager->haveChunks(hashes);
if (!bitArray.isNull()) // If we own at least one chunk we reply with a CHUNKS_OWNED message.
{
Protos::Core::ChunksOwned chunkOwnedMessage;
chunkOwnedMessage.set_tag(IMAliveMessage.tag());
chunkOwnedMessage.mutable_chunk_state()->Reserve(bitArray.size());
for (int i = 0; i < bitArray.size(); i++)
chunkOwnedMessage.add_chunk_state(bitArray[i]);
this->send(Common::MessageHeader::CORE_CHUNKS_OWNED, header.getSenderID(), chunkOwnedMessage);
}
}
}
break;
case Common::MessageHeader::CORE_CHAT_MESSAGE:
{
Protos::Core::ChatMessage chatMessage;
chatMessage.ParseFromArray(this->bodyBuffer, header.getSize());
emit newChatMessage(header.getSenderID(), chatMessage);
}
break;
case Common::MessageHeader::CORE_FIND: // Find.
{
Protos::Core::Find findMessage;
findMessage.ParseFromArray(this->bodyBuffer, header.getSize());
QList<Protos::Common::FindResult> results =
this->fileManager->find(
Common::ProtoHelper::getStr(findMessage, &Protos::Core::Find::pattern),
SETTINGS.get<quint32>("max_number_of_search_result_to_send"),
SETTINGS.get<quint32>("max_udp_datagram_size") - Common::MessageHeader::HEADER_SIZE
);
for (QMutableListIterator<Protos::Common::FindResult> i(results); i.hasNext();)
{
Protos::Common::FindResult& result = i.next();
result.set_tag(findMessage.tag());
this->send(Common::MessageHeader::CORE_FIND_RESULT, header.getSenderID(), result);
}
}
break;
default:
L_WARN(QString("Unkown header type from multicast socket : %1").arg(header.getType(), 0, 16));
}
}
}