C++ Qt-错误:成员函数的使用无效(您是否忘记了';()';?)

C++ Qt-错误:成员函数的使用无效(您是否忘记了';()';?),c++,qt,C++,Qt,你好,我是Qt开发的新手 我只想把一些C++代码移植到Qt中。在C++上,它可以成功地构建,但是当我尝试将代码移植到Qt时,它显示 错误:成员函数的使用无效(您是否忘记了“()”?) 这是我的错误代码行: capture_循环(pdev,数据包,(pcap_处理程序)解析_数据包) 这是我的职责: void MainWindow::capture_loop(pcap_t* pdev, int packets, pcap_handler func){ int linktype; // Deter

你好,我是Qt开发的新手

<>我只想把一些C++代码移植到Qt中。在C++上,它可以成功地构建,但是当我尝试将代码移植到Qt时,它显示

错误:成员函数的使用无效(您是否忘记了“()”?)

这是我的错误代码行:

capture_循环(pdev,数据包,(pcap_处理程序)解析_数据包)

这是我的职责:

void MainWindow::capture_loop(pcap_t* pdev, int packets, pcap_handler func){
int linktype;

// Determine the datalink layer type.
if ((linktype = pcap_datalink(pdev)) < 0)
{
    printf("pcap_datalink(): %s\n", pcap_geterr(pdev));
    return;
}

// Set the datalink layer header size.
switch (linktype)
{
case DLT_NULL:
        linkhdrlen = 4;
    break;

case DLT_EN10MB:
    linkhdrlen = 14;
    break;

case DLT_SLIP:
case DLT_PPP:
    linkhdrlen = 24;
    break;

default:
    printf("Unsupported datalink (%d)\n", linktype);
    return;
}

// Start capturing packets.
if (pcap_loop(pdev, packets, func, 0) < 0)
    printf("pcap_loop failed: %s\n", pcap_geterr(pdev));}
void MainWindow::parse_packet(u_char *user, struct pcap_pkthdr *packethdr,u_char *packetptr){
struct ip* iphdr;
struct icmphdr* icmphdr;
struct tcphdr* tcphdr;
struct udphdr* udphdr;
char iphdrInfo[256], srcip[256], dstip[256];
unsigned short id, seq;

// Skip the datalink layer header and get the IP header fields.
packetptr += linkhdrlen;
iphdr = (struct ip*)packetptr;
strcpy(srcip, inet_ntoa(iphdr->ip_src));
strcpy(dstip, inet_ntoa(iphdr->ip_dst));
sprintf(iphdrInfo, "ID:%d TOS:0x%x, TTL:%d IpLen:%d DgLen:%d",ntohs(iphdr->ip_id), iphdr->ip_tos, iphdr->ip_ttl,4*iphdr->ip_hl, ntohs(iphdr->ip_len));

// Advance to the transport layer header then parse and display
// the fields based on the type of hearder: tcp, udp or icmp.
packetptr += 4*iphdr->ip_hl;
switch (iphdr->ip_p)
{
case IPPROTO_TCP:
    tcphdr = (struct tcphdr*)packetptr;
    printf("TCP  %s:%d -> %s:%d\n", srcip, ntohs(tcphdr->source),dstip, ntohs(tcphdr->dest));
    printf("%s\n", iphdrInfo);
    printf("%c%c%c%c%c%c Seq: 0x%x Ack: 0x%x Win: 0x%x TcpLen: %d\n",
           (tcphdr->urg ? 'U' : '*'),
           (tcphdr->ack ? 'A' : '*'),
           (tcphdr->psh ? 'P' : '*'),
           (tcphdr->rst ? 'R' : '*'),
           (tcphdr->syn ? 'S' : '*'),
           (tcphdr->fin ? 'F' : '*'),
           ntohl(tcphdr->seq), ntohl(tcphdr->ack_seq),
           ntohs(tcphdr->window), 4*tcphdr->doff);
    break;

case IPPROTO_UDP:
    udphdr = (struct udphdr*)packetptr;
    printf("UDP  %s:%d -> %s:%d\n", srcip, ntohs(udphdr->source),
           dstip, ntohs(udphdr->dest));
    printf("%s\n", iphdrInfo);
    break;

case IPPROTO_ICMP:
    icmphdr = (struct icmphdr*)packetptr;
    printf("ICMP %s -> %s\n", srcip, dstip);
    printf("%s\n", iphdrInfo);
    memcpy(&id, (u_char*)icmphdr+4, 2);
    memcpy(&seq, (u_char*)icmphdr+6, 2);
    printf("Type:%d Code:%d ID:%d Seq:%d\n", icmphdr->type, icmphdr->code,
           ntohs(id), ntohs(seq));
    break;
}
printf("=============================================================\n\n");}
void主窗口::捕获循环(pcap\u t*pdev、int数据包、pcap\u处理程序func){
int链接类型;
//确定数据链路层类型。
如果((linktype=pcap_数据链路(pdev))<0)
{
printf(“pcap_datalink():%s\n”,pcap_geterr(pdev));
返回;
}
//设置数据链路层标头大小。
开关(链式)
{
案例DLT_NULL:
linkhdrlen=4;
打破
案例DLT_EN10MB:
linkhdrlen=14;
打破
案件登记表:
案例DLT_PPP:
linkhdrlen=24;
打破
违约:
printf(“不支持的数据链路(%d)\n”,链接类型);
返回;
}
//开始捕获数据包。
if(pcap_循环(pdev,数据包,func,0)<0)
printf(“pcap_循环失败:%s\n”,pcap_geterr(pdev));}
void main window::parse_数据包(u_char*user,struct pcap_pkthdr*packethdr,u_char*packetptr){
结构ip*iphdr;
结构icmphdr*icmphdr;
结构tcphdr*tcphdr;
结构udphdr*udphdr;
char iphdrInfo[256]、srcip[256]、dstip[256];
无符号短id,seq;
//跳过数据链路层标头并获取IP标头字段。
packetptr+=linkhdrlen;
iphdr=(结构ip*)包PTR;
strcpy(srcip,inet_ntoa(iphdr->ip_src));
strcpy(dstip,inet_ntoa(iphdr->ip_dst));
sprintf(iphdrInfo,“ID:%d TOS:0x%x,TTL:%d IpLen:%d DgLen:%d”,ntohs(iphdr->ip_-ID),iphdr->ip_-TOS,iphdr->ip_-TTL,4*iphdr->ip_-hl,ntohs(iphdr->ip_-len));
//前进到传输层标头,然后解析并显示
//基于侦听器类型的字段:tcp、udp或icmp。
packetptr+=4*iphdr->ip_hl;
开关(iphdr->ip\U p)
{
案例IPPROTO_TCP:
tcphdr=(结构tcphdr*)packetptr;
printf(“TCP%s:%d->%s:%d\n”、srcip、ntohs(tcphdr->source)、dstip、ntohs(tcphdr->dest));
printf(“%s\n”,iphdrInfo);
printf(“%c%c%c%c%c%c Seq:0x%x Ack:0x%x Win:0x%x TcpLen:%d\n”,
(tcphdr->urg?'U':'*'),
(tcphdr->ack?'A':'*'),
(tcphdr->psh?'P':'*'),
(tcphdr->rst?'R':'*'),
(tcphdr->syn?'S':'*'),
(tcphdr->fin?'F':'*'),
ntohl(tcphdr->seq),ntohl(tcphdr->ack_seq),
ntohs(tcphdr->窗口),4*tcphdr->doff;
打破
案例IPPROTO_UDP:
udphdr=(结构udphdr*)packetptr;
printf(“UDP%s:%d->%s:%d\n”、srcip、ntohs(udphdr->source),
dstip,NTOH(udphdr->目的地);
printf(“%s\n”,iphdrInfo);
打破
案例IPPROTO_ICMP:
icmphdr=(结构icmphdr*)包PTR;
printf(“ICMP%s->%s\n”,srcip,dstip);
printf(“%s\n”,iphdrInfo);
memcpy(&id,(u_char*)icmphdr+4,2);
memcpy(&seq,(u_char*)icmphdr+6,2);
printf(“类型:%d代码:%d ID:%d序列:%d\n”,icmphdr->Type,icmphdr->Code,
ntohs(id),ntohs(seq));
打破
}
printf(“=====================================================================================\n\n”);}

Google“成员函数指针”之类的东西。我认为不理解这是你的问题。冒犯的界线在哪里?你展示了一堆不相关的代码。