I've been trying to get a custom icon I created to display in the top left corner of a Qt application I've been writing, and no matter what I try, I cannot get it to display. It will only display the default icon no matter what I do. I created a test app to try and just get it to work without doing it in my app, but even that won't work.
I can get it to display the same icon within a window with QPixmap, so it's not a path issue.
I've even tried deleting the Makefile created by qmake and the .qmake.stash files and running
qmake test_icon.pro
qmake test_icon.pro
To copy to clipboard, switch view to plain text mode
again. But it still will not display my icon no matter what I try.
I would like to display the same icon in all windows of my Qt app, as well as the taskbar icon as well.
I'm new to programming with Qt, so I have no idea what I'm doing wrong.
I'm using Manjaro Linux with Qt5.
My main.cpp file:
#include <QApplication>
#include <QMainWindow>
#include <QIcon>
int main(int argc, char *argv[])
{
// Set the application icon using the resource path (:/myicon.png)
app.
setWindowIcon(QIcon(":/myicon.png"));
// Create main window (and any other windows)
mainWindow.setWindowTitle("My App");
mainWindow.show();
// Any other top-level windows you create will automatically use this icon
// unless you set a different icon on them individually using setWindowIcon()
// on the widget instance itself.
return app.exec();
}
#include <QApplication>
#include <QMainWindow>
#include <QIcon>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Set the application icon using the resource path (:/myicon.png)
app.setWindowIcon(QIcon(":/myicon.png"));
// Create main window (and any other windows)
QMainWindow mainWindow;
mainWindow.setWindowTitle("My App");
mainWindow.show();
// Any other top-level windows you create will automatically use this icon
// unless you set a different icon on them individually using setWindowIcon()
// on the widget instance itself.
return app.exec();
}
To copy to clipboard, switch view to plain text mode
My resources.qrc file:
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource prefix="/">
<file>myicon.png</file>
</qresource>
</RCC>
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource prefix="/">
<file>myicon.png</file>
</qresource>
</RCC>
To copy to clipboard, switch view to plain text mode
My test_icon.pro file:
######################################################################
# Automatically generated by qmake (3.1) Fri Jan 16 16:35:33 2026
######################################################################
TEMPLATE = app
TARGET = test_icon
QT += widgets
INCLUDEPATH += .
RESOURCES += resources.qrc
# You can make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# Please consult the documentation of the deprecated API in order to know
# how to port your code away from it.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# Input
SOURCES += main.cpp
######################################################################
# Automatically generated by qmake (3.1) Fri Jan 16 16:35:33 2026
######################################################################
TEMPLATE = app
TARGET = test_icon
QT += widgets
INCLUDEPATH += .
RESOURCES += resources.qrc
# You can make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# Please consult the documentation of the deprecated API in order to know
# how to port your code away from it.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# Input
SOURCES += main.cpp
To copy to clipboard, switch view to plain text mode
What in the f**king hell am I missing?? I don't understand what I'm doing wrong. I'm at my wits end with this.
Can someone please tell me what I'm doing wrong in plain simple english?
Thanks in advance for any help.
Bookmarks