How to set MainWindow Icon using CMAKELists.txt and QT6

  Kiến thức lập trình

I am trying to set the MainWindow icon using QT6.

My main.cpp has this:

QApplication a(argc, argv);
QIcon icon(":/Icons/web/favicon.ico");
a.setWindowIcon(icon);

My CMakeLists.txt automatically added this when I added a directory:

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(MacroPilot
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        oldFunctions.txt
        Icons/android/mipmap-hdpi/ic_launcher.png Icons/android/mipmap-hdpi/ic_launcher_foreground.png Icons/android/mipmap-hdpi/ic_launcher_round.png Icons/android/mipmap-mdpi/ic_launcher.png Icons/android/mipmap-mdpi/ic_launcher_foreground.png Icons/android/mipmap-mdpi/ic_launcher_round.png Icons/android/mipmap-xhdpi/ic_launcher.png Icons/android/mipmap-xhdpi/ic_launcher_foreground.png Icons/android/mipmap-xhdpi/ic_launcher_round.png Icons/android/mipmap-xxhdpi/_/web/ms-application.png Icons/android/mipmap-xxhdpi/ic_launcher.png Icons/android/mipmap-xxhdpi/ic_launcher_foreground.png Icons/android/mipmap-xxhdpi/ic_launcher_round.png Icons/android/mipmap-xxxhdpi/ic_launcher_foreground.png Icons/android/mipmap-xxxhdpi/ic_launcher_round.png Icons/android/mipmap-xxxhdpi/Iic_launcher.png Icons/android/playstore-icon.png Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/AppIcons/[email protected] Icons/ios/appstore.png Icons/ios/[email protected] Icons/ios/[email protected] Icons/ios/[email protected] Icons/web/android-chrome-192x192.png Icons/web/android-chrome-512x512.png Icons/web/apple-touch-icon.png Icons/web/favicon-16x16.png Icons/web/favicon-32x32.png Icons/web/favicon.ico Icons/web/site.webmanifest
    )

My file structure is:

LEAVE A COMMENT