I want to change the title of my Qt 5.15.0 application after it was executed.
For doing that, I'm using the setWindowTitle function of the QWidget class, like so:
setWindowTitle("My new window title");
Turns out the title is changed correctly on Windows but not on macOS. Here are the results:
Windows 10
macOS Catalina
You can see that in macOS the title is updated in the Window but not in the MenuBar (top) and in the Dock (bottom).
Is there a way to change all the titles on macOS once the app is running?
Edit
I managed to change the MenuBar title using the Objective-C code posted in this question (I just had to rename my .cpp file to .mm):
#import <AppKit/NSApplication.h>
#import <AppKit/NSMenu.h>
void setMenuProgramName(const char* newName)
{
NSMenu* mainMenu = [[NSApplication sharedApplication] mainMenu];
NSMenu* appMenu = [[mainMenu itemAtIndex:0] submenu];
[appMenu setTitle:[[NSString alloc] initWithUTF8String:newName]];
}
There's still the problem with changing the name in the Dock. There are some insights here and here but I couldn't make it work yet. It is said that I should "comment out NSApplicationMain in supporting files -> main.m" but I don't have that file and I don't know how could I do that using Qt. That's why I propose that the question be reopened since there's no solution for that yet.
Edit II
Apparently, as mentioned in this response, there's no way to change the title when you hover over the app icon in the Dock.
Alternatively, you can add a "badge" with the following code, but that's meant for notifications.
[[NSApp dockTile] setBadgeLabel:@"My custom text"]
It would be nice to know why this can't be changed - if it's because of a bad design decision or just a poorly developed framework.