警告消息“没有匹配的信号”

A warning message “No matching signal for”

我正在使用基于 qt4qt-ros 来构建应用程序。

但是有个问题signal & slot不行

我使用的vlc-qt库提供了一个叫played的信号函数,如下面的link所示。 vlc-qt

我尝试通过创建适当的 slot 函数来连接到 QMetaObject :: connectSlotsByName 方法,但它无法使用警告 "No matching signal for".

在mainWindow.h

public Q_SLOTS:
    void on_vListPlayer_played();

并在 mainWindow.cpp

void MainWindow::on_vListPlayer_played()
{
    ROS_INFO("player started!------------------------------");
}
...
MainWindow::MainWindow(int argc, char** argv, QWidget *parent)
: QMainWindow(parent)
, qnode(argc,argv)
{
    ui.setupUi(this); // Calling this incidentally connects all ui's triggers to on_...() callbacks in this class.

    // UI Init
    QWidget* mainWidget = new QWidget(this);
    this->setCentralWidget(mainWidget);
    mainWidget->setStyleSheet("background-color: black;");
    QVBoxLayout* mainLayout = new QVBoxLayout;
    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);
    mainWidget->setLayout(mainLayout);

    m_vVideoWidget = new VlcWidgetVideo;
    mainLayout->addWidget(m_vVideoWidget);

    m_vInstance = new VlcInstance(VlcCommon::args(), this);
    m_vPlayer = new VlcMediaPlayer(m_vInstance);
    m_vPlayer->setVideoWidget(m_vVideoWidget);

    vListPlayer = new VlcMediaListPlayer(m_vPlayer, m_vInstance);
    QObject::connect(vListPlayer, SIGNAL(played()), this, SLOT(on_vListPlayer_played()));

    m_vVideoWidget->setMediaPlayer(m_vPlayer);

    m_vList = new VlcMediaList(m_vInstance);
    openVideoes(m_DataPath);

    vListPlayer->setMediaList(m_vList);
    vListPlayer->setPlaybackMode(Vlc::PlaybackMode::Repeat);

    vListPlayer->mediaPlayer()->play();
...
}

在 MediaListPlayer.h(vlc-qt 库)

class VLCQT_CORE_EXPORT VlcMediaListPlayer : public QObject
{
    Q_OBJECT
......
public Q_SLOTS:
    void itemAt(int index);
    void next();
    void play();
    void previous();
    void stop();

Q_SIGNALS:

    void played();
    void nextItemSet(VlcMedia *media);
    void nextItemSet(libvlc_media_t *media);
    void stopped();

您正在使用 Qt Designer,生成的代码(由 ui.setupUi(this); 调用)调用 QMetaObject::connectSlotsByName(QObject *object)

根据 Qt documentation 这会尝试连接所有名称与以下模式匹配的插槽:void on_<object name>_<signal name>(<signal parameters>);

由于插槽 void on_vListPlayer_played() 与模式匹配,因此尝试连接它。但是失败了,因为你没有任何对象 named vListPlayer.

对于你的情况,我建议你重命名你的插槽,这样它们就不会匹配模式并且不会自动连接。