本文整理汇总了C++中qCompress函数的典型用法代码示例。如果您正苦于以下问题:C++ qCompress函数的具体用法?C++ qCompress怎么用?C++ qCompress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qCompress函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: 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
示例2: generateReport
void BugReportForm::generateReport(const QByteArray &buf)
{
Messagebox msgbox;
QFile output;
QString filename=QFileInfo(QString(output_edt->text() +
GlobalAttributes::DIR_SEPARATOR +
GlobalAttributes::BUG_REPORT_FILE)
.arg(QDateTime::currentDateTime().toString(QString("_yyyyMMdd_hhmm")))).absoluteFilePath();
//Opens the file for writting
output.setFileName(filename);
output.open(QFile::WriteOnly);
if(!output.isOpen())
msgbox.show(Exception::getErrorMessage(ERR_FILE_DIR_NOT_WRITTEN).arg(filename), Messagebox::ERROR_ICON);
else
{
QByteArray comp_buf;
//Compress the buffer (using zlib) in a compression rate at 8
comp_buf=qCompress(buf, 8);
//Saves the buffer
output.write(comp_buf.data(), comp_buf.size());
output.close();
msgbox.show(trUtf8("Bug report successfuly generated! Please, send the file <strong>%1</strong> to <em>%2</em> in order be analyzed. Thank you for the collaboration!").arg(filename).arg(GlobalAttributes::BUG_REPORT_EMAIL),
Messagebox::INFO_ICON);
}
}
开发者ID:danubionogueira,项目名称:pgmodeler,代码行数:30,代码来源:bugreportform.cpp
示例3: slotSaveAs
void KMoneyThingMainWidget::slotSave()
{
KTempFile temp;
QString fileName = mCurrentFile->kurl().path();
if (fileName == "")
{
slotSaveAs();
return;
}
if (!mCurrentFile->kurl().isLocalFile())
{
fileName = temp.name();
}
emit(setStatus(i18n("Saving file...")));
QByteArray dump = qCompress(mCurrentFile->dump());
QFile file(fileName);
file.open(IO_WriteOnly);
QDataStream stream(&file);
stream << (QString) "KMoneyThingFile" << dump;
file.close();
if (!mCurrentFile->kurl().isLocalFile())
{
emit(setStatus(i18n("Uploading file...")));
if (!KIO::NetAccess::upload(fileName, mCurrentFile->kurl(), this))
KMessageBox::error(this, i18n("Failed to upload file."));
}
temp.unlink();
emit(setStatus(i18n("Ready.")));
}
开发者ID:BackupTheBerlios,项目名称:kmoneything-svn,代码行数:35,代码来源:kmoneythingmainwidget.cpp
示例4: writeData
bool JArchive::writeData(const QString &key,const QByteArray &data,bool compress,const QString &data_type) {
QByteArray data2;
if (compress) data2=qCompress(data);
QString tmp=key;
if (!d->m_group_prefix.isEmpty())
tmp=d->m_group_prefix+"/"+key;
QByteArray key2=tmp.toAscii();
QByteArray data_type2=data_type.toAscii();
qint32 length_of_header=4+4+4+4+4+key2.count()+4+4+data_type2.count();
qint32 length_of_data=data.count();
qint32 compressed_length_of_data=length_of_data;
if (compress) {
compressed_length_of_data=data2.count();
}
qint32 length_of_key=key2.count();
qint32 is_compressed=0;
if (compress) is_compressed=1;
qint32 code=JARCHIVE_BEGIN_RECORD_CODE;
qint32 length_of_data_type=data_type2.count();
d->write_int32(code); //4
d->write_int32(length_of_header); //4
d->write_int32(compressed_length_of_data); //4
d->write_int32(length_of_data); //4
d->write_int32(length_of_key); //4
d->write_bytes(key2); //length_of_key
d->write_int32(is_compressed); //4
d->write_int32(length_of_data_type); //4
d->write_bytes(data_type2); //length_of_data_type
if (compress) d->write_bytes(data2);
else d->write_bytes(data);
return true;
}
开发者ID:magland,项目名称:viewmda,代码行数:34,代码来源:jarchive.cpp
示例5: qCompress
void Socket::sendData(const QByteArray &content)
{
if(socket->state() == QAbstractSocket::ConnectedState){
QByteArray buffer;
if(compressed_){
buffer = qCompress(content);
}else{
buffer = content;
}
quint32 length = buffer.length()+1; // one more byte to
// store extra information
uchar c1, c2, c3, c4;
c1 = length & 0xFF;
length >>= 8;
c2 = length & 0xFF;
length >>= 8;
c3 = length & 0xFF;
length >>= 8;
c4 = length & 0xFF;
socket->putChar(c4);
socket->putChar(c3);
socket->putChar(c2);
socket->putChar(c1);
// lowest bit for compressed or not
if(compressed_){
socket->putChar(0x1);
}else{
socket->putChar(0);
}
socket->write(buffer);
}
开发者ID:paintty-project,项目名称:painttyUpdater,代码行数:32,代码来源:socket.cpp
示例6: prepName
// Save the prepared API information.
bool QsciAPIs::savePrepared(const QString &filename) const
{
QString pname = prepName(filename, true);
if (pname.isEmpty())
return false;
// Write the prepared data to a memory buffer.
QByteArray pdata;
QDataStream pds(&pdata, QIODevice::WriteOnly);
// Use a serialisation format supported by Qt v3.0 and later.
pds.setVersion(QDataStream::Qt_3_0);
pds << PreparedDataFormatVersion;
pds << lexer()->lexer();
pds << prep->wdict;
pds << prep->raw_apis;
// Compress the data and write it.
QFile pf(pname);
if (!pf.open(QIODevice::WriteOnly|QIODevice::Truncate))
return false;
if (pf.write(qCompress(pdata)) < 0)
{
pf.close();
return false;
}
pf.close();
return true;
}
开发者ID:Esenin,项目名称:qreal,代码行数:34,代码来源:qsciapis.cpp
示例7: out
bool Vocabulary::save( const QString& filename ) const {
QByteArray data;
QDataStream out( &data, QIODevice::WriteOnly );
out.setVersion( QDataStream::Qt_2_1 );
// 0x0010 means 0.10.x version.
out << qint32( Vocabulary::magicNumber ) << qint16( 0x0010 ) << *this;
QByteArray compressedData( qCompress( data ) );
QFile dataFile( filename );
QFileInfo dataFileInfo( dataFile );
QDir dataFileDir( dataFileInfo.absoluteDir() );
if( !dataFileDir.mkpath( dataFileDir.path() ) )
return( false );
if( !dataFile.open( QIODevice::WriteOnly ) )
return( false );
int ret = dataFile.write( compressedData );
dataFile.close();
if( ret == -1 || dataFile.error() != QFile::NoError ) {
dataFile.unsetError();
return( false );
}
return( true );
}
开发者ID:FBergeron,项目名称:tomotko-fremantle,代码行数:31,代码来源:Vocabulary.cpp
示例8: s
bool Emu::saveState(const QString &statePath)
{
emsl.save = true;
QByteArray data;
data.reserve(10*1024*1024);
QDataStream s(&data, QIODevice::WriteOnly);
s.setByteOrder(QDataStream::LittleEndian);
s.setFloatingPointPrecision(QDataStream::SinglePrecision);
if (!saveInternal(&s))
return false;
QFile file(statePath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
emsl.error = tr("Could not open file for writing.");
return false;
}
s.setDevice(&file);
s << frame().copy(videoSrcRect().toRect());
QByteArray compressed = qCompress(data);
bool ok = (file.write(compressed) == compressed.size());
file.close();
if (!ok)
file.remove();
return ok;
}
开发者ID:V10lator,项目名称:emumaster,代码行数:28,代码来源:emu.cpp
示例9: out
QByteArray ourtrackserv::Serialize(const QVector<MainListItem> &items)
{
// Результирующий буффер
QByteArray buffer;
QDataStream out(&buffer, QIODevice::WriteOnly);
QMap<quint16, QVariant> m; // Карта для записи элементов класса для последующей сериализации
int counter = 0; // Количество записей в карту (используется как ключ)
// Добавляем количество элементов (потребуется для десериализации)
m.insert(counter++, items.size());
// Добавляем все элементы
for (auto it = items.begin(); it != items.end(); ++it)
{
m.insert(counter++, it->id);
m.insert(counter++, it->category);
m.insert(counter++, it->name);
m.insert(counter++, it->description);
m.insert(counter++, it->size);
m.insert(counter++, it->reg_time);
m.insert(counter++, it->hash);
m.insert(counter++, it->user_id);
m.insert(counter++, it->download);
m.insert(counter++, it->liked);
}
out << m;
return qCompress(buffer, 0);
}
开发者ID:AiSatan,项目名称:ourtrack,代码行数:30,代码来源:serialization.cpp
示例10: embedData
static ulong embedData( QTextStream& out, const uchar* input, int nbytes )
{
#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
QByteArray bazip( qCompress( input, nbytes ) );
ulong len = bazip.size();
#else
ulong len = nbytes;
#endif
static const char hexdigits[] = "0123456789abcdef";
QString s;
for ( int i=0; i<(int)len; i++ ) {
if ( (i%14) == 0 ) {
s += "\n ";
out << (const char*)s;
s.truncate( 0 );
}
uint v = (uchar)
#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
bazip
#else
input
#endif
[i];
s += "0x";
s += hexdigits[(v >> 4) & 15];
s += hexdigits[v & 15];
if ( i < (int)len-1 )
s += ',';
}
if ( s.length() )
out << (const char*)s;
return len;
}
开发者ID:OS2World,项目名称:LIB-QT3_Toolkit_Vbox,代码行数:33,代码来源:embed.cpp
示例11: warn
bool OctreePacketData::compressContent() {
PerformanceWarning warn(false, "OctreePacketData::compressContent()", false, &_compressContentTime, &_compressContentCalls);
// without compression, we always pass...
if (!_enableCompression) {
return true;
}
_bytesInUseLastCheck = _bytesInUse;
bool success = false;
const int MAX_COMPRESSION = 9;
// we only want to compress the data payload, not the message header
const uchar* uncompressedData = &_uncompressed[0];
int uncompressedSize = _bytesInUse;
QByteArray compressedData = qCompress(uncompressedData, uncompressedSize, MAX_COMPRESSION);
if (compressedData.size() < (int)MAX_OCTREE_PACKET_DATA_SIZE) {
_compressedBytes = compressedData.size();
for (int i = 0; i < _compressedBytes; i++) {
_compressed[i] = compressedData[i];
}
_dirty = false;
success = true;
}
return success;
}
开发者ID:Giugiogia,项目名称:hifi,代码行数:29,代码来源:OctreePacketData.cpp
示例12: out
void Buddha::saveScreenshot ( QString fileName ) {
QImage out( (uchar*) RGBImage, w, h, QImage::Format_RGB32 );
out.save( fileName, "PNG" );
QByteArray compress = qCompress( (const uchar*) RGBImage, w * h * sizeof(int), 9 );
cout << "Compressed size vs Full: " << compress.size() << " " << w * h * sizeof(int) << endl;
}
开发者ID:ker2x,项目名称:WinbuddhaVS,代码行数:7,代码来源:buddha.cpp
示例13: ds
bool TSessionRedisStore::store(TSession &session)
{
QByteArray data;
QDataStream ds(&data, QIODevice::WriteOnly);
ds << *static_cast<const QVariantMap *>(&session);
data = qCompress(data, 1).toBase64();
#ifndef TF_NO_DEBUG
{
QByteArray badummy;
QDataStream dsdmy(&badummy, QIODevice::ReadWrite);
dsdmy << *static_cast<const QVariantMap *>(&session);
TSession dummy;
dsdmy.device()->seek(0);
dsdmy >> *static_cast<QVariantMap *>(&dummy);
if (dsdmy.status() != QDataStream::Ok) {
tSystemError("Failed to store a session into the cookie store. Must set objects that can be serialized.");
}
}
#endif
TRedis redis;
tSystemDebug("TSessionRedisStore::store id:%s", session.id().data());
return redis.setEx('_' + session.id(), data, lifeTimeSecs());
}
开发者ID:foundations,项目名称:treefrog-framework,代码行数:26,代码来源:tsessionredisstore.cpp
示例14: writeVector
void writeVector(QDataStream& out, char ch, QVector<T> vec) {
// Minimum number of bytes to consider compressing
const int ATTEMPT_COMPRESSION_THRESHOLD_BYTES = 2000;
out.device()->write(&ch, 1);
out << (int32_t)vec.length();
auto data { QByteArray::fromRawData((const char*)vec.constData(), vec.length() * sizeof(T)) };
if (data.size() >= ATTEMPT_COMPRESSION_THRESHOLD_BYTES) {
auto compressedDataWithLength { qCompress(data) };
// qCompress packs a length uint32 at the beginning of the buffer, but the FBX format
// does not expect it. This removes it.
auto compressedData = QByteArray::fromRawData(
compressedDataWithLength.constData() + sizeof(uint32_t), compressedDataWithLength.size() - sizeof(uint32_t));
if (compressedData.size() < data.size()) {
out << FBX_PROPERTY_COMPRESSED_FLAG;
out << (int32_t)compressedData.size();
out.writeRawData(compressedData.constData(), compressedData.size());
return;
}
}
out << FBX_PROPERTY_UNCOMPRESSED_FLAG;
out << (int32_t)0;
out.writeRawData(data.constData(), data.size());
}
开发者ID:AndrewMeadows,项目名称:hifi,代码行数:29,代码来源:FBXWriter.cpp
示例15: 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
示例16: qDebug
bool FileManager::serialize(Serialize *serializable, const QString &path)
{
this->setFilePath(path);
if(!this->fileRemove())
{
qDebug("Could not remove the old found file");
return false;
}
this->setFilePath(path);
if(!this->fileOpen(QIODevice::WriteOnly))
{
qDebug("File could not be opened in write only mode.");
return false;
}
QDataStream stream(this->refFile());
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QBuffer::ReadWrite);
serializable->serialize(&buffer);
stream << qCompress(bytes,7);
serializable->setFileInfo(path);
return this->fileClose();
}
开发者ID:Ryoga-Unryu,项目名称:pidgirl-engine,代码行数:30,代码来源:FileManager.cpp
示例17: nameWithExtension
bool DataFile::writeFile( const QString& filename )
{
const QString fullName = nameWithExtension( filename );
const QString fullNameTemp = fullName + ".new";
const QString fullNameBak = fullName + ".bak";
QFile outfile( fullNameTemp );
if( !outfile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
if( Engine::hasGUI() )
{
QMessageBox::critical( NULL,
SongEditor::tr( "Could not write file" ),
SongEditor::tr( "Could not open %1 for writing. You probably are not permitted to "
"write to this file. Please make sure you have write-access to "
"the file and try again." ).arg( fullName ) );
}
return false;
}
if( fullName.section( '.', -1 ) == "mmpz" )
{
QString xml;
QTextStream ts( &xml );
write( ts );
outfile.write( qCompress( xml.toUtf8() ) );
}
else
{
QTextStream ts( &outfile );
write( ts );
}
outfile.close();
// make sure the file has been written correctly
if( QFileInfo( outfile.fileName() ).size() > 0 )
{
if( ConfigManager::inst()->value( "app", "disablebackup" ).toInt() )
{
// remove current file
QFile::remove( fullName );
}
else
{
// remove old backup file
QFile::remove( fullNameBak );
// move current file to backup file
QFile::rename( fullName, fullNameBak );
}
// move temporary file to current file
QFile::rename( fullNameTemp, fullName );
return true;
}
return false;
}
开发者ID:Skyh13,项目名称:lmms,代码行数:60,代码来源:DataFile.cpp
示例18: enet_simple_compress
// 返回压缩后的大小
static size_t enet_simple_compress(void * context, const ENetBuffer * inBuffers, size_t inBufferCount,
size_t inLimit, enet_uint8 * outData, size_t outLimit)
{
// return 0;
if (inLimit < 200) return 0;
qDebug()<<inBufferCount<<inLimit<<outLimit;
size_t cpsz = 0;
QByteArray inbuf;
size_t inlen = 0;
for (int i = 0; i < inBufferCount; i ++) {
const ENetBuffer *buffer = &inBuffers[i];
if (inlen + buffer->dataLength > inLimit) {
break;
}
inlen += buffer->dataLength;
inbuf.append((const char*)buffer->data, buffer->dataLength);
}
QByteArray outbuf = qCompress(inbuf, 7);
memcpy(outData, outbuf.data(), outbuf.length());
if (outbuf.length() > outLimit) {
qDebug()<<"invlid compress:"<<outbuf.length()<<outLimit<<inlen;
return 0;
}
return outbuf.length();
return 0;
}
开发者ID:kitech,项目名称:toxsh,代码行数:31,代码来源:toxtunbase.cpp
示例19: QString
void MainWindow::on_streamButton_clicked()
{
if (QFile::exists(ui->fileEdit->text()) != true)
{
QMessageBox::critical(this, "Critical", QString(FILE_NOT_FOUND).arg(ui->fileEdit->text()));
return;
}
QFile *file = new QFile(ui->fileEdit->text());
if (!file->open(QIODevice::ReadOnly))
{
delete file;
QMessageBox::critical(this, "Critical", QString(CANT_OPEN_TO_READ).arg(ui->fileEdit->text()));
return;
}
if (file->size() == 0)
{
file->close();
delete file;
QMessageBox::critical(this, "Critical", QString(FILE_IS_EMPTY).arg(ui->fileEdit->text()));
}
QByteArray *data = new QByteArray();
*data = file->readAll();
file->close();
delete file;
QByteArray *data_compressed = new QByteArray();
*data_compressed = qCompress(*data).remove(0, 4);
int size = data->size();
int size_compressed = data_compressed->size();
if(size_compressed < size) {
delete data;
data = data_compressed;
}
else {
delete data_compressed;
size_compressed = size;
}
QByteArray *args = new QByteArray();
//*args = ui->argEdit->text().toAscii(); //toAscii() has been depreciated in qt5
*args = ui->argEdit->text().toLatin1(); //toAscii() has been replaced by toLatin1()
int args_len = 0;
if(!args->isEmpty())
args_len = args->size() + 1;
ui->progressBar->setMaximum(size_compressed);
ui->progressBar->setEnabled(true);
wiiStreamThread = new QWiiStreamThread(ui->hostEdit->text(), data, size, size_compressed, args, args_len);
connect(wiiStreamThread, SIGNAL(transferFail(QString)), this, SLOT(transferFail(QString)));
connect(wiiStreamThread, SIGNAL(transferDone()), this, SLOT(transferDone()));
connect(wiiStreamThread, SIGNAL(progressBarPosition(int)), this, SLOT(progressBarPosition(int)));
wiiStreamThread->start();
ui->streamButton->setEnabled(false);
}
开发者ID:fkmclane,项目名称:WiiTCPLoad,代码行数:59,代码来源:mainwindow.cpp
示例20: SDPASSERT
int DatabaseManager::commitDetection(DetectionJob* job) {
SDPASSERT(Logger::instancePtr());
int newID = -1;
if ( !__db.isOpen() ) {
Logger::instancePtr()->addMessage(Logger::CRITICAL, __func__,
QString("Failed to store detection job %1. Database couldn't be opened.")
.arg(job->id()));
return newID;
}
QByteArray buffer;
QDataStream stream(&buffer, QIODevice::WriteOnly);
#if (QT_VERSION >= QT_VERSION_CHECK(4, 8, 0))
stream.setVersion(QDataStream::Qt_4_8);
#else
stream.setVersion(QDataStream::Qt_4_6);
#endif
job->toDataStream(stream);
QSqlQuery query;
if ( detectionExists(job->id()) ) {
query.prepare("UPDATE main.Detection SET return_code=:jretcode, "
"data=:jdata WHERE id = :jid");
query.bindValue("jretcode", job->runExitCode());
query.bindValue("jdata", qCompress(buffer));
query.bindValue("jid", job->id());
}
else {
query.prepare("INSERT INTO main.Detection (id, return_code, data) "
"VALUES (:jid, :jretcode, :jdata)");
query.bindValue("jid", job->id());
query.bindValue("jretcode", job->runExitCode());
query.bindValue("jdata", qCompress(buffer));
}
if ( query.exec() )
newID = query.lastInsertId().toInt();
else
Logger::instancePtr()->addMessage(Logger::CRITICAL, __func__,
QString("Query failed: %1").arg(query.executedQuery()));
return newID;
}
开发者ID:ovsm-dev,项目名称:sdp,代码行数:46,代码来源:databasemanager.cpp
注:本文中的qCompress函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论