8
votes

I'm currently reading the QML docs, and I realized that there is no explanation on how to define the app icon.

I tried something, but this doesn't work:

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);
    app.setWindowIcon(QIcon(":/favicon.ico"));

    QQmlApplicationEngine engine;
    engine.load(QUrl(QLatin1String("qrc:/main.qml")));

    return app.exec();
}

Can someone enlighten me? Thanks in advance:)

2
There is no portable way, for windows add win32:RC_ICONS += appicon.ico to your PRO file.dtech
Already done. I've also put my icon in the root folder..Francis-Olivier Couture
No this is diiferent, this is QML app, not C++Olivier RD

2 Answers

8
votes

For me it only worked when using a PNG instead of an ICO file. Also you might want to test it with a full path:

app.setWindowIcon(QIcon("C:/path_to_ico/favicon.png"));

Or directly - if it resides in your working dir:

app.setWindowIcon(QIcon("favicon.png"));

As soon as this works you can try to use a relative path or resource access again :-)

1
votes

Add the image to qrc file. Then give the path starting with :/.

app.setWindowIcon(QIcon(":/images/favicon.png"));

Qt version: 5.15.2

OS: Windows 10