|
qt新手,这几天需要用QHash做些东西,结果刚开始就碰个小问题:QHash在程序里总是编译不过,总会提示"QHashData"的"Undefined reference"问题。为了测试问题所在,写了一个非常简单的程序如下:
#include <iostream>
#include <QtCore/QHash>
#include <QtCore/QHashData>
using namespace std;
int main(int argc, const char* argv[])
{
QHash<int, char*>* hash = new QHash<int, char*>();
(*hash)[0] = "aaa";
(*hash)[1] = "bbb";
cout << "The hash value for 0 is " << (*hash)[0];
return 0;
}
同样,编译时出现问题:
Undefined symbols:
"QHashData::freeNode(void*)", referenced from:
QHash<int, char*>::deleteNode(QHashNode<int, char*>*)in main.o
"QHashData::destroyAndFree()", referenced from:
QHash<int, char*>::freeData(QHashData*)in main.o
"qt_assert(char const*, char const*, int)", referenced from:
QHash<int, char*>::findNode(int const&, unsigned int*) constin main.o
"QHashData::rehash(int)", referenced from:
QHashData::willGrow() in main.o
"QHashData::detach_helper(void (*)(QHashData::Node*, void*), int)", referenced from:
QHash<int, char*>::detach_helper()in main.o
"QHashData::allocateNode()", referenced from:
QHash<int, char*>::createNode(unsigned int, int const&, char* const&, QHashNode<int, char*>**)in main.o
"QHashData::shared_null", referenced from:
__ZN9QHashData11shared_nullE$non_lazy_ptr in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
总觉得是缺了哪个库引用了,但是试过添加QHashData,没用。其实QHashData就是在qhash.h文件中定义的…各位有经验的高手指教一下,我估计是犯什么低级错误了…先谢过了!
[color="Red"]解决办法:还是自己没有好好看qt的手册阿…其实需要自己在项目所在目录下面运行qmake -project和qmake projectname.pro,然后qt会自动生成需要的Makefile。用这个Makefile就没问题了… |
|