I want to make a global variable in Qt. So I wrote a singleton class. But I am getting the following errors
:: error: symbol(s) not found,
:: error: collect2: ld returned 1 exit status
I am using the following code :
CityBookGlobalVariables.h:
class CityBookGlobalVariables
{
private:
CityBookGlobalVariables();
CityBookGlobalVariables( const CityBookGlobalVariables& _instance );
static CityBookGlobalVariables* m_pInstance;
public:
QStringList m_cityList;
static CityBookGlobalVariables* instance()
{
if ( !m_pInstance )
m_pInstance = new CityBookGlobalVariables;
return m_p开发者_开发技巧Instance;
}
void setCityList(QStringList cityList);
QStringList getCityList();
};
CityBookGlobalVariables.cpp:
//CityBookGlobalVariables* CityBookGlobalVariables::m_pInstance = 0;
CityBookGlobalVariables* m_pInstance = 0;
CityBookGlobalVariables::CityBookGlobalVariables()
{
}
CityBookGlobalVariables::CityBookGlobalVariables(const CityBookGlobalVariables& _instance )
{
}
void CityBookGlobalVariables::setCityList(QStringList cityList)
{
m_cityList = cityList;
}
QStringList CityBookGlobalVariables::getCityList()
{
return m_cityList;
}
setCityList calling from A1.cpp
CityBookGlobalVariables *pointer = CityBookGlobalVariables::instance();
pointer->setCityList(cityitems);
getCityList calling from B1.cpp
CityBookGlobalVariables *pointer = CityBookGlobalVariables::instance();
cityModel->setStringList(pointer->getCityList());
精彩评论