我的环境是Qt5 32bit
Windows 7 64bit
MSVC 2010 32bit
我的代码是一个简单的音乐播放器
这是主要代码
slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 100);
player->setMedia(QUrl::fromLocalFile("D://test.mp3"));
player->setVolume(50);
...
connect(player, SIGNAL(bufferStatusChanged(int)), slider, SLOT(setValue(int)));
当我运行这个播放器时,它可以播放音乐,但它的值slider
从未改变。
然后我添加这个:
connect(player, SIGNAL(bufferStatusChanged(int)), slider, SLOT(helloWorld(int)));
...
void player::helloWorld(int)
{
qDebug() << "hello, world";
}
我再次运行它,发现字符串hello, world
永远不会被打印。
没有打印任何东西。
为什么slider
不改变值?
-------------------------完整代码------------------------ ---
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
mainWidget = new QWidget();
HLayout = new QHBoxLayout();
VLayout = new QVBoxLayout();
playButton = new QPushButton("Okay");
exitButton = new QPushButton("Exit");
slider = new QSlider(Qt::Horizontal);
player = new QMediaPlayer();
connect(playButton, SIGNAL(toggled(bool)), this, SLOT(playOrPause(bool)));
connect(player, SIGNAL(bufferStatusChanged(int)), slider, SLOT(setValue(int)));
connect(player, SIGNAL(bufferStatusChanged(int)), this, SLOT(test(int)));
player->setMedia(QUrl::fromLocalFile("D://test.mp3"));
player->play();
player->setVolume(50);
slider->setRange(0, 100);
//UI
exitButton->setAutoDefault(true);
playButton->setAutoDefault(true);
playButton->setCheckable(true);
HLayout->addStretch();
HLayout->addWidget(playButton);
HLayout->addWidget(exitButton);
VLayout->addWidget(slider);
VLayout->addStretch();
VLayout->addLayout(HLayout);
mainWidget->setLayout(VLayout);
setCentralWidget(mainWidget);
setWindowIcon(QIcon(":/icons/icon.png"));
setWindowTitle("YUCOAT");
//connect(playButton, SIGNAL(toggled(bool)), this, SLOT(playOrPause(bool)));
//connect(player, SIGNAL(bufferStatusChanged(int)), slider, SLOT(setValue(int)));
}
MainWindow::~MainWindow()
{
}
void MainWindow::playOrPause(bool s)
{
if (s)
player->play();
else
player->pause();
}
void MainWindow::test(int s)
{
qDebug() << "hello, world!";
qDebug() << s;
qDebug() << player->mediaStatus();
}