"Missing font family" warning on macOS
-
@f-kurushin with GnuPlot ?
-
same issue here!
this issue:qt.qpa.fonts: Populating font family aliases took 252 ms. Replace uses of missing font family "Sans" with one that exists to avoid this cost.
has been posted almost everywhere, e.g. at github, stakeoverflow, at octave and here at QT.
It said to have been solved at 5.15.2, but for me, 5.15.2 at macOS 10.15.6 not either.
please review. and find the root cause and help suggest a solution. thanks!
EDIT: one the solution I found is, set env e.g. at macOS: ~/.gnuplot ( for Windows is gnuplot.ini):
set term qt font "Arial 12"
then no complain.
-
I am regularly getting this error too, with PySide 6.1.2, and I'm not using Gnuplot. The only font my application refers to explicitly is "Helvetica Neue" which is present by default on any macOS Catalina system, including mine.
The error I get doesn't mention "Sans" but rather some mysterious "H", as in:
qt.qpa.fonts: Populating font family aliases took 253 ms. Replace uses of missing font family "H" with one that exists to avoid this cost.
EDIT: the mysterious "H" is definitely related to "Helvetica Neue" because when I changed the font in the app to Garamond, I got the same message with a (less mysterious) "G".
-
@JoeCFD Is there a way I can go through this search when the app starts? I tried calling QFont with the font name and assigning it to a dummy variable but it didn't change anything.
EDIT: Solved by actually assigning the font to something, as early as possible (such as in the
QApplication
constructor):self.setFont(QFont('Helvetica Neue'))
The message still appears but (1) it doesn't add a delay the first time a widget uses the font and (2) it pollutes the console as early as possible.
-
@Strangelove A better way to do it is to release your app with the font used. That will make sure it is available all the time.
-
Seems like this bug is back. From my Mac OS X Mojave computer using Qt 15.5.8
"qt.qpa.fonts: Populating font family aliases took 1268 ms. Replace uses of missing font family "Verdana" with one that exists to avoid this cost. "
How to overcome this?
@JoeCFD I am using Qt default fonts ... How to test/check what's going on ....
-
I'm getting the same error, running PySide/Qt 6.2.3 on macOS Mojave 10.14.6:
qt.qpa.fonts: Populating font family aliases took 2081 ms. Replace uses of missing font family ".SF NS Text" with one that exists to avoid this cost.
I've specified no styling or fonts, so this is just the default; thus San Francisco, the default system font on Mojave, is a perfectly plausible choice. The only question is why Qt isn't finding it.
-
I'm also getting it, really frustrating. On Monterey 12.2, Python version: 3.9.5, PySide6 version: 6.3.0
I'm explicitly adding a font local to my app to the QFontDatabase early in the apps run:
fontpath = os.path.abspath("resources/fonts/Futura-Light.otf") _id = QFontDatabase.addApplicationFont(fontpath)
Then, each time I need it I use:
font = QFontDatabase.font('Futura', "Light", con.searchBarFontSize)
I get:
qt.qpa.fonts: Populating font family aliases took 188 ms. Replace uses of missing font family "Futura" with one that exists to avoid this cost.
-
Hi, just tested with C++, I'm on Monterey 12.4 Xcode 13.4.1 and Qt 6.3.1. Downloaded Futura-Light.otf, created an empty widget app with a listwidget and tried this code at start (in mainwindow's constructor):
QFontDatabase::addApplicationFont("/Users/henry/Downloads/futura-light-opentype.otf"); auto font = QFontDatabase::font("Futura","Light",24); ui->listWidget->setFont(font);
and I get no error message (and the Futura Light font is visible in that listwidget).
Note that it's difficult to get that error "qt.qpa.fonts: Populating font family aliases to...." from a call to QFontDatabase::font (at least in C++) if I try
QFontDatabase::addApplicationFont("/Users/henry/Downloads/futura-light-opentype.otf"); auto font = QFontDatabase::font("Futurama","Light",24); ui->listWidget->setFont(font);
no Futura font shows up in my listwidget but also no error message
however if I try:QFontDatabase::addApplicationFont("/Users/henry/Downloads/futura-light-opentype.otf"); auto font = QFont("Futurama",24); ui->listWidget->setFont(font);
no Futura font shows up and now I get "Populating font family aliases took 215 ms. Replace uses of missing font family "Futurama" with one that exists to avoid this cost."
So perhaps your error message is due to some call to QFont(....) and not QFontDatabase.font?
-
@syr123 said in "Missing font family" warning on macOS:
I'm also getting it, really frustrating. On Monterey 12.2, Python version: 3.9.5, PySide6 version: 6.3.0
I'm explicitly adding a font local to my app to the QFontDatabase early in the apps run:
fontpath = os.path.abspath("resources/fonts/Futura-Light.otf")Using a relative path to the font file is very fragile. Calling abspath() will not help. It will be considered relative to the running executable current working directory. This directory is unlikely to be in the source tree and variable even if it sometimes is in the source tree, with the result that the font is not found, not added, and the fallback behaviour still exists.
-
Thank you both for taking a look. @hskoglund, I searched my whole project and have eliminated all calls to QFont(...). They're all:
font = QFontDatabase.font('Futura', "Light", 18)
@ChrisW67 - I moved my font initialization as early in the app as I can, immediately after the QApplication(sys.argv) call. I replaced the font path with an absolute path as well, so I'm fairly certain it's not an issue with path resolution.
Is there any way I can get Qt to print what line is triggering the "qt.qpa.fonts" warning?
-
You are asking for a font family "Futura" and the system is telling you it does not exist. The system scans the entire font database trying to find the non-existent family name, or something aliased to it. That takes some time and generates the warning.
Assuming it is loading correctly, the OpenType font you have manually loaded probably provides a font family name "Futura Light" (as this one does) and not "Futura". What happens if you use that family name?
On my Linux system an attempt to match "Futura" will return font "Futura Light" if there is no exact match. On MacOS the behaviour seems different.
$ fc-scan futura-light.otf Pattern has 24 elts (size 32) family: "Futura Light"(s) "Futura"(s) familylang: "en"(s) style: "Regular"(s) "Light"(s) stylelang: "en"(s) fullname: "Futura-Light"(s) "Futura Light"(s) fullnamelang: "en"(s) slant: 0(i)(s) weight: 50(f)(s) width: 100(f)(s) foundry: "adobe"(s) file: "futura-light.otf"(s) index: 0(i)(s) outline: True(s) scalable: True(s) charset: 0000: 00000000 ffffffff ffffffff 7fffffff 00000000 ffffdffe ffffffff ffffffff 0001: 00000000 00020000 000c0006 61000003 00040000 00000000 00000000 00000000 0002: 00000000 00000000 00000000 00000000 00000000 00000000 3f0000c0 00000000 0020: 77180000 06010047 00000010 00000000 00000000 00000000 00000000 00000000 0021: 00000000 00000004 00000000 00000000 00000000 00000000 00000000 00000000 0022: 00040000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00fb: 00000006 00000000 00000000 00000000 00000000 00000000 00000000 00000000 (s) lang: aa|ay|bi|br|ch|co|da|de|en|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gv|ho|ia|id|ie|io|is|it|lb|mg|nb|nds|nl|nn|no|nr|nso|oc|om|pt|rm|sma|smj|so|sq|ss|st|sv|sw|tl|tn|ts|uz|vo|vot|wa|xh|yap|zu|an|fil|ht|jv|kj|kwm|li|ms|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|za(s) fontversion: 65536(i)(s) capability: "otlayout:latn"(s) fontformat: "CFF"(s) decorative: False(s) postscriptname: "Futura-Light"(s) color: False(s) symbol: False(s) variable: False(s) $ fc-match Futura futura-light.otf: "Futura Light" "Regular"
Or from Qt 5 or 6:
#include <QApplication> #include <QFontDatabase> #include <QFont> #include <QDebug> int main(int argc, char **argv) { QApplication app(argc, argv); int fontId = QFontDatabase::addApplicationFont("./futura-light.otf"); qDebug() << fontId; #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QFontDatabase fd; QFont font = fd.font("Futura", "Light", 12); #else QFont font = QFontDatabase::font("Futura", "Light", 12); #endif qDebug() << font; return 0; }
0 QFont( "Futura,12,-1,5,25,0,0,0,0,0,Light" )
-
You say "You are asking for a font family "Futura" and the system is telling you it does not exist."
Part of the reason I am suspicious of this claim is that I've used the Glyphs app to modify the otf file, to add weight to each glyph of the font and change the appearance a bit. And, when I run my app, the labels using Futura Light do display with this modified font.
Additionally, QFontDatabase::addApplicationFont claims "The function returns -1 if the font could not be loaded." - when I inspect the return value of this function after adding my font with an absolute path, I see an ID of 0. So, it seems it is being correctly added to the QFontDatabase.
On your recommendation I tried replacing all my calls of:
font = QFontDatabase.font('Futura', "Light", 18)
with
font = QFontDatabase.font("Futura Light", "Futura", 18)
After doing so, I no longer got the qt.qpa..fonts error, but all my fonts were displayed a a small bold Helvetica like font.
This is what I get running fc-scan directly on my modified otf:
src/resources/fonts --> fc-scan Futura-Light.otf Pattern has 26 elts (size 32) family: "Futura"(s) "Futura Light"(s) familylang: "en"(s) "en"(s) style: "Light"(s) "Regular"(s) stylelang: "en"(s) "en"(s) fullname: "Futura Light"(s) fullnamelang: "en"(s) slant: 0(i)(s) weight: 50(f)(s) width: 100(f)(s) foundry: "ADBE"(s) file: "Futura-Light.otf"(s) index: 0(i)(s) outline: True(s) scalable: True(s) charset: 0000: 00000000 ffffffff ffffffff 7fffffff 00000000 ffffffff ffffffff ffffffff 0001: 00000000 00020000 000c0006 61000003 00040000 00000000 00000000 00000000 0002: 00000000 00000000 00000000 00000000 00000000 00000000 3f0002c0 00000000 0003: 00000000 00000000 00000000 00000000 00000000 10000000 00000000 00000000 0020: 77180000 06010047 00000010 00000000 00000000 00001000 00000000 00000000 0021: 00000000 00000004 00000000 00000000 00000000 00000000 00000000 00000000 0022: 02240000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00fb: 00000006 00000000 00000000 00000000 00000000 00000000 00000000 00000000 (s) lang: aa|ay|bi|br|ch|co|da|de|en|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gv|ho|ia|id|ie|io|is|it|lb|mg|nb|nds|nl|nn|no|nr|nso|oc|om|pt|rm|sma|smj|so|sq|ss|st|sv|sw|tl|tn|ts|uz|vo|vot|wa|xh|yap|zu|an|fil|ht|jv|kj|kwm|li|ms|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|za(s) fontversion: 65536(i)(s) capability: "otlayout:DFLT otlayout:latn"(s) fontformat: "CFF"(s) decorative: False(s) postscriptname: "Futura-Light"(s) color: False(s) symbol: False(s) variable: False(s) fonthashint: False(s) order: 0(i)(s)
Calls to get the font like this:
font = QFontDatabase.font("Futura", "Light", 120)
consistently display my labels as expected.
Further confusing me, the following very simple test successfully loads my custom font and gives no error:
def main(): app = QApplication(sys.argv) fontpath = "/Users/Shared/se3/src/se3/src/resources/fonts/Futura-Light.otf" _id = QFontDatabase.addApplicationFont(fontpath) font = QFontDatabase.font("Futura", "Light", 120) from PySide6.QtGui import QFont label = QLabel(alignment=Qt.AlignCenter) label.setFont(font) label.setText("test") label.resize(640, 480) label.show() sys.exit(app.exec()) if __name__ == "__main__": main()
I do not get the qt.qpa error.
This is why I was asking to know if there is any way to determine (in Python) which QFontDatabase.font database call in my much larger app was triggering the warning. I've searched the full source and don't see any calls to QFont or QFontDatabase that aren't in the form
font = QFontDatabase.font("Futura", "Light", 120)
Happy to try anything else you can think of, thanks for your help.