• 5120阅读
  • 1回复

定义线程的问题 急! 谢谢 [复制链接]

上一主题 下一主题
离线ediml
 

只看楼主 倒序阅读 楼主  发表于: 2006-06-01
定义了以后我直接在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的格式有问题呢?

代码是这样的

//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();
 
}
[ 此贴被XChinux在2006-06-01 19:15重新编辑 ]
离线freegnu

只看该作者 1楼 发表于: 2006-06-12

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);
}
}
};

you announce the function void run() in class myThread twice , pls define it like following:

class myThread : public QThread
{
public:
virtual void run();
};

void myThread::myThread::run()
{
int cnt=1;
while(1)
{
  pcap_dispatch(p_handler,   //libpcap 句柄
    cnt,   //要抓取的数据包的个数
    ethernet_protocol_packet_callback, //回调函数
    NULL);   //传给回调函数的参数
  //sleep(1000);
}
}
[ 此贴被freegnu在2006-06-12 15:23重新编辑 ]
快速回复
限100 字节
 
上一个 下一个