user1835297
user1835297

Reputation: 1107

Cannot Add an Icon to QML Desktop Application

I'm writing a QML Desktop Application in QtCreator and c++(on Win7).

In my main.cpp, I have loaded the application like this:

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QDeclarativeView view;
    view.setWindowFlags(Qt::Window | Qt::MSWindowsFixedSizeDialogHint);
    view.setSource(QUrl("qrc:/qml/GenericHostApplicationQML/myMain.qml"));
    view.show();
    menu->load();
    return app.exec();
}

and now I want to add an Icon to my application window, so I tried this:

view.setWindowIcon(QIcon("qrc:/qml/GenericHostApplicationQML/content/pics/TXE.ico"));

and I'm not getting any error, but while I'm running it, the window has the regular .exe file icon, and not the wanted one. I tried changing the picture, but it didn't solve the problem.

Upvotes: 1

Views: 3997

Answers (2)

Pragalathan  M
Pragalathan M

Reputation: 1781

In QT 6, add the png file to the qml.qrc file as below.

<file>app.png</file>

Then in c++ add this,

QGuiApplication app(argc, argv);
app.setWindowIcon(QIcon(QStringLiteral(":app.png")));

Upvotes: 0

TheHuge_
TheHuge_

Reputation: 1039

Here's the documentation about how to set your Desktop Qt Application icon.

Edit: Also, for the window icon you're setting, be sure that referred image file is actually listed in your application resources (see this).

Upvotes: 1

Related Questions