本文整理汇总了C++中QVariant::asByteArray方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::asByteArray方法的具体用法?C++ QVariant::asByteArray怎么用?C++ QVariant::asByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::asByteArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveProperty
void saveProperty( QListView *lv, KTNEFPropertySet *pSet, QWidget *parent )
{
QListViewItem *item = lv->selectedItem();
if ( !item )
KMessageBox::error( parent, i18n( "Select an item." ) );
else if ( item->text( 2 ).isEmpty() )
KMessageBox::error( parent, i18n( "The selected item cannot be saved." ) );
else
{
QString tag = item->text( 2 );
int key = tag.mid( 5 ).toInt();
QVariant prop = ( tag.startsWith( "attr_" ) ? pSet->attribute( key ) : pSet->property( key ) );
QString filename = KFileDialog::getSaveFileName( tag, QString::null, parent );
if ( !filename.isEmpty() )
{
QFile f( filename );
if ( f.open( IO_WriteOnly ) )
{
switch ( prop.type() )
{
case QVariant::ByteArray:
f.writeBlock( prop.asByteArray().data(), prop.asByteArray().size() );
break;
default:
{
QTextStream t( &f );
t << prop.toString();
break;
}
}
f.close();
}
else
KMessageBox::error( parent, i18n( "Unable to open file for writing, check file permissions." ) );
}
}
}
示例2: getPref
uint64_t XMLPreferences::getPrefUInt64(const QString& inName,
const QString& inSection,
uint64_t def,
Persistence pers)
{
// try to retrieve the preference
QVariant* preference = getPref(inName, inSection, pers);
// if preference was retrieved, return it as a string
if (preference != NULL)
{
uint64_t value = def;
switch(preference->type())
{
case QVariant::String:
// convert it to a uint64_t (in base 16)
value = strtoull(preference->toString(), 0, 16);
break;
case QVariant::Int:
case QVariant::UInt:
value = preference->toInt();
break;
case QVariant::Double:
value = uint64_t(preference->toDouble());
break;
case QVariant::ByteArray:
{
QByteArray& ba = preference->asByteArray();
if (ba.size() == sizeof(uint64_t))
value = *(uint64_t*)ba.data();
break;
}
default:
qWarning("XMLPreferences::getPrefUInt64(%s, %s, %llu): preference found,\n"
"\tbut type %s is not convertable to type uint64_t!",
(const char*)inName, (const char*)inSection,
(unsigned long long)def,
preference->typeName());
}
// return the key
return value;
}
// return the default value
return def;
}