This forum contains many examples of such situation, but in my case static variables are defined correctly, however I still get that error. So this issue is not duplicate of previous and above link does not answer the question. Suggested 21 answers post does not have solution Simon gave me here, please unmark this as "duplicate".
Seems I've declared all correctly, check this:
.h file:
class ValueSetsModelsContainer : public QObject
{
Q_OBJECT
public:
static void DLLEXPORT loadAllergiesValueSets(MPTDatabase *db);
static void DLLEXPORT loadProceduresValueSets(MPTDatabase *db);
// Models access functions
static QStandardItemModel *drugsModel();
static QStandardItemModel *substanceModel();
static QStandardItemModel *reactionsModel();
private:
static QStandardItemModel *myDrugsModel, *mySubstanceModel, *myReactionsModel;
};
.cpp:
QStandardItemModel *ValueSetsModelsContainer::myDrugsModel = 0;
QStandardItemModel *ValueSetsModelsContainer::mySubstanceModel = 0;
QStandardItemModel *ValueSetsModelsContainer::myReactionsModel = 0;
QStandardItemModel *ValueSetsModelsContainer::drugsModel()
{
return ValueSetsModelsContainer::myDrugsModel;
}
QStandardItemModel *ValueSetsModelsContainer::substanceModel()
{
return ValueSetsModelsContainer::mySubstanceModel;
}
QStandardItemModel *ValueSetsModelsContainer::reactionsModel()
{
return ValueSetsModelsContainer::myReactionsModel;
}
So static variables are defined in cpp, however I still get linking error in another module which calls ValueSetsModelsContainer methods:
- allergiesdialog.obj:-1: error: LNK2001: unresolved external symbol "private: static class QStandardItemModel * ValueSetsModelsContainer::myDrugsModel" (?myDrugsModel@ValueSetsModelsContainer@@0PAVQStandardItemModel@@A)
- allergiesdialog.obj:-1: error: LNK2001: unresolved external symbol "private: static class QStandardItemModel *
ValueSetsModelsContainer::mySubstanceModel"
(?mySubstanceModel@ValueSetsModelsContainer@@0PAVQStandardItemModel@@A)- allergiesdialog.obj:-1: error: LNK2001: unresolved external symbol "private: static class QStandardItemModel *
ValueSetsModelsContainer::myReactionsModel"
(?myReactionsModel@ValueSetsModelsContainer@@0PAVQStandardItemModel@@A)
Where the problem could be?