本文整理汇总了C++中QByteArray::toBase64方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::toBase64方法的具体用法?C++ QByteArray::toBase64怎么用?C++ QByteArray::toBase64使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::toBase64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: imageToHash
QString QgsRenderChecker::imageToHash( QString theImageFile )
{
QImage myImage;
myImage.load( theImageFile );
QByteArray myByteArray;
QBuffer myBuffer( &myByteArray );
myImage.save( &myBuffer, "PNG" );
QString myImageString = QString::fromUtf8( myByteArray.toBase64().data() );
QCryptographicHash myHash( QCryptographicHash::Md5 );
myHash.addData( myImageString.toUtf8() );
return myHash.result().toHex().constData();
}
示例2: toByteArray
QByteArray IconFactory::toByteArray(const QIcon &icon) {
QByteArray array;
QBuffer buffer(&array);
buffer.open(QIODevice::WriteOnly);
QDataStream out(&buffer);
out.setVersion(QDataStream::Qt_4_7);
out << icon;
buffer.close();
return array.toBase64();
}
示例3: generateKey
/*!
\internal
*/
QByteArray WebSocket::generateKey() const
{
QByteArray key;
for (int i = 0; i < 4; ++i)
{
quint32 tmp = generateRandomNumber();
key.append(static_cast<const char *>(static_cast<const void *>(&tmp)), sizeof(quint32));
}
return key.toBase64();
}
示例4: messageFromClient
void Server::messageFromClient(QByteArray message,QString client){
qDebug()<<ENCAPS(tr("[server] incoming"))<<message.toBase64()<<ENCAPS(tr("from"))<<client;
QString header;
QDataStream stream(message);
stream >> header;
qDebug()<<header;
if(0==header.compare("SET_VELOCITY")){
qDebug()<<ENCAPS(tr("Got velocity data!"));
int i;
stream >> i;
stream >> spaceObjects[client][i].velocity;
}
示例5: startAuthentication
bool LoginJobPrivate::startAuthentication()
{
//SASL authentication
if ( !initSASL() ) {
q->setError( LoginJob::UserDefinedError );
q->setErrorText( i18n( "Login failed, client cannot initialize the SASL library." ) );
return false;
}
authState = LoginJobPrivate::Authenticate;
const char *out = 0;
uint outlen = 0;
const char *mechusing = 0;
int result = sasl_client_new( "imap", m_session->hostName().toLatin1(), 0, 0, callbacks, 0, &conn );
if ( result != SASL_OK ) {
kDebug() << "sasl_client_new failed with:" << result;
q->setError( LoginJob::UserDefinedError );
q->setErrorText( QString::fromUtf8( sasl_errdetail( conn ) ) );
return false;
}
do {
result = sasl_client_start( conn, authMode.toLatin1(), &client_interact, capabilities.contains( "SASL-IR" ) ? &out : 0, &outlen, &mechusing );
if ( result == SASL_INTERACT ) {
if ( !sasl_interact() ) {
sasl_dispose( &conn );
q->setError( LoginJob::UserDefinedError ); //TODO: check up the actual error
return false;
}
}
} while ( result == SASL_INTERACT );
if ( result != SASL_CONTINUE && result != SASL_OK ) {
kDebug() << "sasl_client_start failed with:" << result;
q->setError( LoginJob::UserDefinedError );
q->setErrorText( QString::fromUtf8( sasl_errdetail( conn ) ) );
sasl_dispose( &conn );
return false;
}
QByteArray tmp = QByteArray::fromRawData( out, outlen );
QByteArray challenge = tmp.toBase64();
if ( challenge.isEmpty() ) {
tags << sessionInternal()->sendCommand( "AUTHENTICATE", authMode.toLatin1() );
} else {
tags << sessionInternal()->sendCommand( "AUTHENTICATE", authMode.toLatin1() + ' ' + challenge );
}
return true;
}
示例6: variantEncode
QVariant SettingsManager::variantEncode(const QVariant &v) const
{
if (v.type() == QVariant::ByteArray) {
QByteArray data = v.toByteArray();
data = data.toBase64();
return data;
}
else {
return v;
}
}
示例7: encrypt
//=============================================================================
//=============================================================================
QString Crypt::encrypt(QString str)
{
FUNC_DEBUG;
if (_key.isEmpty() || str.isEmpty()) { return QString(); }
QByteArray baEncrypt = str.toLatin1();
for (int i = 0; i < baEncrypt.count(); i++) {
baEncrypt[i] = baEncrypt.at(i) ^ _key.at(i % _key.size());
}
baEncrypt = qCompress(baEncrypt,9);
return QString(baEncrypt.toBase64());
}
示例8: calculateResponse
QByteArray QAuthenticatorPrivate::calculateResponse(const QByteArray &requestMethod, const QByteArray &path)
{
QByteArray response;
const char *methodString = 0;
switch(method) {
case QAuthenticatorPrivate::None:
methodString = "";
phase = Done;
break;
case QAuthenticatorPrivate::Plain:
response = '\0' + user.toUtf8() + '\0' + password.toUtf8();
phase = Done;
break;
case QAuthenticatorPrivate::Basic:
methodString = "Basic ";
response = user.toLatin1() + ':' + password.toLatin1();
response = response.toBase64();
phase = Done;
break;
case QAuthenticatorPrivate::Login:
if (challenge.contains("VXNlciBOYW1lAA==")) {
response = user.toUtf8().toBase64();
phase = Phase2;
} else if (challenge.contains("UGFzc3dvcmQA")) {
response = password.toUtf8().toBase64();
phase = Done;
}
break;
case QAuthenticatorPrivate::CramMd5:
break;
case QAuthenticatorPrivate::DigestMd5:
methodString = "Digest ";
response = digestMd5Response(challenge, requestMethod, path);
phase = Done;
break;
case QAuthenticatorPrivate::Ntlm:
methodString = "NTLM ";
if (challenge.isEmpty()) {
response = qNtlmPhase1().toBase64();
if (user.isEmpty())
phase = Done;
else
phase = Phase2;
} else {
response = qNtlmPhase3(this, QByteArray::fromBase64(challenge)).toBase64();
phase = Done;
}
break;
}
return QByteArray(methodString) + response;
}
示例9: createSecurityToken
// static
bool Sandbox::createSecurityToken(const QString& canonicalPath,
bool isDirectory) {
if (sDebug) {
qDebug() << "createSecurityToken" << canonicalPath << isDirectory;
}
if (!enabled()) {
return false;
}
QMutexLocker locker(&s_mutex);
if (s_pSandboxPermissions == NULL) {
return false;
}
#ifdef Q_OS_MAC
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
CFURLRef url = CFURLCreateWithFileSystemPath(
kCFAllocatorDefault, QStringToCFString(canonicalPath),
kCFURLPOSIXPathStyle, isDirectory);
if (url) {
CFErrorRef error = NULL;
CFDataRef bookmark = CFURLCreateBookmarkData(
kCFAllocatorDefault, url,
kCFURLBookmarkCreationWithSecurityScope, nil, nil, &error);
CFRelease(url);
if (bookmark) {
QByteArray bookmarkBA = QByteArray(
reinterpret_cast<const char*>(CFDataGetBytePtr(bookmark)),
CFDataGetLength(bookmark));
QString bookmarkBase64 = QString(bookmarkBA.toBase64());
s_pSandboxPermissions->set(keyForCanonicalPath(canonicalPath),
bookmarkBase64);
CFRelease(bookmark);
return true;
} else {
if (sDebug) {
qDebug() << "Failed to create security-scoped bookmark for" << canonicalPath;
if (error != NULL) {
qDebug() << "Error:" << CFStringToQString(CFErrorCopyDescription(error));
}
}
}
} else {
if (sDebug) {
qDebug() << "Failed to create security-scoped bookmark URL for" << canonicalPath;
}
}
#endif
#endif
return false;
}
示例10: messageFromServer
void ClientWidget::messageFromServer(QByteArray message){
qDebug()<<ENCAPS(tr("incoming"))<<message.toBase64();
QString header;
QDataStream stream(message);
stream >> header;
qDebug()<<header;
if(0==header.compare("SIMULATION_UPDATE_DATA")){
qDebug()<<ENCAPS(tr("Got simulation data!"));
int size,i;
stream >> size;
stream >> i;
stream >> me;
}
示例11: write
QString BaseStateAbstract::write(QString val, bool compress)
{
QString ret;
QByteArray data = val.toUtf8();
if (compress)
data = qCompress(data,9).toBase64().prepend(COMPRESSED_MARKER); // prepending # to signify the string is compressed
else
data = data.toBase64();
ret = QString::fromUtf8(data.constData(), data.size());
return ret;
}
示例12: serialiseLeaves
void unitFaceModel::serialiseLeaves(const QList<QList<QList<int> > >& allLeaves)
{
QByteArray byteArray;
QBuffer writeBuffer(&byteArray);
writeBuffer.open(QIODevice::WriteOnly);
QDataStream out(&writeBuffer);
out << allLeaves;
writeBuffer.close();
serialisedLeaves = QString(byteArray.toBase64());
}
示例13: serializeItems
QString RecentItemsModel::serializeItems() {
// historical reasons to have QQueue here
// now only thing left is to be backward compatible
QQueue<QString> items;
for (auto &kv: m_LRUcache.data()) {
items.enqueue(kv.first);
}
Q_ASSERT(m_LRUcache.size() <= m_MaxRecentItems);
QByteArray raw;
QDataStream ds(&raw, QIODevice::WriteOnly);
ds << items;
return QString::fromLatin1(raw.toBase64());
}
示例14:
QByteArray AuthHelper::encodeBasicB64Auth( const QString& aUsername, const QString& aPassword ) const
{
FUNCTION_CALL_TRACE;
QByteArray in;
in.append( aUsername );
in.append( ':' );
in.append( aPassword );
return in.toBase64();
}
示例15: saveState
void TorrentActivity::saveState(KSharedConfigPtr cfg)
{
search_bar->saveState(cfg);
group_view->saveState(cfg);
group_switcher->saveState(cfg);
qm->saveState(cfg);
tool_views->saveState(cfg, "TorrentActivityBottomTabBar");
magnet_view->saveState(cfg);
KConfigGroup g = cfg->group("TorrentActivitySplitters");
if (vsplit)
{
QByteArray data = vsplit->saveState();
g.writeEntry("vsplit", data.toBase64());
}
if (hsplit)
{
QByteArray data = hsplit->saveState();
g.writeEntry("hsplit", data.toBase64());
}
}