I'm using QSystemTrayIcon to display notification in Windows 10. Along with the notification, the application name is also displayed. The problem here is the app name is displayed along with the extension(.exe).
How can the extension(.exe) be removed from the notification?
Try adding this line to your .pro
file:
QMAKE_TARGET_DESCRIPTION = "Whatever"
It should change the process name (both in the notifications and in the task manager) to "Whatever".
More variables like this can be found here: Qmake Variables Documentation
Note from the documentation:
This is only utilized if the
VERSION
orRC_ICONS
variable is set and theRC_FILE
andRES_FILE
variables are not set.
Create Qt Widgets Application project, containing a QWidget
based widget
Create images
directory in the project folder, put an icon file into it (for this example let it be icon.ico
)
Add a resource file to the project
To that resource file add prefix /
, then "Add Files", selecting ./images/icon.ico
In main.cpp
change the code to following:
#include "widget.h"
#include <QApplication>
#include <QIcon>
int main(int argc, char *argv[])
{
QCoreApplication::setApplicationName(APP_NAME);
QApplication a(argc, argv);
a.setWindowIcon(QIcon(":/images/icon.ico"));
Widget w;
w.setWindowTitle(qApp->applicationName());
w.setWindowIcon(qApp->windowIcon());
w.show();
return a.exec();
}
widget.cpp
change code to following: #include "widget.h"
#include "ui_widget.h"
#include <QSystemTrayIcon>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(qApp->windowIcon(), this);
trayIcon->show();
connect(trayIcon, &QSystemTrayIcon::activated, [=]() {
trayIcon->showMessage("Title", "Message");
});
}
Widget::~Widget()
{
delete ui;
}
.pro
) file add following: DEFINES += APP_NAME=\\\"AppName\\\"
QMAKE_TARGET_DESCRIPTION = "Whatever"
win32:RC_ICONS += images/icon.ico
Save, run qmake (Build -> Run qmake), rebuild project
Start the application. Now the window title should be "AppName", which came from APP_NAME define, both window and tray icon - icon.ico, and the process name in task manager and notifications - "Whatever". You can make the app display a notification by clicking on the tray icon. Notification should look like this: