Linux Program Development: multi-thread programming in QT
Source: Internet
Author: User
Linux Program Development: multi-thread programming in QT-general Linux technology-Linux programming and kernel information. For details, see the following. As a cross-platform GUI system based on C ++, Qt provides powerful functions for users to construct graphical user interfaces. To meet the user's need to construct a complex graphic interface system, Qt provides rich multi-threaded programming support.
As a cross-platform GUI system based on C ++, Qt provides powerful functions for users to construct graphical user interfaces. To meet the user's need to construct a complex graphic interface system, Qt provides rich multi-threaded programming support. Starting from Version 2.2, Qt provides support for multi-threaded programming in the following three aspects: 1. constructs some basic thread classes unrelated to the platform; ii. Thread-safe mode for submitting user-defined events; iii. Multiple inter-Thread synchronization mechanisms, such as semaphores and global locks. These provide great convenience for users. However, in some cases, using the timer mechanism enables Billy to use the multi-thread mechanism of Qt itself to implement the required functions more conveniently and avoid the occurrence of unsafe phenomena. This article not only discusses the multi-thread support mechanism in Qt, but also focuses on the method of simulating multi-thread programming by using the timer mechanism.
1. multi-thread programming supported by the system
Different platforms support different methods for Qt multithreading. When you install Qt on a Windows operating system, thread support is an option of the compiler. The mkfiles subdirectory of Qt contains the compilation files of different types of compilers, among them, files with the-mt suffix support multithreading.
In Unix operating systems, thread support is added by adding the-thread option when running the configure script file. The installation process creates an independent library, libqt-mt. To support multi-threaded programming, you must connect to the Library (the link option is-lqt-mt ), instead of connecting to the common Qt Library (-lqt.
In addition, regardless of the platform, you must define the macro QT_THREAD_SUPPORT (that is, add the compilation option-DQT_THREAD_SUPPORT) when adding thread support ). In Windows, this is usually implemented by adding an option in the qconfig. h file. In Unix systems, it is usually added to the Makefile file.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.