QT4/C++:没有这样的信号问题

use*_*966 1 c++ qt4 netbeans-6.9

我有一个小程序来显示设备和捕获任何数据包,使用GUI.I使用QT Designer和Netbeans 6.9绘制GUI,但问题来自我尝试实现信号/插槽.基本上当选择组合框时, QlineEdit将显示所选设备的MAC地址.错误:

 Object::connect: No such signal QComboBox::selectedDev(int) in MainGUI.cpp:21
Object::connect:  (sender name:   'comboBox')
Object::connect:  (receiver name: 'MYMACBOX')
Run Code Online (Sandbox Code Playgroud)

MainGUI.h

#ifndef _MAINGUI_H
#define    _MAINGUI_H

#include "ui_MainGUI.h"

class MainGUI : public QDialog {
    Q_OBJECT
public:
    MainGUI();
    virtual ~MainGUI();
    void displayDevices();
    void selectedValue();
public slots:
    void showmac(int);

    signals:
    void selectedDev(int);
private:
    Ui::MainGUI widget;
};
Run Code Online (Sandbox Code Playgroud)

MainGUI.cpp

#include "MainGUI.h"
#include "pcapCapture.h"
#include <pcap.h>
#include <iostream>
MainGUI::MainGUI() // constructor
{
    widget.setupUi(this);
    //show devices here    
  QObject::connect(widget.comboBox,SIGNAL(selectedDev(int)),widget.MYMACBOX,SLOT(showmac(int)));
}
void MainGUI::showmac(int value)
{
   //show MAC address here
}
Run Code Online (Sandbox Code Playgroud)

我不知道这里的问题是什么,我尝试了不同的方法来解决这个问题,但是它们不会起作用.对于任何明显的错误,这里的Apology,我仍然是QT4(和libpcap)的新手.

Rap*_*ael 5

QComboBox没有selectedDev(int)信号.该文档为每个Qt类提供了一个方便的信号和插槽列表:QComboBox文档

你已经在MainGUI类中定义了selectedDev(int)信号,所以你对connect的调用应该是这样的:(连接的参数是:信号源,信号,槽或信号源,槽或信号.)

QObject::connect(this,SIGNAL(selectedDev(int)),widget.MYMACBOX,SLOT(showmac(int)));
Run Code Online (Sandbox Code Playgroud)

但这没有任何影响,因为没有触发selectedDev(int)信号.

也许您可以尝试将组合框的currentIndexChanged(int)连接到selectedDev(int)信号,如下所示:

QObject::connect(widget.comboBox,SIGNAL(currentIndexChanged(int)),this ,SIGNAL(selectedDev(int)));
Run Code Online (Sandbox Code Playgroud)

我在这里做的是在组合框索引发生变化时触发MainGUI的selectedDev(int)信号.

如果您只是想在用户选择组合框中的某些内容时执行showmac(int),则不能比这更简单:

QObject::connect(widget.comboBox,SIGNAL(currentIndexChanged(int)),widget.MYMACBOX,SLOT(showmac(int)));
Run Code Online (Sandbox Code Playgroud)

因为它对信号和插槽有点困惑,所以这里有一些可能有用的链接:

来自Qt文档的信号和插槽

我的博客上的一篇Qt文章介绍了一个非常简单的Qt应用程序是如何工作的(它与我的博客无关,但对于任何以Qt开头的人来说,这是一个很好的概述Qt应用程序)