QMediaPlayer LNK2019错误

时间:2017-01-26 15:05:58

标签: c++ qt

大家好我的程序有问题,我想在qt游戏中播放一些声音效果,我遇到错误:link here

MyRect.h看起来像这样:

#ifndef MYRECT_H
#define MYRECT_H

#include <QGraphicsRectItem>
#include <QGraphicsScene>
#include <QKeyEvent>
#include <QObject>
#include <QMediaPlayer>

class MyRect:public QObject, public QGraphicsRectItem
{
    Q_OBJECT;
public:
    MyRect(QGraphicsItem *parent);
    ~MyRect();

    void keyPressEvent(QKeyEvent * event);

public slots:
    void spawn();
private:
    QMediaPlayer * bSound;
};

#endif // !MYRECT_H

MyRect.cpp:

#include "MyRect.h"
#include "Bullets.h"
#include <QDebug>
#include "Enemy.h"
#include <QMediaPlayer>

MyRect::MyRect(QGraphicsItem *parent): QGraphicsRectItem(parent)
{
    bSound = new QMediaPlayer;
    bSound->setMedia(QUrl("qrc:/Sounds/BulletShoot.wav"));
}


MyRect::~MyRect()
{
}

void MyRect::keyPressEvent(QKeyEvent * event){

    if (event->key() == Qt::Key_Left) {
        if(pos().x() > 0)
            setPos(x() - 10, y());
    }
    else if (event->key() == Qt::Key_Right) {
        if(pos().x() < 700)
            setPos(x() + 10, y());
    }
    else if (event->key() == Qt::Key_Space) {   
        //create a bullet
        Bullets * bullet = new Bullets();
        bullet->setPos(x(), y());
        scene()->addItem(bullet);
        bSound->play();
    }
}

void MyRect::spawn() {
    //create an enemy
    Enemy * enemy = new Enemy();
    scene()->addItem(enemy);
}

我使用Visual Studio 2015作为IDE,我还在其他包含目录中包含MULTIMEDIA目录。 问题是产生这个错误的原因我花了3个小时试图解决它并且没有发生。你们可以帮助我吗?

0 个答案:

没有答案