Qt GUI
This sample shows how to bind the Qt graphical user interface (GUI) with KINGSTAR Win32 methods. Because this sample centers on the link between the Qt GUI and the KINGSTAR functions, it demonstrates only the basic features.
Prerequisites
You must complete the following steps before compiling the Qt sample:
- Assign write permission to the Qt sample folder
- Install Qt
- Install Qt Visual Studio Tools
- Open the Qt KINGSTAR sample in Visual Studio
- Configure Qt VS Tools
Compile and run the sample
The sample file is located at C:\Users\Public\Public Documents\IntervalZero\KINGSTAR SDK\<Version Number>\Samples\GUI\QtGUI. Compile QtGUI.sln.
NOTE: File Explorer has two paths: the hierarchy path and full path. The hierarchy path is shown in the address bar. The full path is shown in <File Name> Properties—if you right-click QtGUI.sln
and click Properties, you'll see the Location is C:\Users\Public\Documents\IntervalZero\KINGSTAR SDK\<Version Number>\Samples\GUI\QtGUI
, which is the full path. Notice that in the hierarchy path it is Public Documents
. If you are using a non-English Windows system, and you want to copy and paste the path to the address bar to find the sample quickly, you must use the full path. If you want to browse to the sample folder through clicks, use the hierarchy path. For English Windows, folder redirection is done automatically. Even if you paste the hierarchy path, File Explorer can lead you to the sample.
![]() |
![]() |
Output
The figure below shows the output of the sample:
Source code
The sample is a Qt application developed using C++ in Visual Studio 2019, and Qt Framework 5.12.9. When developing your own applications, you can choose your own development environment, as long as the application is 64-bit. The use of 64-bit is required to control the real-time Subsystem.
The main source code is contained in the following files:
- main.cpp: generates the Qt GUI window.
- ksworker.cpp: contains all KINGSTAR functions.
- QtGui.cpp: defines how Qt GUI elements work.
- ksworker.h: contains all declarations of KINGSTAR and QTimer variables and functions.
- QtGui.h: contains all declarations of Qt GUI variables and functions. It also contains the ksWorker class.
When you view code, start from QtGui.cpp, and see ksworker.h and ksworker.cpp when the code refers to KINGSTAR functions.
Link the Win32 functions to the Qt GUI
Before you start writing code, you should have built a Qt GUI. The layout of the GUI can be customized to meet your needs. In this sample, we use only the basic components to demonstrate how to link the Win32 functions to the GUI.
The way the Qt GUI works is different from other GUI samples. Qt uses signals and slots to define the interaction between GUI elements and functions. A signal is the behavior of a GUI element. A slot is a function that is called when the signal is triggered. A signal and a slot is connected by the connect function. In QtGui.cpp you'll find each GUI element is described like this:
QObject::connect(ui->btnConnect, &QPushButton::clicked, this, &QtGui::btnConnectClicked);
In the above example, a button is named btnConnect
, which has a signal clicked. When clicked is triggered, the slot btnConnectClicked is called. The Qt program, this, receives and handles the signal.
Components
This section introduces the following components: