obj= new MyObject();
delete obj
MyObject::MyObject(){ tmp = new QObject();}MyObject::~MyObject(){ delete tmp;}
MyObject::~MyObject(){ //delete tmp;}
MyObject::~MyObject(){ tmp->deleteLater();}
#include "MyService.h"MyLogServer *myLogServer;int main(int argc, char *argv[]){ MyService service(argc, argv, "My service", "Description"); return service.exec();}
void MyService::start(){ myLogServer = new MyLogServer(isDebugMode,sDebugOutput); dApp = application(); dMain = new MyServiceMain(dApp); // класс от QObject в котором создается еще один QObject, как описано выше}
MyService::MyService(int argc, char **argv, QString pServiceName, QString pServiceDescription) : QTService(argc, argv, pServiceName){...}
MyService::MyService(int argc, char **argv, QString pServiceName, QString pServiceDescription) : QTService(argc, argv, pServiceName),obj(){...}
#ifndef MySERVICE_H#define MySERVICE_H#include "MyMain.h"class MyService : public QtService<QCoreApplication>{private: MyMain* dMain; QCoreApplication* dApp; QString sRootPath; bool isDebugMode;public: explicit MyService(int argc, char **argv, QString pServiceName, QString pServiceDescription); virtual ~MyService();protected: void start(); void stop(); void pause(); void resume(); void processCommand(int code);};#endif // MySERVICE_H
#include "MyService.h"extern MDLogServer *srgLogServer;MyService::MyService(int argc, char **argv, QString pServiceName, QString pServiceDescription) : QtService<QCoreApplication>(argc, argv, pServiceName),dMain(){ QString sPar = ""; isDebugMode = false; setServiceDescription(pServiceDescription); setServiceFlags(QtServiceBase::Default); if(argc>1) { sPar = argv[1]; if(sPar == "-e" || sPar == "-exec") { isDebugMode = true; } }}MyService::~MyService(){}void MyService::start(){ srgLogServer = new MDLogServer(isDebugMode); dApp = application(); dMain = new MyMain(dApp);}void MyService::stop(){ delete dMain; srgLogServer->deleteLater();}void MyService::pause(){ dMain->processCommand(0);}void MyService::resume(){ dMain->processCommand(1);}void MyService::processCommand(int code){ dMain->processCommand(code);}
C++ (Qt)void MyService::start(){ qDebug() << "Start"; srgLogServer = new MDLogServer(isDebugMode); dApp = application(); dMain = new MyMain(dApp);} void MyService::stop(){ qDebug() << "Stop"; delete dMain; srgLogServer->deleteLater();} ...