#include <QDebug> class A { public: static A* getInstance() { if(a==NULL) a = new A; return a; } void setB(QString tmp){b = tmp;} QString getB(){return b;} private: QString b; A(){} static A* a; }; A* A::a = NULL; int main() { A *aa = A::getInstance(); aa->setB("10"); qDebug() << aa->getB(); A *bb = A::getInstance(); bb->setB("20"); qDebug() << aa->getB(); qDebug() << "aa:" << aa << "bb:" << bb; return 0; } 输出: "10"