预览:
双击qml的model 实现音乐播放以及歌曲信息,播放进度
一、设置上下文属性,使c++类对象能够被qml调用
Player mPlayer;
engine.rootContext()->setContextProperty("Player",&mPlayer);
二、在player类中增加信号函数
signals:
void currentPositionChanged(QString);
void updateTotalTime(int);
void musicChanged(QString);
三、在qml文件中关联qml的函数
PlaySlider{
id:sliderWindow
anchors{
left: stepForward.right
leftMargin: 10*dp
right: collectBtn.left
rightMargin: 10*dp
top:parent.top
topMargin: 1*dp
bottom: parent.bottom
bottomMargin: 1*dp

本文详细介绍了如何在C++和QML中通过信号槽进行交互,包括设置上下文属性使得C++对象能被QML调用,定义C++类的信号函数,以及在QML文件中绑定函数,最终实现C++信号触发QML函数的效果。
最低0.47元/天 解锁文章
894

被折叠的 条评论
为什么被折叠?



