Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Applicaton icon Qt5.2, Windows and Linux, QML

Applicaton icon Qt5.2, Windows and Linux, QML

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 5.3k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    anjwicks
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

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

      157

      1 Reply Last reply
      0
      • A Offline
        A Offline
        anjwicks
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          That's weird. Can you post complete contents of main.cpp ?
          Please use code tags '@@' for pasting the code here.

          157

          1 Reply Last reply
          0
          • A Offline
            A Offline
            anjwicks
            wrote on last edited by
            #5

            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!

            1 Reply Last reply
            0
            • A Offline
              A Offline
              anjwicks
              wrote on last edited by
              #6

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

              }@

              1 Reply Last reply
              0
              • p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #7

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

                157

                1 Reply Last reply
                0

                • Login

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