Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define a window icon for a QML application

Tags:

qt

qt5

qml

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:)

like image 221
Francis-Olivier Couture Avatar asked Jan 04 '17 18:01

Francis-Olivier Couture


1 Answers

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 :-)

like image 181
ToeBee Avatar answered Sep 17 '22 13:09

ToeBee