简体   繁体   中英

Qt Phonon MediaObject conversion error

I want to play some WAV files, but I have error C2664 in Visual Studio:

error C2664: 'Phonon::MediaObject::setCurrentSource' : conversion error from'const char [24]' to 'const Phonon::MediaSource &'

This is the code:

Phonon::MediaObject *media_object_;

media_object_ = new Phonon::MediaObject(this);
media_object_->setCurrentSource("/sounds/startsound.wav");
media_object_->play();

Error 11 error C2664: 'Phonon::MediaObject::setCurrentSource' : no se puede convertir el parámetro 1 de 'const char [24]' a 'const Phonon::MediaSource &' c:\\Naali\\devgit\\naali\\UiModule\\Inworld\\View\\TTSChatWidget.cpp 105 UiModule

Thanks!

The setCurrentSource() function takes a MediaSource object by const-reference. There is no constructor for MediaSource that takes a const char * (a null terminated byte string). You will probably need to create a temporary object of QString with your path and pass it to a MediaSource (possibly temporary) and use it to create your . The second example of MSDN documentation on C2664 explains this.

media_object_->setCurrentSource(MediaSource(QString("/sounds/startsound.wav")));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM