|
我在qt下用线程,连参考文档里的例子也没编译通过,想问问还有别的这方面的资料吗?
也不知道是不是我的编译方法有问题.
用的例子如下:
//a.cpp
class MyThread : public QThread {
public:
virtual void run();
};
void MyThread::run()
{
for( int count = 0; count < 20; count++ ) {
sleep( 1 );
qDebug( " ing!" );
}
}
int main()
{
MyThread a;
MyThread b;
a.start();
b.start();
a.wait();
b.wait();
}
编译方法:
qmake -project
qmake
make
出现错误:
g++ -c -pipe -Wall -W -I/usr/include/fontconfig -I/usr/include/Xft2 -O2 -march=i386 -mcpu=i686 -fno-use-cxa-atexit -fno-exceptions -DQT_NO_DEBUG -I/usr/lib/qt-3.0.5/include -I/usr/lib/qt-3.0.5/mkspecs/default -o a.o a.cpp
a.cpp:1: parse error before `{' token
a.cpp:10: invalid use of undefined type `class MyThread'
a.cpp:1: forward declaration of `class MyThread'
a.cpp: In member function `void MyThread::run()':
a.cpp:12: `sleep' undeclared (first use this function)
a.cpp:12: (Each undeclared identifier is reported only once for each function
it appears in.)
a.cpp:13: `qDebug' undeclared (first use this function)
a.cpp: In function `int main()':
a.cpp:19: aggregate `MyThread a' has incomplete type and cannot be defined
a.cpp:20: aggregate `MyThread b' has incomplete type and cannot be defined
a.cpp:26:1: warning: no newline at end of file
make: *** [a.o] Error 1
有哪位大侠知道什么原因吗? |
|