PDA

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



derektmm
26th August 2011, 09:17
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:

audio = new Phonon::AudioOutput(Phonon::MusicCategory);

Thanks in advance.

wysota
26th August 2011, 09:55
Can Phonon be used in worker threads at all?

derektmm
26th August 2011, 12:04
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

wysota
26th August 2011, 14:44
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).