我正在尝试从 QSound 对象播放声音。我看不出为什么它不起作用,看前面的例子
这是标题
#ifndef ACCESSPANEL_H
#define ACCESSPANEL_H
#include <QWidget>
#include "theislandmain.h"
#include <QString>
#include <QtMultimedia/QSound>
namespace Ui {
class accessPanel;
}
class accessPanel : public QWidget
{
Q_OBJECT
public:
explicit accessPanel(QWidget *parent = 0);
~accessPanel();
private slots:
QString getCode();
void on_one_clicked();
void on_two_clicked();
void on_three_clicked();
void on_four_clicked();
void on_five_clicked();
void on_six_clicked();
void on_seven_clicked();
void on_eight_clicked();
void on_nine_clicked();
void on_cancel_clicked();
void on_zero_clicked();
void on_confirm_clicked();
private:
Ui::accessPanel *ui;
QString input;
QSound *keypad;
};
#endif // ACCESSPANEL_H
这是主要
#include "accesspanel.h"
#include "ui_accesspanel.h"
#include <QtMultimedia/QSound>
accessPanel::accessPanel(QWidget *parent) :
QWidget(parent),
ui(new Ui::accessPanel)
{
ui->setupUi(this);
keypad = new QSound("../Island/Sounds/keypad.wav", this);
}
accessPanel::~accessPanel()
{
delete ui;
}
QString accessPanel::getCode()
{
return input;
}
void accessPanel::on_one_clicked()
{
keypad->play();
input = input + "1";
ui->codeDisplay->setText(input);
}
void accessPanel::on_two_clicked()
{
input = input + "2";
ui->codeDisplay->setText(input);
}
void accessPanel::on_three_clicked()
{
input = input + "3";
ui->codeDisplay->setText(input);
}
void accessPanel::on_four_clicked()
{
input = input + "4";
ui->codeDisplay->setText(input);
}
void accessPanel::on_five_clicked()
{
input = input + "5";
ui->codeDisplay->setText(input);
}
void accessPanel::on_six_clicked()
{
input = input + "6";
ui->codeDisplay->setText(input);
}
void accessPanel::on_seven_clicked()
{
input = input + "7";
ui->codeDisplay->setText(input);
}
void accessPanel::on_eight_clicked()
{
input = input + "8";
ui->codeDisplay->setText(input);
}
void accessPanel::on_nine_clicked()
{
input = input + "9";
ui->codeDisplay->setText(input);
}
void accessPanel::on_cancel_clicked()
{
this->close();
input = "";
ui->codeDisplay->clear();
}
void accessPanel::on_zero_clicked()
{
input = input + "0";
ui->codeDisplay->setText(input);
}
void accessPanel::on_confirm_clicked()
{
ui->codeDisplay->setText(input);
TheIslandMain::setInput(input);
this->close();
}
我收到以下错误。
accesspanel.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void _ thiscall QSound::play(void)" ( _imp_?play@QSound@@QAEXXZ) 在函数“private: void __thiscall”中引用accessPanel::on_one_clicked(void)" (?on_one_clicked@accessPanel@@AAEXXZ)
accesspanel.obj:-1: 错误: LNK2019: 无法解析的外部符号“__declspec(dllimport) public: __thiscall QSound::QSound(class QString const &,class QObject *)” (_ imp ??0QSound@@QAE@ABVQString@@ PAVQObject@@@Z) 在函数“public: __thiscall accessPanel::accessPanel(class QWidget *)”中引用 (??0accessPanel@@QAE@PAVQWidget@@@Z)
accesspanel.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QSound::metaObject(void)const" (?metaObject@QSound@@UBEPBUQMetaObject@@XZ)
和其他3个类似的。
我试过以下
QSound::play("filename");
- 同样的问题
我搞砸了一个静态引用,但得到了类似的东西