views:

43

answers:

1

Hi,

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!

+2  A: 

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")));
dirkgently
I was using it because it's here: http://doc.trolltech.com/4.6/phonon-mediaobject.html
andofor
Where do I have to declare MediaSource?
andofor
Just include the appropriate headers for `MediaSource` and `QString`. Also, note what the `setCurrentSource` documentation says: _You can just as well use a QUrl or QString (for a local file) here._
dirkgently