源代码如下:
- /* ***** thread.h ************/
- #include <qthread.h>
- //#include <unistd.h>
- //#include "form1.h"
- class MyThread : public QThread
- {
- public:
- MyThread();
- virtual void run();
- ~MyThread();
- };
- /************* thread.cpp **********/
- #include "thread.h"
- void MyThread::run()
- { while(1){
- printf("123\n");
- sleep(1);
- printf("321\n");
- sleep(1);
- }
- }[font=楷体_GB2312][/font]
- MyThread::MyThread()
- {
- }
- MyThread::~MyThread()
- { }
调试信息如下:
thread.h:6: parse error before `{' token
thread.h:9: virtual outside class declarationthread.h:10: destructors must be member functions
thread.h:11: parse error before `}' token
thread.cpp:4: invalid use of undefined type `class MyThread'
thread.h:5: forward declaration of `class MyThread'
thread.cpp: In member function `void MyThread::run()':
thread.cpp:7: `sleep' undeclared (first use this function)
thread.cpp:7: (Each undeclared identifier is reported only once for each
function it appears in.)
thread.cpp: At global scope:
thread.cpp:14: invalid use of undefined type `class MyThread'
thread.h:5: forward declaration of `class MyThread'
thread.cpp:17: invalid use of undefined type `class MyThread'
thread.h:5: forward declaration of `class MyThread'
主要问题出在黑体的调试信息部分,
” class MyThread : public QThread “是第六行。为什么这里会出错了?假如我把QThread 换成QApplication 等别的类,此处的报错就会没有。
还有一个问题是:run在此处必须是virtual的吗?
[ 此贴被xd1198在2005-10-09 12:52重新编辑 ]