In this tutorial, we will discuss about how to develop a multithreaded application using
QT C++ in QT Creator. After viewing the video tutorial, download the source code and try to modify the
code, so that, you get an idea of what is discussed and learned in the tutorial
video.
Among the defining characteristics of Java is its built-in support for multithreaded programming. This support, which has been present in Qt C++ from the start, is provided by the Thread class, the
runnable interface, several methods supplied by Object, and the synchronized keyword.
Multithreading enables you to write programs that contain two or more separate paths of execution that can execute concurrently. Each path of execution is called a thread. Through the careful use of multithreading, you can create programs that make efficient use of system resources and maintain a responsive
user interface.
Multithreading Fundamentals :
At its core, multithreading is a form of multitasking. There are two distinct types of multitasking: process-based and thread-based.
It is important to differentiate between the two. As it relates to this discussion, a process, in essence,
is a program that is executing. Thus, process-based multitasking is the feature that allows your computer to run two or more programs concurrently. For example, it is process-based multitasking that allows you to download a file at the same time you are compiling a program or sorting a database . In process-based multitasking, a program is the smallest unit of code that can be dispatched by the scheduler.
In a thread-based multitasking environment, the thread is the smallest unit of dispatchable code. Because a program can contain more than one thread, a single program can use multiple threads to perform two or more tasks at once.
For instance, a browser can begin rendering a Web page while it is still downloading the
remaining page. This is possible because each action is performed by a separate thread.
All processes have at least one thread of execution, which is called the main thread, because it is the one that is executed when a program begins. From the main thread, you can create other threads. These other threads can also create threads, and so on.
Multithreading is important for two main reasons. First, multithreading enables you to write very efficient programs because it lets you utilize the idle time that is present in most programs. Most I/O devices, whether they be network ports, disk drives, or the keyboard, are much slower than the CPU. Thus, a program will often spend a majority of its execution time waiting to send or receive information to or from a device. By using multithreading, your program can execute another task during this idle time.
The second reason that multithreading is important is the event handling model. A program(such as an applet) must respond quickly to an event and then return. An event handler must not retain control of the CPU.
QT Creator SDK :The QT Creator SDK (software development kit) is a set of development tools used to develop applications for QT platform. The QT Creator SDK includes the following:
Required libraries,
Debugger,
An emulator,
Relevant documentation for the QT C++ application program interfaces (APIs),
Sample source code,
Tutorials for the Android OS .
Click below to see the video and source.
QT C++ Multithreaded Programming Video Tutorial