QFontDatabase: Cannot find font directory qt5

按照提示,在Qt库安装目录中 lib文件夹下新建个fonts文件夹,把字体拷贝进去就行。

QString fontPath = ":/fonts/MyFont.ttf";
int fontId = QFontDatabase::addApplicationFont(fontPath);
if (fontId != -1)
{
    QFont font("MyFont");
    app.setFont(font);
}