Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. setWindowIcon only works once?
Forum Update on Monday, May 27th 2025

setWindowIcon only works once?

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 3 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #6

    Can you show me how you are getting the object m_application ? Are you creating it ?

    Dheerendra
    @Community Service
    Certified Qt Specialist
    http://www.pthinks.com

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Slei
      wrote on last edited by Slei
      #7

      @dheerendra

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

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #8

        show me your main.cpp ?

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Slei
          wrote on last edited by Slei
          #9

          @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,
          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #10

            MyApp is inherited from QApplication ?

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Slei
              wrote on last edited by Slei
              #11

              @dheerendra
              no it just has a QApplication member and has similar member functions(like exec)

              MyApp.h
              std::unique_ptr<QApplication> m_application;

              1 Reply Last reply
              0
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by
                #12

                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
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Slei
                  wrote on last edited by Slei
                  #13

                  @dheerendra
                  I'm using QML instead of QWidget for the gui app, might there be any issue?

                  1 Reply Last reply
                  0
                  • dheerendraD Offline
                    dheerendraD Offline
                    dheerendra
                    Qt Champions 2022
                    wrote on last edited by dheerendra
                    #14

                    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.

                    Dheerendra
                    @Community Service
                    Certified Qt Specialist
                    http://www.pthinks.com

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Slei
                      wrote on last edited by
                      #15

                      Ok Its working now, the issue was indeed QML, now I'Ve just the QQuickWindow as base class for my QML window and use its seticon function on each window instead of using the QApplication setWindowicon

                      1 Reply Last reply
                      0
                      • dheerendraD Offline
                        dheerendraD Offline
                        dheerendra
                        Qt Champions 2022
                        wrote on last edited by
                        #16

                        That is good. You can move the issue to "Solved" state. Enjoy the Qt Programming.

                        Dheerendra
                        @Community Service
                        Certified Qt Specialist
                        http://www.pthinks.com

                        1 Reply Last reply
                        1

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved