2

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:エラー:LNK2019:未解決の外部シンボル "__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:エラー:LNK2001:未解決の外部シンボル "public:virtual struct QMetaObject const * __thiscall QSound :: metaObject(void)const"(?metaObject @ QSound @@ UBEPBUQMetaObject @@ XZ)

そしてそれに似た他の3人。

私は以下を試しました

QSound::play("filename");-同じ問題

私は静的な参照をいじりましたが、次のようなものを手に入れました

4

3 に答える 3

3

問題は私の.proファイルでした。プロジェクトの.proファイルにQT+=マルチメディアを追加する必要がありました。

于 2013-03-01T14:17:42.580 に答える
0

私は同じ問題に遭遇しました。ポインタを作成する代わりに、ヘッダーに空の変数を作成します。

private:
      QSound m_startsound; 

親オブジェクトに明示的に言及して値を割り当てます(そのことを思い出させてくれてありがとう):

BloxProcessor::BloxProcessor() : 
     m_showPopup(true),
     ....
     m_startsound("mysounds/hallo.wav",this)
{
....
}

これは、cppファイルでも実行できます。私の意見では、構造化されていないソリューション:

含む

... QSound m_startsound( "mysounds / hallo.wav"、this);

ただし、これらのソリューションは、静的なサウンドを数回再生する際の読み込み時間を解決する可能性があります。特定のトリガーでサウンドを変更できるようにすることはありません。これには、ポインタ構造が必要です。ヘッダーQPointer p_startsound;

initまたはコンストラクターで、デフォルト値を設定します。

p_startsound = new QSound("mysounds/he.wav",this);

変更トリガーでは、メモリリークを防ぐために、必ず古いオブジェクトを削除してください

BloxProcessor::triggerToChangeSoundActivated()
{
    p_startsound->deleteLater();
    p_startsound = new QSound("mysounds/hallo.wav",this);
}

計算時間が重要でない場合は、単純な再生機能を使用できます

QSound::play("mysounds/hallo.wav");

ところで、どういうわけか、これらのいずれにもマルチメディアパッケージを明示的に含める必要はありません。おそらく、異なるバージョンのQTを使用しているためか、プラットフォームの別の場所で継承されているためです。

編集代わりに保護されたQPointerを使用してください。そうしないとクラッシュします...

于 2014-03-05T08:59:53.927 に答える
0


QT5を使用している場合は、 [プロジェクト]->[プロパティ]->[構成プロパティ]->[リンカー]->[入力]->[追加の依存関係]の[追加の依存関係]にQt5Multimedia.libを追加してください。

于 2020-12-09T22:11:05.387 に答える