setWindowIcon only works once?
-
Hi,
Please you show the code you are using for that.
Also:- What version of Qt are you using ?
- On what platform ?
-
Are you using the same icon variable for
setWindowIcon
then for the system tray ?You omitted to answer two questions.
-
Can you show me how you are getting the object m_application ? Are you creating it ?
-
I'm creating the object my self in an custom object which is created in the main.cpp:
``
MyApp.h
std::unique_ptr<QApplication> m_application;MyApp.cpp
m_application = std::make_unique<QApplication>(argc,
argv); -
show me your main.cpp ?
-
@dheerendra ```
int main(int argc, char *argv[])
{
MyApp a(argc, argv);
MainWindow w;
w.show();//this just uses the QApplication exec
return a.exec();
}In generall i'm actually using the MyApp just as it would be a QApplication directly nothing special,
-
MyApp is inherited from QApplication ?
-
@dheerendra
no it just has a QApplication member and has similar member functions(like exec)MyApp.h
std::unique_ptr<QApplication> m_application; -
My suspect was you have two different instances of QApplication and could be causing the issue. Looks like this is not issue.
I tried on Windows & Mac. It works without any issue. Can you try the following sample?
void MyWidget::on_pushButton_clicked()
{
qDebug() << Q_FUNC_INFO << endl;
qApp->setWindowIcon(QIcon(":/Phone_1.jpg"));
}void MyWidget::on_pushButton_2_clicked()
{
qDebug() << Q_FUNC_INFO << endl;
qApp->setWindowIcon(QIcon(":/RightOption.png"));
}
==========main.cpp =========QApplication a(argc, argv); a.setWindowIcon(QIcon(":/Air.png")); MyWidget w; w.show();
-
@dheerendra
I'm using QML instead of QWidget for the gui app, might there be any issue? -
Yes. it is issue with QML application. It is bug. It should work the same way. Issue is coming from application object. Instead of using the application object to change with window icon, we can use the top-level window object & use the setIcon(...) method to set it. It should work.
-
That is good. You can move the issue to "Solved" state. Enjoy the Qt Programming.