本文整理汇总了C++中QCache::object方法的典型用法代码示例。如果您正苦于以下问题:C++ QCache::object方法的具体用法?C++ QCache::object怎么用?C++ QCache::object使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QCache
的用法示例。
在下文中一共展示了QCache::object方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_file_icon
QIcon get_file_icon(const QString& content_type) {
static QCache<QString, QIcon> cache;
cache.setMaxCost(100);
if (cache.contains(content_type)) return QIcon(*(cache.object(content_type)));
QByteArray ba = content_type.toLocal8Bit();
GIcon* gicon = g_content_type_get_icon(ba.constData());
QStringList tried_names;
if (G_IS_THEMED_ICON(gicon)) {
const gchar * const * names = g_themed_icon_get_names(reinterpret_cast<GThemedIcon*>(gicon));
if (names != 0) {
int i = 0;
while(names[i] != 0) {
QString name = QString::fromLocal8Bit(names[i]);
QIcon r = QIcon::fromTheme(name);
if (r.isNull()) {
tried_names << name;
} else {
cache.insert(content_type, new QIcon(r));
g_object_unref(gicon);
return r;
}
i++;
}
} else {
qDebug() << "get_file_icon: empty or invalid result of g_themed_icon_get_names";
}
} else {
qDebug() << "get_file_icon: gicon is not themed icon";
}
qDebug() << "get_file_icon(" << content_type << "): no valid names" << tried_names << "; returning null icon";
cache.insert(content_type, new QIcon());
g_object_unref(gicon);
return QIcon();
}
示例2: axioms_on_key_type
void tst_QCache::axioms_on_key_type()
{
QCache<KeyType, ValueType> foo;
foo.setMaxCost(1);
foo.clear();
foo.insert(KeyType(123), new ValueType(123));
foo.object(KeyType(123));
foo.contains(KeyType(456));
foo[KeyType(456)];
foo.remove(KeyType(456));
foo.remove(KeyType(123));
foo.take(KeyType(789));
// If this fails, contact the maintaner
QVERIFY(sizeof(QHash<int, int>) == sizeof(void *));
}
示例3: sCode
QPixmap * getPixmapForCountryCode( const QString & countryCode )
{
if( countryCode.isEmpty() )
return NULL;
QString sCode( countryCode.toLower() );
QPixmap * pm = NULL;
pm = pPixmapCache->object(sCode);
if( !pm )
{
QString sFlag( KStandardDirs::locate("locale", sFlagTemplate.arg(sCode)) );
if( !sFlag.isEmpty() )
{
pm = new QPixmap(sFlag);
pPixmapCache->insert( sCode, pm );
}
}
return pm;
}