首页| 论坛| 消息

标题:定义线程的问题 急! 谢谢
作者:ediml
日期:2006-05-31 15:58
内容:

我定义了一个class
class myThread : public Qthread{
public:
virtual void run();
};
void myThread::run(){
int cnt=1;
while(1){
pcap_dispatch(p_handler, //libpcap 句柄
cnt, //要抓取的数据包的个数
ethernet_protocol_packet_callback, //回调函数
NULL); //传给回调函数的参数

}
}
定义了以后我直接在Object Explorer的 Class Variables里加的 myThread pcap_thread
编译的时候:
.ui/mainform.h:52: 'myThread' is used as a type, but is not defined as a type.
In file included from mythread.h:2, (我已经在mainform.ui.h头文件中加了#inculde "mythread.h")
............
mythread.h: At global scope:
mythread.h:5: parse error before `{' token
mythread.h:9: invalid use of undefined type `class myThread'
mythread.h:5: forward declaration of `class myThread'
是不是我定义class的格式有问题呢?


#1 [shiroki 05-31 17:57]
QThread的头文件include了吗? 还是文件贴得不全阿
#2 [ediml 05-31 18:46]
头文件加了
#include
#include "pcap.h"
#include "analyse.h"
//mythread.h
class myThread : public QThread {
// Q_OBJECT
public:
virtual void run();
void myThread::run(){
int cnt=1;
while(1){
pcap_dispatch(p_handler, //libpcap 句柄
cnt, //要抓取的数据包的个数
ethernet_protocol_packet_callback,//回调函数
NULL); //传给回调函数的参数
//sleep(1000);
}
}
};
#include "aboutme.h"
#include "cap_pkt.h"
#include
#include
#include "analyse.h"
#include
#include "config_filter.h"
#include "mythread.h"
void mainForm::capture_pkt()
{

v=result; //v指向输出包信息的表
myThread pcap_thread;
Init_pcap();
//判断数据链路曾的类型,如果不是以太网类型,则退出
if(pcap_datalink(p_handler)!=DLT_EN10MB){
QMessageBox::information(this,"error","For ethernet only!.");
pcap_close(p_handler);
p_handler = NULL;
return;
}

pcap_thread.start();

}
代码大概就是这样的.没用到的我删掉了
#3 [ediml 06-01 12:16]

#4 [shiroki 06-01 13:48]
恩,很可能你的qt编译的时候没有把多线程configure进去吧?
#5 [ediml 06-01 19:48]
怎么把多线程configure进去呢
光加头文件#include 不行吗

<< 1 2 >> (1/2)

回复 发表
主题 版块