android: avoid crash with failed font load

Check that we found font families before accessing them.
But the larger issue is likely that bundling the font failed.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-11-20 10:08:17 -08:00
parent e6804152e5
commit 4c3b6e6df2

View file

@ -67,13 +67,18 @@ void run_ui()
if (getAndroidHWInfo().contains("/OnePlus/")) {
QFontDatabase db;
int id = QFontDatabase::addApplicationFont(":/fonts/Roboto-Regular.ttf");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont newDefaultFont;
newDefaultFont.setFamily(family);
(static_cast<QApplication *>(QCoreApplication::instance()))->setFont(newDefaultFont);
qDebug() << "Detected OnePlus device, trying to force bundled font" << family;
QFont defaultFont = (static_cast<QApplication *>(QCoreApplication::instance()))->font();
qDebug() << "Qt reports default font is set as" << defaultFont.family();
QStringList fontFamilies = QFontDatabase::applicationFontFamilies(id);
if (fontFamilies.count() > 0) {
QString family = fontFamilies.at(0);
QFont newDefaultFont;
newDefaultFont.setFamily(family);
(static_cast<QApplication *>(QCoreApplication::instance()))->setFont(newDefaultFont);
qDebug() << "Detected OnePlus device, trying to force bundled font" << family;
QFont defaultFont = (static_cast<QApplication *>(QCoreApplication::instance()))->font();
qDebug() << "Qt reports default font is set as" << defaultFont.family();
} else {
qDebug() << "Detected OnePlus device, but can't determine font family used";
}
}
#endif
QScreen *appScreen = QApplication::screens().at(0);