Android 不同平台下的单例销毁

Android 不同平台下的单例销毁,android,c++,linux,windows,cross-platform,Android,C++,Linux,Windows,Cross Platform,这段代码在Windows和Linux中工作得很好,但在Android中,不要调用appCfg::~appCfg()。如何修改代码以在所有平台上自动销毁appCfg(在关闭程序中) .cpp 所有的代码都不适合,所以我在这里编写其余的代码 h @塞尔文。所有的代码都不适合,所以我在回答中写下了其余的代码,为什么在getInstance方法中返回指针值的引用?基本上,您不会返回任何与p_实例指针相关的内容。@ozur。p_实例在第一次调用getInstance()时初始化 appCfg * appC

这段代码在Windows和Linux中工作得很好,但在Android中,不要调用appCfg::~appCfg()。如何修改代码以在所有平台上自动销毁appCfg(在关闭程序中)

.cpp


所有的代码都不适合,所以我在这里编写其余的代码

h


@塞尔文。所有的代码都不适合,所以我在回答中写下了其余的代码,为什么在getInstance方法中返回指针值的引用?基本上,您不会返回任何与p_实例指针相关的内容。@ozur。p_实例在第一次调用getInstance()时初始化
appCfg * appCfg::p_instance = 0;
SingletonDestroyer appCfg::destroyer;

SingletonDestroyer::~SingletonDestroyer() {  
    delete p_instance;
}
void SingletonDestroyer::initialize( appCfg* p ) {
    p_instance = p;
}

appCfg& appCfg::getInstance() {
    if(!p_instance)     {
        p_instance = new appCfg();
        destroyer.initialize( p_instance);    
    }
    return *p_instance;
}

appCfg::appCfg()
{
    pSetting = new QSettings(Const::SettingPath()+"/main.cfg",QSettings::IniFormat);
}
//called on Windows and Linux platforms, but not on Android    
appCfg::~appCfg()
{
    pSetting->sync();
    delete pSetting;
}

...
class SingletonDestroyer
{
private:
    appCfg* p_instance;
public:   
    ~SingletonDestroyer();
    void initialize( appCfg* p );
};

class appCfg : public QObject
{
private:
    static appCfg* p_instance;
    static SingletonDestroyer destroyer;

    QSettings * pSetting;
protected:
    appCfg();
    appCfg( const appCfg& );
    appCfg& operator=( appCfg& );
    ~appCfg();
    friend class SingletonDestroyer;
public:
    static appCfg& getInstance();
   ...
};