首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >出现警告消息“没有匹配的信号”

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

Stack Overflow用户
提问于 2018-12-21 15:07:36
回答 1查看 90关注 0票数 1

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

但是有一个问题,signal & slot不能工作。

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

我尝试通过创建适当的slot函数来连接到QMetaObject :: connectSlotsByName方法,但它不能在出现警告"No matching signal for“的情况下工作。

在mainWindow.h中

代码语言:javascript
复制
public Q_SLOTS:
    void on_vListPlayer_played();

在mainWindow.cpp中

代码语言:javascript
复制
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 lib)中

代码语言:javascript
复制
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();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-22 17:54:47

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

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

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

在您的情况下,我建议您重命名插槽,以便它们与模式不匹配,并且不会自动连接。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53880556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档