Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

c++ - How to solve Qt Unresolved error code 0x80040216?

I am a student writing a project using Qt. I need to play an audio file when the button is pushed, so I write the code:

void DrumsWindow::on_pushButton_dHH_clicked()
{
    m_player = new QMediaPlayer(this);
    m_playlist = new QMediaPlaylist(m_player);

    m_player->setPlaylist(m_playlist);
    m_playlist->addMedia(QUrl::fromLocalFile("sound/HH.wav"));

    m_player->play();
}

But when I hit the pushbutton, it doesn't work, an error occures:

DirectShowPlayerService::doSetUrlSource: Unresolved error code 0x80040216 ()

Please, help me! What am I doing wrong?

P.S.: I was told to do the task without using resource files. Of course, this code works:

void DrumsWindow::on_pushButton_dHH_clicked()
{
    m_player = new QMediaPlayer(this);
    m_playlist = new QMediaPlaylist(m_player);

    m_player->setPlaylist(m_playlist);
    m_playlist->addMedia(QUrl("qrc:/aud/sound/HH.wav"));

    m_player->play();
}

But I'm not allowed to use this way.

question from:https://stackoverflow.com/questions/65886167/how-to-solve-qt-unresolved-error-code-0x80040216

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should write your complete file directory to solve the problem. Alternatively you can receive the song path from file browser or a QLineEdit filled by user.

Update You can use QDir::currentPath() to find your current directory (executing directory) and move wherever you want.

void DrumsWindow::on_pushButton_dHH_clicked()
{
    QString filePath = QDir::currentPath();
    m_player = new QMediaPlayer(this);
    m_playlist = new QMediaPlaylist(m_player);

    m_player->setPlaylist(m_playlist);
    m_playlist->addMedia(QUrl::fromLocalFile(filePath + "/sound/HH.wav"));

    m_player->play();
}

Also move your creating code of m_player and m_playlist to the constructor to prevent memory leak in your application.

    m_player = new QMediaPlayer(this);
    m_playlist = new QMediaPlaylist(m_player);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...