나는이 질문은 옛 것을 알고 있지만, 답이 유지 방법 요즘, 나는 그것이 가능한 대답을 적절 생각까지 문제가 지속.
당신은 docs에 따르면
void QtServiceBase::createApplication (int & argc, char ** argv)
를 재 구현하여 Qt는 서비스의 시작 매개 변수를 얻을 수있을 것입니다 :
This function is only called when no service specific arguments were passed to the service constructor, and is called by exec() before it calls the executeApplication() and start() functions.
서비스가 시작 함수를 호출 할 때 그래서 인수는 사용할 수
,
createApplication
이
start
함수보다 먼저 호출되기 때문입니다. 여기
예 :
#include <QtCore>
#include "qtservice.h"
class Service : public QtService<QCoreApplication>
{
public:
explicit Service(int argc, char *argv[], const QString &name) : QtService<QCoreApplication>(argc, argv, name)
{
setServiceDescription("Service");
setServiceFlags(QtServiceBase::CanBeSuspended);
setStartupType(QtServiceController::ManualStartup);
}
protected:
void start()
{
// use args;
}
void stop()
{
}
void pause()
{
}
void resume()
{
}
void processCommand(int code)
{
}
void createApplication(int &argc, char **argv)
{
for (int i = 0; i < argc; i++)
args.append(QString(argv[i]));
QtService::createApplication(argc, argv);
}
private:
QStringList args;
};
int main(int argc, char *argv[])
{
Service s(argc, argv, "Service");
return s.exec();
}