Android: Don't rely on QIcon::isNull() to validate icon data.

QIcon::isNull() only checks if it has a valid d pointer and not if it
actually contains any image data. The result is that the QImage create
from the icon would be invalid, and later cause an exception to be
thrown. To avoid this we should check the QImage as well.

Task-number: QTBUG-34416
Change-Id: I9dd0a2387d73bfc2c27ceb9df247ddc186dd659f
Reviewed-by: BogDan Vatra <bogdan@kde.org>
This commit is contained in:
Christian Strømme 2013-10-29 15:06:34 +01:00 committed by The Qt Project
parent fb5036b7f1
commit b280182053

View File

@ -197,16 +197,18 @@ namespace QtAndroidMenu
env->CallObjectMethod(menuItem, setCheckedMenuItemMethodID, checked);
env->CallObjectMethod(menuItem, setEnabledMenuItemMethodID, enabled);
if (!icon.isNull()) {
if (!icon.isNull()) { // isNull() only checks the d pointer, not the actual image data.
int sz = qMax(36, qgetenv("QT_ANDROID_APP_ICON_SIZE").toInt());
QImage img = icon.pixmap(QSize(sz,sz),
enabled
? QIcon::Normal
: QIcon::Disabled,
QIcon::On).toImage();
env->CallObjectMethod(menuItem,
setIconMenuItemMethodID,
createBitmapDrawable(createBitmap(img, env), env));
if (!img.isNull()) { // Make sure we have a valid image.
env->CallObjectMethod(menuItem,
setIconMenuItemMethodID,
createBitmapDrawable(createBitmap(img, env), env));
}
}
env->CallObjectMethod(menuItem, setVisibleMenuItemMethodID, visible);