|
代码是这样的
//mythread.h
#include <qthread.h>
#include "pcap.h"
#include "analyse.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);
}
}
};
//mainform.ui.h
#include "aboutme.h"
#include "cap_pkt.h"
#include <qstring.h>
#include <qmessagebox.h>
#include "analyse.h"
#include <qtable.h>
#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();
}
编译的时候:
.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'
高手指点一下吧 |
|