我正在使用基于qt4的qt-ros来构建应用程序。
但是有一个问题,signal & slot不能工作。
我使用的vlc-qt库提供了一个名为played的信号函数,如下面的链接所示。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 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();发布于 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。
在您的情况下,我建议您重命名插槽,以便它们与模式不匹配,并且不会自动连接。
https://stackoverflow.com/questions/53880556
复制相似问题