我创建了一个MySoundEffect类,因为我希望通过使其能够返回自播放开始以来经过的时间来增强其isPlaying()函数.所以我做了你在代码中看到的.
问题是,构造函数中的连接引发错误.它表现得好像我连接到父的asetTimer()槽当然不存在.我在运行时用调试器检查了这个指针,它指向一个MySoundEffect对象.
我究竟做错了什么?
.H
#ifndef MYSOUNDEFFECT_H
#define MYSOUNDEFFECT_H
#include <QSoundEffect>
#include <QElapsedTimer>
class MySoundEffect : public QSoundEffect
{
QElapsedTimer* timer;
public slots:
void asetTimer();
public:
MySoundEffect();
~MySoundEffect();
int isPlaying();
};
#endif // MYSOUNDEFFECT_H
Run Code Online (Sandbox Code Playgroud)
的.cpp
#include "mysoundeffect.h"
MySoundEffect::MySoundEffect() : QSoundEffect()
{
timer = new QElapsedTimer();
connect(this,SIGNAL(playingChanged()), this, SLOT(asetTimer()));
}
void MySoundEffect::asetTimer(){
if (QSoundEffect::isPlaying() == true){
timer->restart();
}
}
int MySoundEffect::isPlaying(){
if (QSoundEffect::isPlaying() == true){
return timer->elapsed();
}
else{
return -1;
}
}
MySoundEffect::~MySoundEffect(){
delete timer;
}
Run Code Online (Sandbox Code Playgroud)
错误:
QObject::connect: No such slot QSoundEffect::asetTimer() in ../rob3/mysoundeffect.cpp:6
Run Code Online (Sandbox Code Playgroud)