A Short Course on QT
A cross-platform application framework
Download QT
Installation
1. Run the qt installer you’ve just downloaded.
2. Sign up to acquire a QT account.
3. Accept the license.
Installation
4. Specify installation folder.
5. Select QT 6.x desktop development.
6. Proceed with installation.
Project
Step 1 Create a Qt Project using the wizard.
Project
Select Qt Widgets Application. Step 2
Specify project name and location.
Project
Step 3
Avoid using folder names with a space character (or any foreign characters).
Define the build system
Project
Step 4
Select qmake as the build system.
Use the default base class.
Project
Step 5
Project
Optionally, specify a translation language
Select a Kit
Project
Step 6
Select Manage button to customise the Kit for your project.
Select MinGW 64-bit kit
Project
Step 7
Click the MinGW 64-bit kit
Qt versions
Project
Step 8
Under QT versions, select the latest version (e.g. Qt 6.5.1)
Compilers
Project
Step 9
Under Compilers tab, select MinGW for C++ and C. You may remove the other existing
compilers for the project (if there are any) as we don’t need them.
Debuggers
Project
Step 10
Under Debuggers, we will use the one that comes with MinGW. Click Apply, then OK buttons.
Project
Click Next to proceed.
Project
Click Finish.
Project
Files comprising the start-up codes.
This is the Edit view
Project
Build directory.
A build directory is automatically created for the LetterRecognition project.
Select Form, mainwindow.ui
Project
Step 11
Design view
Project
Step 12
Add a horizontal layout
Project
Step 13
Add a label
Project
Step 14
Project
Step 15
horizontalSlider_maxEpochs
Property value
Widgets
Add a horizontal slider.
Add an LCD number.
Project
Step 16
horizontalSlider_maxEpochs
lcdNumber_maxEpochs
Widgets
Property value
Project
Step 17 Switch to Edit mode, then add a new header file to the project.
Project
Switch to Edit mode, then add a header file to the
project.
Click next, then finish.
Switch to globalVariables.h, then add an external
variable declaration.
Project
Step 18
#ifndef GLOBALVARIABLES_H
#define GLOBALVARIABLES_H
extern int maxEpochs;
#endif // GLOBALVARIABLES_H
Switch to Design view by clicking main.cpp
Project
Step 19
#include <QApplication>
#include "mainwindow.h"
int maxEpochs;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Associate a function with the horizontal slider by
right-clicking it, then selecting Go to slot, then
the valueChanged() function.
Project
Step 20
#include "mainwindow.h"
#include "ui_mainwindow.h"
////////////////////////////////////////
#include "globalVariables.h“
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_horizontalSlider_maxEpochs_valueChanged(int value)
{
ui->lcdNumber_maxEpochs->setSegmentStyle(QLCDNumber::Filled);
ui->lcdNumber_maxEpochs->display(value);
maxEpochs = value;
}
Write the implementation for the valueChanged()
signal.
Project
Step 21
We now have an interface for the maxEpochs
global variable.
Project
Step 22
Add an LCD for displaying a calculated floating
point value.
Project
Step 1
lcdNumber_result
Improves readability
Add a pushButton.
Project
Step 2
pushButton_Calculate
Right-click the pushButton, then
select Go to slot to assign a
function to it’s clicked() signal.
Write the implementation for the clicked() signal,
inside mainwindow.cpp.