我正在基于qt-ros
使用qt4
来构建应用程序。
但是有一个问题,signal & slot
不起作用。
我正在使用的vlc-qt库提供了一个称为play的信号功能,如下面的链接所示。 vlc-qt
我尝试通过创建适当的QMetaObject :: connectSlotsByName
函数来连接到slot
方法,但不适用于警告“无匹配信号”。
在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 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();
答案 0 :(得分:1)
您使用的是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
。
在您的情况下,我建议您重命名插槽,以使其与模式不匹配并且不会自动连接。