SourceFiles.org - Use the Source, Luke
Home | Register | News | Forums | Guide | MyLinks | Bookmark

Related Sites

Latest News
  General News
  Reviews
  Press Releases
  Software
  Hardware
  Security
  Tutorials
  Off Topic


Back to files

A lot of people asked if Qt threads were usable, or if PerlQt was thread-safe.

The short answer is "no, absolutely not".

In general, Qt itself puts a lot of restrictions on the usage of threads.

For instance, you can't expect to access widget methods directly accross threads. The usual model is to pass custom events, which would trigger an action in the main, GUI thread. See Qt threading model documentation for more informations.

However, even this latter model can't be used as of now with PerlQt, because the whole module isn't threadsafe. So even if message passing is threadsafe within Qt, the PerlQt wrapper around those functions isn't yet.

Now, what can you do exactly with PerlQt and Perl threads?

Well, even if you can't access the PerlQt methods from several threads, you still can use them in your main thread, and use threads::shared variables to communicate.

The pqt_threads.pl example demonstrate that.

Please keep in mind though that the use of Perl threads with PerlQt is discouraged and mostly unsupported.

Very often, the need for threading is overkill and indicates a flaw in the Object Oriented design, where the tasks have not been properly sliced. Tasks then start to block the event loop and developers start to look at threads with greedy eyes :-)

Instead, you should first see if you can't:

  • slice properly your tasks so that they integrate flawlessly in the event loop (cf. Qt::Timer, Qt::Object::startTimer()...)
  • delegate the work to a background process, controlled via STDIN/STDOUT (cf. Qt::Process)

Have fun,
Germain Garand


Other Sites

Discussion Groups
  Beginners
  Distributions
  Networking / Security
  Software
  PDAs

About | FAQ | Privacy | Awards | Contact
Comments to the webmaster are welcome.
Copyright 2006 Sourcefiles.org All rights reserved.