QMediaPlayer doesn't start



  • Hello,

    I'm trying to create an instance of QMediaPlayer, but I always get an error in runtime.

    QMediaPlayer	player;
    

    I get the error message:

    The inferior stopped because it recieved a signal from the
    operating system.
    
    Signal name: ?
    Signam meaning: Unknown signal
    

    OS: aktuelles Windows 10

    QT:
    Qt Creator 4.14.0
    Based on Qt 5.12.2 (MSVC 2019, 64 bit)

    the .pro file contains:
    QT += core gui multimedia

    Has anybody an idea or coult help please?

    Thanks and regards
    Andreas


  • Lifetime Qt Champion

    Please show some code. We can't know what you're doing without it...



  • void WndTemplBase::PlaySound(QString    _sFilename)
    {
        // the following line causes the runtime error!
        m_pPlayer  = new QMediaPlayer;       // member variable
    
        QUrl   urlTitle = QUrl::fromLocalFile(_sFilename);
    
        m_pPlayer->setMedia(urlTitle);
        m_pPlayer->setVolume(50);
        m_pPlayer->play();
    }
    

  • Lifetime Qt Champion

    @AndreasKwd said in QMediaPlayer doesn't start:

    m_pPlayer = new QMediaPlayer;

    So you create a new QMediaPlayer every time PlaySound() is called? This doesn't look right.



  • No, I create it in the constructor. I just wanted to make it easier.
    The full code is:

    void WndTemplBase::WndTemplBase()
    {
        // the following line causes the runtime error!
        m_pPlayer  = new QMediaPlayer;       // member variable
    }
    
    void WndTemplBase::~WndTemplBase()
    {
        delete m_pPlayer;
    }
    
    void WndTemplBase::PlaySound(QString    _sFilename)
    {
        QUrl   urlTitle = QUrl::fromLocalFile(_sFilename);
    
        m_pPlayer->setMedia(urlTitle);
        m_pPlayer->setVolume(50);
        m_pPlayer->play();
    }
    

  • Lifetime Qt Champion

    Strange. Where do you instantiate WndTemplBase?
    What Qt version and OS do you use?


Log in to reply