Skip to content

Commit

Permalink
Allow specifying the application name in configuration
Browse files Browse the repository at this point in the history
This is useful for QSettings and possibly other things. I also put the
name into the window title so it's easier to determine what's running in
which window.
  • Loading branch information
MartinBriza authored and patrickelectric committed Sep 8, 2023
1 parent a16c3c9 commit 66a5f09
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ To run qhot:
--profile-path Path (including filename) to qhot-profile.json (file)
--background Set the background color (color)
--quick-controls-conf Path (including filename) to qtquickcontrols2.conf (file)
--app-name Name of the application running inside qhot (name)
```

### Store options in a profile
Expand Down
2 changes: 1 addition & 1 deletion qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ProvidesSomething

ApplicationWindow {
id: window
title: "QHot"
title: Qt.application.name
visible: true

Shortcut {
Expand Down
8 changes: 8 additions & 0 deletions src/commandline/commandlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ void CommandLineParser::_parseQHotProfile(const QString& profilePath)
auto absPath = profileDir.absoluteFilePath(controlsConfPath.toString());
qputenv("QT_QUICK_CONTROLS_CONF", absPath.toLocal8Bit());
}

auto appName = jsonObject.value(QLatin1String { "app-name" });
if (appName.isString()) {
_posAppFunctions.append(
[appName]{
qApp->setApplicationName(APPNAME_FORMAT.arg(appName.toString()));
});
}
}

void CommandLineParser::_translate(const QString &translationFile)
Expand Down
6 changes: 6 additions & 0 deletions src/commandline/commandlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "../providessomething.h"

#define APPNAME_FORMAT QStringLiteral("qhot (%1)")

/**
* @brief Deal with command lines
*
Expand Down Expand Up @@ -108,5 +110,9 @@ class CommandLineParser : public QCommandLineParser {
{"quick-controls-conf", "Path (including filename) to qtquickcontrols2.conf", "file"},
[](const QString& path) { qputenv("QT_QUICK_CONTROLS_CONF", path.toLocal8Bit()); },
},
{
{"app-name", "Name of the application to set in QGuiApplication::setApplicationName", "name"},
[this](const QString& argument) { _posAppFunctions.append([argument]{ qApp->setApplicationName(APPNAME_FORMAT.arg(argument)); });},
},
};
};
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ int main(int argc, char *argv[])
{
qmlRegisterSingletonType<ProvidesSomething>("ProvidesSomething", 1, 0, "ProvidesSomething", ProvidesSomething::qmlSingletonRegister);

CommandLineParser commandLineParser(argc, argv);

QGuiApplication app(argc, argv);
app.setOrganizationDomain("patrickelectric.work");
app.setOrganizationName("patrickelectric");
CommandLineParser commandLineParser(argc, argv);
commandLineParser.setApplication(&app);

QQmlApplicationEngine appEngine;
Expand Down

0 comments on commit 66a5f09

Please sign in to comment.