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

发布于 2024-10-07 08:55:07 字数 1193 浏览 0 评论 0原文

我有一个小程序,可以使用 GUI 显示设备并捕获任何数据包。我使用 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')

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

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
}

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

I have a small program to show devices and capture any packets, with GUI.I use QT Designer and Netbeans 6.9 to draw the GUI,but the problem comes when i try to implement a signal/slot.Basically when a combo box is selected, a QlineEdit would show a MAC address of the selected device.
The error:

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

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

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
}

I don't know whts the problem here, i tried different ways to get around this problem, but they won't work.Apologies for any obvious mistakes here, i am still new to QT4( and libpcap).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦归所梦 2024-10-14 08:55:07

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

您已在 MainGUI 类中定义了 selectedDev(int) 信号,因此对 connect 的调用应如下所示:(连接的参数为:信号源、信号、槽或信号源、槽或信号。)

QObject::connect(this,SIGNAL(selectedDev(int)),widget.MYMACBOX,SLOT(showmac(int)));

但这不会有任何影响,因为没有任何东西触发 selectedDev(int) 信号。

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

QObject::connect(widget.comboBox,SIGNAL(currentIndexChanged(int)),this ,SIGNAL(selectedDev(int)));

我在这里所做的是当组合框索引更改时触发 MainGUI 的 selectedDev(int) 信号。

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

QObject::connect(widget.comboBox,SIGNAL(currentIndexChanged(int)),widget.MYMACBOX,SLOT(showmac(int)));

因为它看起来您对信号和信号有点困惑。这里有一些可能有帮助的链接:

Signals & Qt 文档中的插槽

Qt 介绍性内容我博客中的文章解释了一个非常简单的 Qt 应用程序如何工作(它与我的博客无关,但对于任何开始使用 Qt 的人来说,它都是对 Qt 应用程序的很好的概述)

QComboBox does not have a selectedDev(int) signal. The documentation provides a handy list of signals and slots for every Qt class: QComboBox documentation

You have defined the selectedDev(int) signal in your MainGUI class so your call to connect should be like this: (the arguments to connect are: signal source, signal, slot or signal source, slot or signal.)

QObject::connect(this,SIGNAL(selectedDev(int)),widget.MYMACBOX,SLOT(showmac(int)));

But this won't have any effect as there's nothing firing the selectedDev(int) signal.

Perhaps you could try to connect the combo box's currentIndexChanged(int) to your selectedDev(int) signal, like this:

QObject::connect(widget.comboBox,SIGNAL(currentIndexChanged(int)),this ,SIGNAL(selectedDev(int)));

What I'm doing here is firing the selectedDev(int) signal of your MainGUI when the combo box index changes.

If you simply want to execute showmac(int) when the user select something in the combo box you can't do it more straightforward than this:

QObject::connect(widget.comboBox,SIGNAL(currentIndexChanged(int)),widget.MYMACBOX,SLOT(showmac(int)));

As it seams that you are a bit confused about signals & slots here are some links that might help:

Signals & Slots from the Qt documentation

An introductory Qt article from my blog that explains how a very simple Qt application works (it has nothing to do with it being my blog but it's a nice overview of a Qt application for anyone starting with Qt)

自控 2024-10-14 08:55:07

我同意上面 Raphael 的观点。Qcombobox 已经有信号表明当前选择已更改。这是 qcombobox 发出的信号列表。

Signals
void    activated ( int index )
void    activated ( const QString & text )
void    currentIndexChanged ( int index )
void    currentIndexChanged ( const QString & text )
void    editTextChanged ( const QString & text )
void    highlighted ( int index )
void    highlighted ( const QString & text )

您需要连接到 qlineedit 的信号是 void currentIndexChanged ( int index ) 并且不需要实现新信号。

关于错误

您收到的错误是真实的,正如您从上面 qcombobox 发出的信号列表中看到的那样,没有一个是 QComboBox::selectedDev(int)使错误变得有意义。

Object::connect: No such signal QComboBox::selectedDev(int) in MainGUI.cpp:21

i agree with Raphael above.Qcombobox already has the signal to indicate that the current selection has changed. This is a list of signals emited by qcombobox

Signals
void    activated ( int index )
void    activated ( const QString & text )
void    currentIndexChanged ( int index )
void    currentIndexChanged ( const QString & text )
void    editTextChanged ( const QString & text )
void    highlighted ( int index )
void    highlighted ( const QString & text )

The one you need to connect to your qlineedit is void currentIndexChanged ( int index ) and dont need to implement a new signal.

About the error

The error you are getting is true, as you see from the list of signals emitted by qcombobox above, none of them is QComboBox::selectedDev(int) which makes the error make sense.

Object::connect: No such signal QComboBox::selectedDev(int) in MainGUI.cpp:21
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文