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


C++ QBitArray::count方法代码示例

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


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

示例1: bitsToBytes

QByteArray bitsToBytes(QBitArray bits)
{
    QByteArray bytes;
    bytes.resize(qCeil(bits.count() / 8.0));
    bytes.fill(0);
        for(int b = 0; b < bits.count(); ++b)
        {
            bytes[b / 8] = (bytes.at(b / 8) | ((bits[b] ? 1 : 0) << (b % 8)));
        }

    return bytes;
}
开发者ID:zhenggao2,项目名称:ltetoolset2,代码行数:12,代码来源:main.cpp

示例2: QCOMPARE

void tst_QBitArray::countBits2()
{
    QBitArray bitArray;
    for (int i = 0; i < 4017; ++i) {
        bitArray.resize(i);
        bitArray.fill(true);
        QCOMPARE(bitArray.count(true), i);
        QCOMPARE(bitArray.count(false), 0);
        bitArray.fill(false);
        QCOMPARE(bitArray.count(true), 0);
        QCOMPARE(bitArray.count(false), i);
    }
}
开发者ID:RS102839,项目名称:qt,代码行数:13,代码来源:tst_qbitarray.cpp

示例3: sendPieceList

// Sends the complete list of pieces that we have downloaded.
void PeerWireClient::sendPieceList(const QBitArray &bitField)
{
    // The bitfield message may only be sent immediately after the
    // handshaking sequence is completed, and before any other
    // messages are sent.
    if (!sentHandShake)
        sendHandShake();

    // Don't send the bitfield if it's all zeros.
    if (bitField.count(true) == 0)
	return;

    int bitFieldSize = bitField.size();
    int size = (bitFieldSize + 7) / 8;
    QByteArray bits(size, '\0');
    for (int i = 0; i < bitFieldSize; ++i) {
        if (bitField.testBit(i)) {
            quint32 byte = quint32(i) / 8;
            quint32 bit = quint32(i) % 8;
            bits[byte] = uchar(bits.at(byte)) | (1 << (7 - bit));
        }
    }

    char message[] = {0, 0, 0, 1, 5};
    toNetworkData(bits.size() + 1, &message[0]);
    write(message, sizeof(message));
    write(bits);
}
开发者ID:SfietKonstantin,项目名称:radeon-qt5-qtbase-kms,代码行数:29,代码来源:peerwireclient.cpp

示例4: execute

// Run:
bool OKFilter::execute(const QList<QDir> &directories, const QString &srcFile)
{
    if (directories.size() < 2)
        return false;
    // Get reference file:
    QString refFile = directories.first().absoluteFilePath(srcFile);
    QImage img(refFile);
    int nPixels = img.width()*img.height();
    int threshold = qRound(.5*nPixels);

    // Get reference state:
    QBitArray refState = imageToVect(refFile);
    for (int i=1; i<directories.size(); i++)
    {
        // Exists?
        QString file = directories[i].absoluteFilePath(srcFile);
        QBitArray currentState = imageToVect(file);

        QBitArray tmp = (~refState & currentState) | (refState & ~currentState);
        int nErrors = tmp.count(true);
        if (nErrors > threshold)
            return false;
    }

    return true;
}
开发者ID:flegall2014,项目名称:ImageCompare,代码行数:27,代码来源:okfilter.cpp

示例5: while

QList<QWidget *> FatherBlock::GetEnableBlocksWidget(int theStatusIndex)
{
    QList<QWidget *>theBlockWidgets;
    if(theStatusIndex == -1)
    {
        theStatusIndex = m_current_status_index;
    }
    if(theStatusIndex < m_status_list.count())
    {
        QBitArray theStatus = m_status_list[theStatusIndex];
        int count = theStatus.count()-1;
        while(count >= 0)
        {
            if(theStatus.testBit(count) == true)
            {
                QWidget *ChildBlockWidget = GetSingleBlock(m_block_type);
                ChildBlockWidget->setStyleSheet(m_BlockStyleSheet);
                ChildBlockWidget->setGeometry(m_blocks_list[count]->geometry());
                ChildBlockWidget->setGeometry(ChildBlockWidget->x()+this->x(),ChildBlockWidget->y()+this->y(),ChildBlockWidget->width(),ChildBlockWidget->height());
                theBlockWidgets.append(ChildBlockWidget);
            }
            count--;
        }
    }
    return theBlockWidgets;
}
开发者ID:FIRECONTER,项目名称:RussiaBlocks,代码行数:26,代码来源:FatherBlock.cpp

示例6: AddServerAlibi

  void BlameMatrix::AddServerAlibi(uint server_idx, const QBitArray &bits)
  {
    Q_ASSERT(server_idx < _num_servers);
    Q_ASSERT(_num_users == static_cast<uint>(bits.count()));

    for(uint user_idx=0; user_idx<_num_users; user_idx++) {
      _data[user_idx][server_idx].server_bit= bits[user_idx];
    }
  }
开发者ID:franklinsxx,项目名称:Dissent,代码行数:9,代码来源:BlameMatrix.cpp

示例7: restoreState

void TreeWidget::restoreState(const QByteArray& data)
{
    QVariantMap state;
    QDataStream in(data);
    in >> state;

    if (state.contains("expanded")) {
        QBitArray expanded = state.value("expanded").toBitArray();
        if (expanded.count() == topLevelItemCount()) {
            for (int i = 0; i < expanded.count(); ++i)
                topLevelItem(i)->setExpanded(expanded.testBit(i));
        }
    }
    if (state.contains("sorting")) {
        d.sorting = state.value("sorting").toMap();
        restoreSortOrder();
    }
}
开发者ID:jpnurmi,项目名称:communi-desktop,代码行数:18,代码来源:treewidget.cpp

示例8: addStatus

bool FatherBlock::addStatus(QBitArray theStatus)
{
    if(theStatus.count() == m_blocks_list.count())
    {
        m_status_list.append(theStatus);
        return true;
    }else
    {
        return false;
    }
}
开发者ID:FIRECONTER,项目名称:RussiaBlocks,代码行数:11,代码来源:FatherBlock.cpp

示例9: updateValue

void DashLabel::updateValue(QVariant value){
    if(value.type() == QVariant::Double || value.type() == QVariant::String){
        setText(value.toString());
    }else if(value.type() == QVariant::BitArray){
        QString text;
        QBitArray bit = value.toBitArray();
        for(int i=0; i<bit.count(); i++){
            text.append(bit[i]?'1':'0');
            setText(text);
        }
    }

}
开发者ID:DavideMalvezzi,项目名称:EscorpioEvo15-DAQSystem,代码行数:13,代码来源:dashlabel.cpp

示例10: ReadBitsHelper

  void ReadBitsHelper(int arrlen, int offset, int n_bits)
  {
    QByteArray msg(arrlen, 'a');
    QBitArray bits(n_bits, true);

    Serialization::WriteBitArray(bits, msg, offset);

    QBitArray out = Serialization::ReadBitArray(msg, offset, n_bits);
    EXPECT_EQ(n_bits, out.count());
    for(int i=0; i<n_bits; i++) {
      EXPECT_EQ(true, out[i]);
    }
  }
开发者ID:ASchurman,项目名称:Dissent,代码行数:13,代码来源:SerializationTest.cpp

示例11: slot_test

void QtBinaryCalc::slot_test()
{
	QBitArray *a = new QBitArray();
	QBitArray *b = new QBitArray();
	QBitArray *result = new QBitArray();

	QString *resultString = new QString();

	a->fill(0, 16);
	b->fill(0, 16);
	result->fill(0, 16);

	for(int i = 0 ; i < this->numberA->getBytesAsBin().count() ; i++)
	{
		a->setBit(i, this->numberA->getBytesAsBin().at(i).digitValue() );
	}

	for(int i = 0 ; i < this->numberB->getBytesAsBin().count() ; i++)
	{
		b->setBit(i, this->numberB->getBytesAsBin().at(i).digitValue() );
	}


	*result = ~(*a);
	SHOWVALUE(result, *result);

	for ( int i = result->count()-1 ; i >= 0 ; i-- )
	{
		resultString->append( QString::number( (int)result->at(i) ) );
	}

	SHOWVALUE(resultString, *resultString);
	SHOWVALUE(resultString->toInt(0, 2), resultString->toInt(0,2));//tu trzeba zrobic invert bitow 0->16, 1->15 itd

	this->numberResult->slot_setValue(resultString->toInt());

	SHOWVALUE(a, *a);
	SHOWVALUE(b, *b);

}
开发者ID:pawlosck,项目名称:QtBinaryCalc,代码行数:40,代码来源:qtbinarycalc.cpp

示例12: tempBlock

QList<QRect> FatherBlock::GetEnableBlockRects(int theStatusIndex,bool theRealBlocksFlag)
{
    QList<QRect>theBlockRects;
    if(theStatusIndex == -1)
    {
        theStatusIndex = m_current_status_index;
    }
    if(theStatusIndex < m_status_list.count())
    {
        QBitArray theStatus = m_status_list[theStatusIndex];
        int count = theStatus.count()-1;
        while(count >= 0)
        {
            if(theStatus.testBit(count) == true)
            {
                QRect ChildBlockRect =  QRect(m_blocks_list[count]->geometry());
                ChildBlockRect.setX(ChildBlockRect.x() + this->x());
               ChildBlockRect.setY(ChildBlockRect.y() + this->y());
               ChildBlockRect.setWidth(m_blocks_list[count]->width());
               ChildBlockRect.setHeight(m_blocks_list[count]->height());
                if(!hasBottomBlock(count) && !theRealBlocksFlag)
                {
                    QRect tempBlock(ChildBlockRect);
                    tempBlock.setY(ChildBlockRect.y()+m_blocks_list[count]->height());
                    theBlockRects.append(tempBlock);
                }
                if(!hasRightBlock(count) && !theRealBlocksFlag)
                {
                    QRect tempBlock(ChildBlockRect);
                    tempBlock.setX(ChildBlockRect.x() + m_blocks_list[count]->width());
                    theBlockRects.append(tempBlock);
                }
                 theBlockRects.append(ChildBlockRect);
            }
            count--;
        }
    }
    return theBlockRects;
}
开发者ID:FIRECONTER,项目名称:RussiaBlocks,代码行数:39,代码来源:FatherBlock.cpp

示例13: RotateShape

bool FatherBlock::RotateShape(int theStatusIndex)
{
    if(theStatusIndex < m_status_list.count())
    {
        QBitArray theStatus = m_status_list[theStatusIndex];
        int count = theStatus.count()-1;
        while(count >= 0)
        {
            if(theStatus.testBit(count) == true)
            {
                SetStatusEnable(m_blocks_list[count]);
            }else
            {
                SetStatusDisable(m_blocks_list[count]);
            }
            count--;
        }
        return true;
    }else
    {
        return false;
    }
}
开发者ID:FIRECONTER,项目名称:RussiaBlocks,代码行数:23,代码来源:FatherBlock.cpp

示例14: msg

  TEST(Serialization, ReadBitsEasy) 
  {
    QByteArray msg(1, 'a');
    QBitArray bits(1, true);

    Serialization::WriteBitArray(bits, msg, 0);
    QBitArray out = Serialization::ReadBitArray(msg, 0, 1);
    ASSERT_EQ(1, out.count());
    ASSERT_EQ(true, out[0]);

    bits.setBit(0, false);

    Serialization::WriteBitArray(bits, msg, 0);
    QBitArray out2 = Serialization::ReadBitArray(msg, 0, 1);
    ASSERT_EQ(1, out2.count());

    ReadBitsHelper(2, 0, 8);
    ReadBitsHelper(2, 1, 8);
    ReadBitsHelper(2, 0, 9);
    ReadBitsHelper(3, 1, 9);
    ReadBitsHelper(3, 1, 10);
    ReadBitsHelper(3, 0, 20);
  }
开发者ID:ASchurman,项目名称:Dissent,代码行数:23,代码来源:SerializationTest.cpp

示例15: modifyUnplugEvents

void InputDaemon::modifyUnplugEvents(QQueue<SDL_Event> *sdlEventQueue)
{
    QHashIterator<InputDevice*, InputDeviceBitArrayStatus*> genIter(releaseEventsGenerated);
    while (genIter.hasNext())
    {
        genIter.next();
        InputDevice *device = genIter.key();
        InputDeviceBitArrayStatus *generatedTemp = genIter.value();
        QBitArray tempBitArray = generatedTemp->generateFinalBitArray();
        //qDebug() << "ARRAY: " << tempBitArray;

        unsigned int bitArraySize = tempBitArray.size();
        //qDebug() << "ARRAY SIZE: " << bitArraySize;

        if (bitArraySize > 0 && tempBitArray.count(true) == bitArraySize)
        {
            if (pendingEventValues.contains(device))
            {
                InputDeviceBitArrayStatus *pendingTemp = pendingEventValues.value(device);
                QBitArray pendingBitArray = pendingTemp->generateFinalBitArray();
                QBitArray unplugBitArray = createUnplugEventBitArray(device);
                unsigned int pendingBitArraySize = pendingBitArray.size();

                if (bitArraySize == pendingBitArraySize &&
                    pendingBitArray == unplugBitArray)
                {
                    QQueue<SDL_Event> tempQueue;
                    while (!sdlEventQueue->isEmpty())
                    {
                        SDL_Event event = sdlEventQueue->dequeue();
                        switch (event.type)
                        {
                            case SDL_JOYBUTTONDOWN:
                            case SDL_JOYBUTTONUP:
                            {
                                tempQueue.enqueue(event);
                                break;
                            }
                            case SDL_JOYAXISMOTION:
                            {
                                if (event.jaxis.which != device->getSDLJoystickID())
                                {
                                    tempQueue.enqueue(event);
                                }
                                else
                                {
                                    InputDevice *joy = trackjoysticks.value(event.jaxis.which);

                                    if (joy)
                                    {
                                        JoyAxis *axis = joy->getActiveSetJoystick()->getJoyAxis(event.jaxis.axis);
                                        if (axis)
                                        {
                                            if (axis->getThrottle() != JoyAxis::NormalThrottle)
                                            {
                                                event.jaxis.value = axis->getProperReleaseValue();
                                            }
                                        }
                                    }

                                    tempQueue.enqueue(event);
                                }

                                break;
                            }
                            case SDL_JOYHATMOTION:
                            {
                                tempQueue.enqueue(event);
                                break;
                            }
                            case SDL_CONTROLLERAXISMOTION:
                            {
                                if (event.caxis.which != device->getSDLJoystickID())
                                {
                                    tempQueue.enqueue(event);
                                }
                                else
                                {
                                    InputDevice *joy = trackcontrollers.value(event.caxis.which);
                                    if (joy)
                                    {
                                        SetJoystick* set = joy->getActiveSetJoystick();
                                        JoyAxis *axis = set->getJoyAxis(event.caxis.axis);
                                        if (axis)
                                        {
                                            if (event.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT ||
                                                event.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT)
                                            {
                                                event.caxis.value = axis->getProperReleaseValue();
                                            }
                                        }
                                    }

                                    tempQueue.enqueue(event);
                                }

                                break;
                            }
                            case SDL_CONTROLLERBUTTONDOWN:
                            case SDL_CONTROLLERBUTTONUP:
//.........这里部分代码省略.........
开发者ID:AdriiSixx,项目名称:antimicro,代码行数:101,代码来源:inputdaemon.cpp


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