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

我猜头文件中声明了一个或多个函数,但它们的主体尚未构建。

例如:

//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 回答