• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ qChecksum函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中qChecksum函数的典型用法代码示例。如果您正苦于以下问题:C++ qChecksum函数的具体用法?C++ qChecksum怎么用?C++ qChecksum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: qChecksum

bool SerialClient::writePacket(QByteArray& data)
{
    quint16 checksum;
    
    checksum = qChecksum(data, data.size());
    for(int i = 0;i < SERIAL_MAX_RETRY;i++) {
        m_stream << SERIAL_KEY;
        m_stream << data;
        m_stream << qChecksum(data.constData(), data.size());
        if(checkOk())
            return true;
    }
    return false;
}
开发者ID:DavidMutchler,项目名称:kiss,代码行数:14,代码来源:SerialClient.cpp


示例2: GetDownloadFilename

QString GetDownloadFilename(QString title, QString url)
{
    QByteArray urlarr(url.toLatin1());
    quint16 urlChecksum = qChecksum(urlarr.data(), urlarr.length());
    QByteArray titlearr(title.toLatin1());
    quint16 titleChecksum = qChecksum(titlearr.data(), titlearr.length());
    QUrl qurl(url);
    QString ext = QFileInfo(qurl.path()).suffix();
    QString basefilename = QString("download_%1_%2.%3")
                           .arg(QString::number(urlChecksum))
                           .arg(QString::number(titleChecksum)).arg(ext);

    return basefilename;
}
开发者ID:bwarden,项目名称:mythtv,代码行数:14,代码来源:netutils.cpp


示例3: socketWriteStream

bool CNetRender::SendData(QTcpSocket *socket, sMessage msg)
{
	//			NetRender Message format         (optional)
	// | qint32		| qint32	| qint32	|( 0 - ???	| quint16  |)
	// | command	| id			| size		|( payload	| checksum |)

	if (!socket) return false;
	if(socket->state() != QAbstractSocket::ConnectedState) return false;

	QByteArray byteArray;
	QDataStream socketWriteStream(&byteArray, QIODevice::ReadWrite);

	msg.size = msg.payload.size();
	msg.id = actualId;

	// append header
	socketWriteStream << msg.command << msg.id << msg.size;

	// append payload
	if(msg.size > 0)
	{
		socketWriteStream.writeRawData(msg.payload.data(), msg.size);
		// append checksum
		qint16 checksum = qChecksum(msg.payload.data(), msg.size);
		socketWriteStream << checksum;
	}

	// write to socket
	socket->write(byteArray);
	//socket->waitForBytesWritten();

	return true;
}
开发者ID:gitter-badger,项目名称:mandelbulber2,代码行数:33,代码来源:netrender.cpp


示例4: getCrc

quint16 getCrc(const QString &file_path)
{
  quint16 result = 0;

  QFile file(file_path);
  if (file.open(QIODevice::ReadOnly))
  {
    qint64 file_size = file.size();
    if(file_size)
    {
      QDataStream in(&file);

      char *buf = new char[file_size];
      int num_bytes_read = in.readRawData(buf, file_size);
      if (num_bytes_read != file_size)
      {
        log(QString("Number of bytes read(%) is not equal to file size(%2)"
                    ": %3\n"));
      }
      result = qChecksum(buf, num_bytes_read);
      delete [] buf;
    }
    else
    {
      log(QString("File size is zero: %1\n").arg(file_path));
    }
  }
  else
  {
    log(QString("Failed to open file for reading: %1\n").arg(file_path));
  }


  return result;
}
开发者ID:geotavros,项目名称:PatchMaker,代码行数:35,代码来源:main.cpp


示例5: qChecksum

quint16
Zones::getFingerprint() const
{
    quint64 x = 0;
    for (int i=0; i<ranges.size(); i++) {
        // from
        x += ranges[i].begin.toJulianDay();

        // to
        x += ranges[i].end.toJulianDay();

        // CP
        x += ranges[i].cp;

        // FTP
        x += ranges[i].ftp;

        // W'
        x += ranges[i].wprime;

        // W'
        x += ranges[i].pmax;

        // each zone definition (manual edit/default changed)
        for (int j=0; j<ranges[i].zones.count(); j++) {
            x += ranges[i].zones[j].lo;
        }
    }
    QByteArray ba = QByteArray::number(x);

    // we spot other things separately
    return qChecksum(ba, ba.length());
}
开发者ID:JanDeVisser,项目名称:GoldenCheetah,代码行数:33,代码来源:Zones.cpp


示例6: ba

quint16 OSCPlugin::getHash(QString path)
{
    quint16 hash;
    if (m_hash.contains(path))
        hash = m_hash[path];
    else
    {
        /*
        #include <QByteArray>
        #include <zlib.h>

        QByteArray ba("This is a Test 123 :)!");
        ulong crc = crc32(0, NULL, 0);
        crc = crc32(crc, (const Bytef *)ba.data(), ba.size());
        printf("CRC-32 = 0x%x\n", crc);

        */

        /** No existing hash found. Add a new key to the table */
        hash = qChecksum(path.toUtf8().data(), path.length());
        m_hash[path] = hash;
    }

    return hash;
}
开发者ID:JanetPeck,项目名称:qlcplus,代码行数:25,代码来源:oscplugin.cpp


示例7: whichRange

// get fingerprint just for the range that applies on this date
quint16
Zones::getFingerprint(QDate forDate) const
{
    quint64 x = 0;

    // which range to apply ?
    int i = whichRange(forDate);
    if (i >= 0) {

        // CP
        x += ranges[i].cp;

        // FTP
        x += ranges[i].ftp;

        // W'
        x += ranges[i].wprime;

        // Pmax
        x += ranges[i].pmax;

        // each zone definition (manual edit/default changed)
        for (int j=0; j<ranges[i].zones.count(); j++) {
            x += ranges[i].zones[j].lo;
        }
    }
    QByteArray ba = QByteArray::number(x);

    // limits to only zones now as we sport weight separately
    return qChecksum(ba, ba.length());
}
开发者ID:JanDeVisser,项目名称:GoldenCheetah,代码行数:32,代码来源:Zones.cpp


示例8: uncompressed

	void MTcpSocket::sendPacketInternal(const Mara::MPacket *pPacket)
	{
		QByteArray data;
		bool compressed = pPacket->compressed();

		if(compressed)
		{
			QByteArray uncompressed(*(pPacket->serialize()));
			data = qCompress(uncompressed);
			qDebug("Compression Ratio: %d/%d", data.size(), uncompressed.size());
		}
		else
		{
			data = *(pPacket->serialize());
		}

		{
			QMutexLocker lock(&_mutex);

			write(_packetHeaderBytes);
			_socketStream << data.length();
			_socketStream << pPacket->type();

			write(data);

			_socketStream << qChecksum(data.constData(), data.length());
			_socketStream << compressed;
		}

		if(pPacket->deleteOnSend()) delete pPacket;
	}
开发者ID:Darineth,项目名称:Mara-2,代码行数:31,代码来源:MTcpSocket.cpp


示例9: whichRange

quint16
PaceZones::getFingerprint(QDate forDate) const
{
    quint64 x = 0;

    int i = whichRange(forDate);
    if (i>=0) {

        // from
        x += ranges[i].begin.toJulianDay();

        // to
        x += ranges[i].end.toJulianDay();

        // CV
        x += ranges[i].cv;

        // each zone definition (manual edit/default changed)
        for (int j=0; j<ranges[i].zones.count(); j++) {
            x += ranges[i].zones[j].lo;
        }
    }
    QByteArray ba = QByteArray::number(x);

    return qChecksum(ba, ba.length()); 
}
开发者ID:yarrouye,项目名称:GoldenCheetah,代码行数:26,代码来源:PaceZones.cpp


示例10: while

/* Packets look like this:
        quint32     key = 4 bytes
        QByteArray  data = n bytes
        quint16     checksum = 2 bytes */
bool SerialServer::readPacket(QByteArray *packetData)
{
    while(1){
        QByteArray data;
        quint32 key = 0;
        quint16 checksum = 0xFFFF;
        
        m_inStream >> key;

        if (key == HEADER_KEY) {
            m_inStream >> data;
            m_inStream >> checksum;
            qWarning("data.size()=%d", data.size());
            qWarning("checksum=%x", checksum);
            if(checksum == qChecksum(data, data.size())) {
                *packetData = data;
                sendOk();
                return true;
            }
        }
        m_inStream.skipRawData(512);
        m_inStream.resetStatus();
        qWarning("Retry...");
        if(m_quit) return false;
    }
开发者ID:Craug,项目名称:cbc,代码行数:29,代码来源:SerialServer.cpp


示例11: Q_D

bool QPicturePaintEngine::end()
{
    Q_D(QPicturePaintEngine);
#ifdef QT_PICTURE_DEBUG
    qDebug() << "QPicturePaintEngine::end()";
#endif
    d->pic_d->trecs++;
    d->s << (quint8) QPicturePrivate::PdcEnd << (quint8) 0;
    int cs_start = sizeof(quint32);                // pos of checksum word
    int data_start = cs_start + sizeof(quint16);
    int brect_start = data_start + 2*sizeof(qint16) + 2*sizeof(quint8);
    int pos = d->pic_d->pictb.pos();
    d->pic_d->pictb.seek(brect_start);
    if (d->pic_d->formatMajor >= 4) { // bounding rectangle
        QRect r = static_cast<QPicture *>(d->pdev)->boundingRect();
        d->s << (qint32) r.left() << (qint32) r.top() << (qint32) r.width()
             << (qint32) r.height();
    }
    d->s << (quint32) d->pic_d->trecs;                        // write number of records
    d->pic_d->pictb.seek(cs_start);
    QByteArray buf = d->pic_d->pictb.buffer();
    quint16 cs = (quint16) qChecksum(buf.constData() + data_start, pos - data_start);
    d->s << cs;                                // write checksum
    d->pic_d->pictb.close();
    setActive(false);
    return true;
}
开发者ID:Nacto1,项目名称:qt-everywhere-opensource-src-4.6.2,代码行数:27,代码来源:qpaintengine_pic.cpp


示例12: qUncompress

    void Helpers::restoreBackup(QByteArray& data, const QDir& keystore) {
        QByteArray raw = qUncompress(data);
        QDataStream totalStream(&raw, QIODevice::ReadOnly);

        quint32 allSize;
        quint16 crc;
        totalStream >> allSize;
        totalStream >> crc;
        QByteArray all(allSize, '\0');
        totalStream >> all;

        quint32 segmentSize;
        quint16 checkSum = qChecksum(all.data(), all.size());

        // do CRC check
        if ( crc != checkSum ) {
            throw QString("CRC check mismatch: " + QString::number(crc) + " != " + QString::number(checkSum));
        } else if ( !totalStream.atEnd() ) {
            throw QString("Unexpected data at end of restore stream");
        }

        QByteArray testnetData;

        QDataStream allStream(&all, QIODevice::ReadOnly);
        allStream >> segmentSize;
        QByteArray settingsData(segmentSize, '\0');
        allStream >> settingsData;
        allStream >> segmentSize;
        QByteArray addressData(segmentSize, '\0');
        allStream >> addressData;
        if ( !allStream.atEnd() ) { // testnet addresses are present
            allStream >> segmentSize;
            testnetData = QByteArray(segmentSize, '\0');
            allStream >> testnetData;
        }
开发者ID:almindor,项目名称:etherwall,代码行数:35,代码来源:helpers.cpp


示例13: qWarning

 QByteArray SimpleCrypt::encryptToByteArray(QByteArray plaintext)
 {
     if (m_keyParts.isEmpty()) {
         qWarning() << "No key set.";
         m_lastError = ErrorNoKeySet;
         return QByteArray();
     }
  
  
     QByteArray ba = plaintext;
  
     CryptoFlags flags = CryptoFlagNone;
     if (m_compressionMode == CompressionAlways) {
         ba = qCompress(ba, 9); //maximum compression
         flags |= CryptoFlagCompression;
     } else if (m_compressionMode == CompressionAuto) {
         QByteArray compressed = qCompress(ba, 9);
         if (compressed.count() < ba.count()) {
             ba = compressed;
             flags |= CryptoFlagCompression;
         }
     }
  
     QByteArray integrityProtection;
     if (m_protectionMode == ProtectionChecksum) {
         flags |= CryptoFlagChecksum;
         QDataStream s(&integrityProtection, QIODevice::WriteOnly);
         s << qChecksum(ba.constData(), ba.length());
     } else if (m_protectionMode == ProtectionHash) {
         flags |= CryptoFlagHash;
         QCryptographicHash hash(QCryptographicHash::Sha1);
         hash.addData(ba);
  
         integrityProtection += hash.result();
     }
  
     //prepend a random char to the string
     char randomChar = char(qrand() & 0xFF);
     ba = randomChar + integrityProtection + ba;
  
     int pos(0);
     char lastChar(0);
  
     int cnt = ba.count();
  
     while (pos < cnt) {
         ba[pos] = ba.at(pos) ^ m_keyParts.at(pos % 8) ^ lastChar;
         lastChar = ba.at(pos);
         ++pos;
     }
  
     QByteArray resultArray;
     resultArray.append(char(0x03));  //version for future updates to algorithm
     resultArray.append(char(flags)); //encryption flags
     resultArray.append(ba);
  
     m_lastError = ErrorNoError;
     return resultArray;
 }
开发者ID:UDJ,项目名称:UDJ-Desktop-Client,代码行数:59,代码来源:simplecrypt.cpp


示例14: qxt_p

QString QxtConfirmationMessagePrivate::key() const
{
    QString value = overrideKey;
    if (value.isEmpty())
    {
        const QString all = qxt_p().windowTitle() + qxt_p().text() + qxt_p().informativeText();
        const QByteArray data = all.toLocal8Bit();
        value = QString::number(qChecksum(data.constData(), data.length()));
    }
    return value;
}
开发者ID:mcu786,项目名称:OpenPilot-1,代码行数:11,代码来源:qxtconfirmationmessage.cpp


示例15: qWarning

QByteArray SimpleCrypt::decryptToByteArray(QByteArray cypher)
{
    if (m_keyParts.isEmpty()) {
        qWarning() << "No key set.";
        m_lastError = ErrorNoKeySet;
        return QByteArray();
    }

    if (!cypher.length()) {
        m_lastError = ErrorUnknownVersion;
        return QByteArray();
    }

    QByteArray ba = cypher;

    char version = ba.at(0);

    if (version !=3) {  //we only work with version 3
        m_lastError = ErrorUnknownVersion;
        qWarning() << "Invalid version or not a cyphertext.";
        return QByteArray();
    }

    CryptoFlags flags = CryptoFlags(ba.at(1));

    ba = ba.mid(2);
    int pos(0);
    int cnt(ba.count());
    char lastChar = 0;

    while (pos < cnt) {
        char currentChar = ba[pos];
        ba[pos] = ba.at(pos) ^ lastChar ^ m_keyParts.at(pos % 8);
        lastChar = currentChar;
        ++pos;
    }

    ba = ba.mid(1); //chop off the random number at the start

    bool integrityOk(true);
    if (flags.testFlag(CryptoFlagChecksum)) {
        if (ba.length() < 2) {
            m_lastError = ErrorIntegrityFailed;
            return QByteArray();
        }
        quint16 storedChecksum;
        {
            QDataStream s(&ba, QIODevice::ReadOnly);
            s >> storedChecksum;
        }
        ba = ba.mid(2);
        quint16 checksum = qChecksum(ba.constData(), ba.length());
        integrityOk = (checksum == storedChecksum);
    } else if (flags.testFlag(CryptoFlagHash)) {
开发者ID:binaryking,项目名称:nub,代码行数:54,代码来源:simplecrypt.cpp


示例16: qChecksum

void pAnswer::calculateChecksum(char* _data)
{
    union checksum{
	short int dig;
	char str[2];
    };
    checksum chksm;
    
    chksm.dig = qChecksum(_data + 2, get_size(_data) + 16 - 2);
    for(int i = 0; i < 2; i++)
	_data[i] = chksm.str[i];
}
开发者ID:lgosha,项目名称:ssd,代码行数:12,代码来源:udp_panswer.cpp


示例17: array

bool Editor::open ( bool silentMode )
{
  bool ret = m_textEdit->open ( silentMode, m_filename, m_lastModified );
  QByteArray array ( m_textEdit->toPlainText().toLocal8Bit() );
  if ( array.count() ) {
    char *ptr = array.data();
    quint16 check = qChecksum ( ptr, array.length() );
    m_checksum = check;
  }
  m_timerCheckLastModified.start ( 5000 );
  return ret;
}
开发者ID:vdg1,项目名称:cs8-components,代码行数:12,代码来源:editor.cpp


示例18: GetThumbnailFilename

QString GetThumbnailFilename(QString url, QString title)
{
    QString fileprefix = GetConfDir();

    QDir dir(fileprefix);
    if (!dir.exists())
        dir.mkdir(fileprefix);

    fileprefix += "/cache/netvision-thumbcache";

    dir = QDir(fileprefix);
    if (!dir.exists())
        dir.mkdir(fileprefix);

    QString sFilename = QString("%1/%2_%3")
        .arg(fileprefix)
        .arg(qChecksum(url.toLocal8Bit().constData(),
                       url.toLocal8Bit().size()))
        .arg(qChecksum(title.toLocal8Bit().constData(),
                       title.toLocal8Bit().size()));
    return sFilename;
}
开发者ID:DragonStalker,项目名称:mythtv,代码行数:22,代码来源:netcommon.cpp


示例19: qChecksum

void DLockPacket::updateCrc() {
	// setting back to 0 first
	char empty = 0x00;
	packet.replace(1, 1, &empty, 1);
	packet.replace(2, 1, &empty, 1);
	// then generating the crc
	quint16 crc = qChecksum(packet.constData(), packet.length());
	char low = crc;
	char high = (crc >> 8) & 0xff;
	// finally updating it
	packet.replace(1, 1, &high, 1);
	packet.replace(2, 1, &low, 1);
}
开发者ID:ludovicbarreca,项目名称:dlockd,代码行数:13,代码来源:DLockPacket.cpp


示例20: qChecksum

void tst_BaselineExample::testDataDrivenChecksum_data()
{
    QTest::addColumn<QString>("label");

    const int numItems = 5;
    const char *tags[numItems] = {"short", "long", "empty", "signs", "html"};
    const char *labels[numItems] = {"Ok!", "A really long button text that just does not seem to end", "", "[email protected]#$%^&*()_", "<b>BOLD</b>"};

    for (int i = 0; i<numItems; i++) {
        quint16 checksum = qChecksum(labels[i], qstrlen(labels[i]));
        QBaselineTest::newRow(tags[i], checksum) << labels[i];
    }
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:13,代码来源:tst_baselineexample.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ qCompress函数代码示例发布时间:2022-05-30
下一篇:
C++ qCeil函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap