0
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <Phonon/MediaSource>
#include <QUrl>
#include <Phonon/MediaObject>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QUrl url("http://www.example.com/music.ogg");
    Phonon::MediaObject *wow =
             Phonon::createPlayer(Phonon::NoCategory,
                                  Phonon::MediaSource(url));
         wow->play();

   }

このコードはファイルを再生せず、次のエラーが発生します。

:: エラー: collect2: ld が 1 つの終了ステータスを返しました

ボタンをクリックしたときにファイルを再生するのを手伝ってくれる人はいますか?

ありがとう。

4

2 に答える 2

2

ヘッダー ファイルで 1 つ以上の関数が宣言されていると思いますが、それらの本体はまだビルドされていません。

例えば:

//headerfile
class MyClass
{
    public: MyClass();
    private: void function1();
             void function2();
};

//source file
MyClass::MyClass(){}
void MyClass::function1(){ /*do something*/ }
//here function2 is missing.

そのため、プロジェクト全体のすべての関数に本体があることを確認してください。

基本的なフォノン メディア プレーヤーの場合、

#ifndef MYVIDEOPLAYER_H
#define MYVIDEOPLAYER_H

#include <QWidget>
#include <QPushButton>
#include <Phonon/VideoPlayer>
#include <QVBoxLayout>

class MyVideoPlayer : public QWidget
{
     Q_OBJECT
public:
      explicit MyVideoPlayer(QWidget *parent = 0);
private:
      Phonon::VideoPlayer *videoPlayer;
      QPushButton *btnButton;
      QVBoxLayout layout;

private slots:
      void onPlay();
};
#endif // MYVIDEOPLAYER_H

#include "myvideoplayer.h"

MyVideoPlayer::MyVideoPlayer(QWidget *parent) :
    QWidget(parent)
{
    videoPlayer=new Phonon::VideoPlayer(Phonon::VideoCategory,this);
    btnButton=new QPushButton("Play",this);

    layout.addWidget(btnButton);
    layout.addWidget(videoPlayer);

    setLayout(&layout);

    connect(btnButton,SIGNAL(clicked()),this,SLOT(onPlay()));
}

void MyVideoPlayer::onPlay()
{
    videoPlayer->load(Phonon::MediaSource("movie.mp4"));
    videoPlayer->play();
}
于 2011-02-25T09:19:58.180 に答える
1

templatetypedef がコメントしたように、リンカー エラーのように聞こえます。必要なライブラリがすべて .pro ファイルに追加されていることを確認してください。たとえば、Phonon に対してリンクする必要があるため、.pro ファイルには以下が含まれている必要があります。

QT += phonon
于 2011-02-25T08:43:03.597 に答える