Search code examples
c++qtqt4rosvlc-qt

A warning message “No matching signal for”


I'm using qt-ros based on qt4 to build applications.

But there is a problem that signal & slot does not work.

The vlc-qt library I'm using provides a signal function called played, as shown in the link below. vlc-qt

I try to connect to the QMetaObject :: connectSlotsByName method by creating the appropriate slot function, but it does not work with the warning "No matching signal for".

in mainWindow.h

public Q_SLOTS:
    void on_vListPlayer_played();

and in 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();
...
}

in MediaListPlayer.h (vlc-qt lib)

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

Solution

  • You are using Qt Designer, the generated code (that is called by ui.setupUi(this);) makes a call to QMetaObject::connectSlotsByName(QObject *object).

    As per Qt documentation this attempts to connect all slots with a name matching the following pattern: void on_<object name>_<signal name>(<signal parameters>);

    As the slot void on_vListPlayer_played() matches the pattern, an attempt to connect it is made. But fails because you do not have any object named vListPlayer.

    In your case I would suggest you rename your slots so that they do not match the pattern and do not get connected automatically.