Results 1 to 4 of 4

Thread: why do I get an error "KGlobal::locale() must be called from the main thread..."?

  1. #1
    Join Date
    Aug 2011
    Posts
    12
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default why do I get an error "KGlobal::locale() must be called from the main thread..."?

    Hi,
    I'm building an application with the intention that its cross-platform. I have tried to not use any system-specific code, although I'm developing on Linux.
    I have run into the following problem when moving some code that worked perfectly before, when in the main thread, into a separate thread.
    When executing, the application aborts after the following message:

    KGlobal::locale() must be called from the main thread before using i18n() in threads. KApplication takes care of this. If not using KApplication, call KGlobal::locale() during initialization.
    Aborted


    I'm surprised that I'm getting an error which seems to be KDE-related. Is there any way I can fix this without KDE-specific code?

    The line that makes this error appear is the following:

    Qt Code:
    1. audio = new Phonon::AudioOutput(Phonon::MusicCategory);
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: why do I get an error "KGlobal::locale() must be called from the main thread..."

    Can Phonon be used in worker threads at all?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2011
    Posts
    12
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why do I get an error "KGlobal::locale() must be called from the main thread..."

    Hmm I didn't think that would be a problem, I cannot find anything in the documentation that suggests it shouldn't be possible?

    My idea is to create a phonon audio player class that runs on its own thread. My main application would then be capable of starting 2 independent players to be able to crossfade between them, mixing the output sound.

    Is this not possible, or is there a better way to do this?

    Thanks,
    Derek

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: why do I get an error "KGlobal::locale() must be called from the main thread..."

    Quote Originally Posted by derektmm View Post
    Hmm I didn't think that would be a problem, I cannot find anything in the documentation that suggests it shouldn't be possible?
    Does anything suggest it is possible? In general things that access multimedia usually don't work well with multiple threads although I have no idea if this is the case. I think you should ask on some KDE forum (Phonon originates in KDE).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. KGlobal::locale::Warning error...
    By glafauci in forum Qt-based Software
    Replies: 2
    Last Post: 19th September 2011, 09:56
  2. Replies: 2
    Last Post: 18th July 2011, 14:59
  3. What is the "main thread"? Why is it special?
    By tksharpless in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2010, 01:04
  4. Replies: 7
    Last Post: 22nd October 2010, 13:17
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 16:58

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.