Reputation: 1107
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
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