Fail when using Phonon after restarting application programatically.
Hi all,
I have a problem with using phonon after restarting application.
I have created singleton pattern class which holds voice messages for application. This class inherits from QObject to allow connection of signals and slots. Everything works fine in normal operation. However when i restart the application programatically with use of the following technique:
Code:
int main(int argc, char *argv[])
{
int currentExitCode = 0;
do{
qApp->setQuitOnLastWindowClosed(true);
SoundPlayer::instance()->loadSounds();
bool success;
MainWindow w(success);
if(success)
currentExitCode=a.exec();
else
qApp->exit();
}while( currentExitCode == MainWindow::EXIT_CODE_REBOOT );
return currentExitCode;
}
(..)
void SoundPlayer::loadSounds()
{
unloadSounds();
if(QFile::exists(dirfilename
)) {
qDebug()<<Phonon::phononVersion();
sounds.insert(estSound1 ,Phonon::createPlayer(Phonon::MusicCategory,Phonon::MediaSource(dirfilename)));
connect(sounds[estSound1],SIGNAL(finished()),this, SLOT(rewindPlayer()));
}
}
When the application restarts and the execution reaches loadSounds(), the error arises at:
Code:
Phonon::createPlayer(Phonon::MusicCategory,Phonon::MediaSource(dirfilename))
with message:
Quote:
Fatal Error: Accessed global static 'Phonon::FactoryPrivate *globalFactory()' after destruction. Defined at ../3rdparty/phonon/phonon/factory.cpp:84
the same error appears when i try to execute any of:
Code:
Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput();
Phonon::MediaObject *mo = new Phonon::MediaObject(this);
after restart.
Do you have any idea what can be wrong?
Best regards,
Konrad
Re: Fail when using Phonon after restarting application programatically.
As a workaround i have changed the way i do programatical restart. I have to use process respawn to keep phonon alive:
Code:
// Restart Application
void myApp::Restart(bool Abort)
{
// Spawn a new instance of myApplication:
#ifdef Q_OS_WIN
proc.startDetached(this->applicationFilePath());
#endif
#ifdef Q_OS_MAC
// In Mac OS the full path of aplication binary is:
// <base-path>/myApp.app/Contents/MacOS/myApp
args << (this->applicationDirPath() + "/../../../myApp.app");
proc.startDetached("open", args);
#endif
// Terminate current instance:
if (Abort) // Abort Application process (exit immediattely)
::exit(0);
else
this->exit(0); // Exit gracefully by terminating the myApp instance
}
Maybe the phonon failure is a QT bug or i am missing some object lifetime nuance. If someone has some thoughts, i will appreciate it.
Best regards,