Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
QtService: Added a display name
This is for Windows services. I have no idea how or if it should be used
under unix.
  • Loading branch information
HazardyKnusperkeks committed May 2, 2020
commit c6197e1434c356ba2e4d0af4ab61129120b4da66
21 changes: 21 additions & 0 deletions qtservice/src/qtservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,27 @@ QString QtServiceBase::serviceName() const
return d_ptr->controller.serviceName();
}

/*!
Returns the optional display name of the service.

\sa setDisplayName(), serviceName()
*/
QString QtServiceBase::displayName() const
{
return d_ptr->displayName;
}

/*!
Sets the optional display name of the service. If left empty the display
name is equal to the service name.

\sa displayName(), serviceName()
*/
void QtServiceBase::setDisplayName(const QString &displayName)
{
d_ptr->displayName = displayName;
}

/*!
Returns the description of the service.

Expand Down
3 changes: 3 additions & 0 deletions qtservice/src/qtservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class QT_QTSERVICE_EXPORT QtServiceBase

QString serviceName() const;

QString displayName() const;
void setDisplayName(const QString &displayName);

QString serviceDescription() const;
void setServiceDescription(const QString &description);

Expand Down
1 change: 1 addition & 0 deletions qtservice/src/qtservice_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class QtServiceBasePrivate

QtServiceBase *q_ptr;

QString displayName;
QString serviceDescription;
QtServiceController::StartupType startupType;
QtServiceBase::ServiceFlags serviceFlags;
Expand Down
3 changes: 2 additions & 1 deletion qtservice/src/qtservice_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ bool QtServiceBasePrivate::install(const QString &account, const QString &passwo
SC_HANDLE hSCM = pOpenSCManager(0, 0, SC_MANAGER_ALL_ACCESS);
if (hSCM) {
QString acc = account;
QString dis = displayName.isEmpty() ? controller.serviceName() : displayName;
DWORD dwStartType = startupType == QtServiceController::AutoStartup ? SERVICE_AUTO_START : SERVICE_DEMAND_START;
DWORD dwServiceType = SERVICE_WIN32_OWN_PROCESS;
wchar_t *act = 0;
Expand All @@ -884,7 +885,7 @@ bool QtServiceBasePrivate::install(const QString &account, const QString &passwo

// Create the service
SC_HANDLE hService = pCreateService(hSCM, (wchar_t *)controller.serviceName().utf16(),
(wchar_t *)controller.serviceName().utf16(),
(wchar_t *)dis.utf16(),
SERVICE_ALL_ACCESS,
dwServiceType, // QObject::inherits ( const char * className ) for no inter active ????
dwStartType, SERVICE_ERROR_NORMAL, (wchar_t *)filePath().utf16(),
Expand Down