Previous | qpython - Limitations |
qpython uses both the QThread class and objects from the Python threading module. Although the two threading schemes are not mixed, it is clearly necessary to have enabled threading support when both Python and Qt were built.
Previous versions of qpython used Python threads rather than Qt's thread support. However, such a pure-Python threading solution was less efficient than the current solution due to the use of timers to check for user input.
To be able to interact with Qt, qpython has to instantiate the QApplication class. Generally, Qt only allows one of these objects to be created in an application, and may not allow it to be destroyed and replaced by another. Usually, this is not a problem but, when importing code from existing PyQt-based modules and applications, it is important to be aware that these may attempt to create QApplication instances of their own.
Further problems when using qpython with modules based on PyKDE: many KDE classes expect that a KApplication instance has been created before they are used, and this is not possible once a QApplication has been created:
>>> from kdeui import KMainWindow >>> main_window = KMainWindow() Fatal error: you need to have a KInstance object before you do anything that requires it! Examples of this are config objects, standard directories or translations.
The solution to this problem is to use the khpython interpreter instead. This offers different features to qpython, but will allow the PyKDE classes to be used more easily from within an interactive environment.
Qt requires that GUI operations are performed from the thread which starts the event loop; in qpython, this is the main application thread. Since commands involving the GUI are entered in a separate thread, some effort is required to communicate those to the GUI thread. This is achieved by posting custom events from the thread running the interpreter. However, the user's input is not passed in this event; the event simply tells the GUI thread to retrieve a string from a pure-Python object. This avoids any thread-related problems with transferring data between threads.
Previous | qpython - Limitations |