Results 1 to 2 of 2

Thread: Fail when using Phonon after restarting application programatically.

  1. #1
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default 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:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. int currentExitCode = 0;
    4.  
    5. do{
    6. QApplication a(argc, argv);
    7. qApp->setQuitOnLastWindowClosed(true);
    8.  
    9. SoundPlayer::instance()->loadSounds();
    10. bool success;
    11. MainWindow w(success);
    12. if(success)
    13. currentExitCode=a.exec();
    14. else
    15. qApp->exit();
    16.  
    17. }while( currentExitCode == MainWindow::EXIT_CODE_REBOOT );
    18.  
    19. return currentExitCode;
    20. }
    21.  
    22. (..)
    23.  
    24. void SoundPlayer::loadSounds()
    25. {
    26. unloadSounds();
    27.  
    28. QString dirfilename = "sound.mp3";
    29. if(QFile::exists(dirfilename))
    30. {
    31. qDebug()<<Phonon::phononVersion();
    32.  
    33. sounds.insert(estSound1 ,Phonon::createPlayer(Phonon::MusicCategory,Phonon::MediaSource(dirfilename)));
    34. connect(sounds[estSound1],SIGNAL(finished()),this, SLOT(rewindPlayer()));
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 

    When the application restarts and the execution reaches loadSounds(), the error arises at:

    Qt Code:
    1. Phonon::createPlayer(Phonon::MusicCategory,Phonon::MediaSource(dirfilename))
    To copy to clipboard, switch view to plain text mode 

    with message:


    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:
    Qt Code:
    1. Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput();
    2. Phonon::MediaObject *mo = new Phonon::MediaObject(this);
    To copy to clipboard, switch view to plain text mode 

    after restart.

    Do you have any idea what can be wrong?
    Best regards,
    Konrad

  2. #2
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default 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:

    Qt Code:
    1. // Restart Application
    2. void myApp::Restart(bool Abort)
    3. {
    4. // Spawn a new instance of myApplication:
    5. QProcess proc;
    6. #ifdef Q_OS_WIN
    7. proc.startDetached(this->applicationFilePath());
    8. #endif
    9.  
    10. #ifdef Q_OS_MAC
    11. // In Mac OS the full path of aplication binary is:
    12. // <base-path>/myApp.app/Contents/MacOS/myApp
    13. args << (this->applicationDirPath() + "/../../../myApp.app");
    14. proc.startDetached("open", args);
    15. #endif
    16.  
    17. // Terminate current instance:
    18. if (Abort) // Abort Application process (exit immediattely)
    19. ::exit(0);
    20. else
    21. this->exit(0); // Exit gracefully by terminating the myApp instance
    22. }
    To copy to clipboard, switch view to plain text mode 

    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,
    Last edited by airproject; 2nd November 2012 at 09:03.

Similar Threads

  1. Deploying Phonon application
    By illuzmax in forum Installation and Deployment
    Replies: 1
    Last Post: 10th November 2011, 16:45
  2. How to setFocus to QMenuBar programatically?
    By ticvitanic in forum Qt Programming
    Replies: 0
    Last Post: 2nd July 2010, 16:58
  3. Can I Programatically Overlap Dock Widgets?
    By bieber in forum Qt Programming
    Replies: 0
    Last Post: 29th June 2010, 20:42
  4. Replies: 19
    Last Post: 21st January 2008, 10:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.