Applicaton icon Qt5.2, Windows and Linux, QML
-
Hello!!
Very simple problem: I can not figure out how to change the application icon from default (the icon on the top left of the window).
From, http://qt-project.org/doc/qt-5/appicon.html, it seems I just need to call, "the QWindow::setWindowIcon() method". The code below is from main.cpp. QGuiApplication doesn't have a setWindowIcon(). I can't find any methods to set window icon.
I see RC_ICONS for qmake but we are using CMake...
@#include <QtQuick>
int main(int argc, char *argv[]){
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine(QUrl("qrc:/resources/qml/main.qml"));
return app.exec();
}@Please advise me how to set the applicaton icon in Qt5.2 (QML app).
Sincere thanks!
p.s. I'm sure this is covered in another post but I'm having problems searching posts for some reason.
-
Hi,
QGuiApplication has " setWindowIcon()":http://qt-project.org/doc/qt-5/qguiapplication.html#windowIcon-prop.
To use,
@
QGuiApplication app(argc, argv);
app.setWindowIcon(QIcon(QPixmap("/root/clover.png")));
@ -
Thank you so much for responding (rapidly)! I thought it would be something like that but adding the line of code, "app.setWindowIcon(QIcon(QPixmap("/root/clover.png")));"
is acting like QGuiApplication doesn't have a setWindowIcon method:
[ 76%] Built target isbuild
/home/jwicks/MCG/main.cpp: In function ‘int main(int, char**)’:
/home/jwicks/MCG/main.cpp:25:9: error: ‘class QGuiApplication’ has no member named ‘setWindowIcon'What the heck?!
Thank you sir.
jw -
That's weird. Can you post complete contents of main.cpp ?
Please use code tags '@@' for pasting the code here. -
Yes, this is it. Everything else is happening in main.qml.
@#include <QtQuick>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);QQmlApplicationEngine engine(QUrl("qrc:/resources/qml/main.qml")); return app.exec();
}@
I have an idea; I can try to grep Qt source code for setWindowIcon(). grepping...
Well, I found, "/opt/Qt5.2/5.2.1/gcc_64/include/QtWidgets/qapplication.h: static void setWindowIcon(const QIcon &icon);
"Since it's static, I did:
QApplication::setWindowIcon(QIcon(QPixmap("/images/image.ico")));I don't see the icon yet though... Am I calling it correctly?
Thanks again!
-
UPDATE: I tried something else but still not working. Note, I'm using Linux ~ maybe that has something to do with it?
@#include <QtQuick>
#include <QApplication>int main(int argc, char *argv[])
{
QApplication app(argc, argv);app.setWindowIcon(QIcon(":/resources/images/new_blue.png")); QQmlApplicationEngine engine(QUrl("qrc:/resources/qml/main.qml")); return app.exec();
}@
-
Is it giving any error now or it is not just displaying icon ?
Instead of loading from resource try it from a fixed path.
For e.g
@
app.setWindowIcon(QIcon("/root/new_blue.png"));
@