[solved] QAudioOutput works in example project, doesn't work in my project



  • hello,

    I'm facing a very weird issue. I want to add audio play to my project, so I first tried Qt's AudioOutput example. it compiles and works well. so I copied the same code to my project (same QAudioFormat):

    @
    m_format.setSampleRate(48000);
    m_format.setChannelCount(2);
    m_format.setSampleSize(16);
    m_format.setCodec("audio/pcm");
    m_format.setByteOrder(QAudioFormat::LittleEndian);
    m_format.setSampleType(QAudioFormat::SignedInt);

        QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
        if (!info.isFormatSupported(m_format)) {
            qWarning() << "Default format not supported - trying to use nearest";
            LOG(ERROR, MISC, 0, "Default format not supported - trying to use nearest");
            m_format = info.nearestFormat(m_format);
        }
    

    @

    however, in my project, QAudioDeviceInfo::defaultOutputDevice() always return null device.

    I couldn't see any issue at all. so I copied the same code again to a completely new project's main function, and it worked.

    it just won't work in a specific project. I start to think maybe my .pro settings are wrong or something. I can't figure this out.

    [edit: Added missing coding tags @ SGaist]


  • Lifetime Qt Champion

    Hi,

    Did you compare the working project and your pro file ?



  • If you have the time, you can look up SFML
    http://www.sfml-dev.org/
    really easy to integrate with Qt and it's easier to use that all Audio classes in Qt IMO

    Good luck!



  • Thank you

    Our project is quite large, it is not easy to strip it down and make it compile.

    I will debug Qt instead. I feel that it might have something to do with the lib, flags used by the project.

    [quote author="SGaist" date="1423781265"]Hi,

    Did you compare the working project and your pro file ?[/quote]



  • will certainly try this!

    Thanks
    [quote author="maximus" date="1423782750"]If you have the time, you can look up SFML
    http://www.sfml-dev.org/
    really easy to integrate with Qt and it's easier to use that all Audio classes in Qt IMO

    Good luck![/quote]



  • after debugging Qt, I realized that the issue is
    QFactoryLoader can't load the audio plugin for my project even the inputs I provide seem to be the same between the working case and the failed case.

    I'm still debugging QFactoryLoader to see how it works.



  • Ok, so the root cause is in the failed case, we called:
    QCoreApplication::setLibraryPaths(QStringList(QCoreApplication::applicationDirPath()));

    before setting up audio. This path doesn't contain the default Qt plugins, so it can't find the audio plugin dll for windows.


  • Lifetime Qt Champion

    Why are you making this call ?



  • this is a joint project with many people. I don't why and who added this code.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.