A Short Course on QT
A Short Course on QT
项目类别:计算机

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.

Project

Step 3

void MainWindow::on_horizontalScrollBar_valueChanged(int value)

{

ui->lcdNumber_maxEpochs->setSegmentStyle(QLCDNumber::Filled);

ui->lcdNumber_maxEpochs->display(value);

maxEpochs = value;

}

void MainWindow::on_pushButton_Calculate_clicked()

{

float result=0.0;

result = maxEpochs * 2.2; //some hypothetical formula

ui->lcdNumber_result->display(result);

update();

QCoreApplication::processEvents();

}

Sample run.

Project

Step 4

pushButton_Calculate

Performs a simple calculation:

30 * 2.2

Project

Mouse cursor How to change the mouse cursor to indicate busy

calculation activity.

Add the following header first, in order to access

the mouse cursor methods:

#include <QApplication>

QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

//perform lengthy operations here…

QApplication::restoreOverrideCursor();

Add more widgets

Project

Step 5

pushButton

plainTextEdit_results

留学ICU™️ 留学生辅助指导品牌
在线客服 7*24 全天为您提供咨询服务
咨询电话(全球): +86 17530857517
客服QQ:2405269519
微信咨询:zz-x2580
关于我们
微信订阅号
© 2012-2021 ABC网站 站点地图:Google Sitemap | 服务条款 | 隐私政策
提示:ABC网站所开展服务及提供的文稿基于客户所提供资料,客户可用于研究目的等方面,本机构不鼓励、不提倡任何学术欺诈行为。