KEMBAR78
QT 프로그래밍 기초(basic of QT programming tutorial) | PDF
Basic Programming Tutorial
Han Sol Kang
October 5, 2018
2
Contents
Installation
Qt application
Introduction
Example
October 5, 2018
3
Introduction
Haavard Nord(left) and
Eirik Chambe-Eng(right)
Qt (/kjuːt/ "cute") : a cross-platform application framework that is widely used for
developing application software
“Write once, compile anywhere” (WOCA)
“Q”
“t”
Haavard's Emacs typeface
Inspired by Xt (X toolkit)
October 5, 2018
4
Introduction
A modern user interface that is beautiful on every screen and performs
perfectly on every platform is not an option, it’s a necessity.
— 8 of Top 10 Fortune 500 companies use Qt —
October 5, 2018
5
Introduction
If you want to know just what’s possible with Qt, all you have to do is look at
how some of the leading companies in more than 70 industries are powering
millions of devices all over the world including Rimac, Formlabs, AMD,
Ubuntu, Imaginando, Xsens, Dolby Labs, Tableau, Holoplot, Ulstein, NXP, and
many more.
October 5, 2018
6
Introduction
 Supported Platforms (Officially)
Windows
Windows 10 (64-bit) MSVC 2015
Windows 10 (32-bit) MSVC 2015
Windows 8.1 (64-bit) MSVC 2015, MSVC 2013, MinGW 5.3
, MinGW 4.9, MinGW 4.8
Windows 8.1 (32-bit) MSVC 2015, MSVC 2013, MinGW 5.3
, MinGW 4.9, MinGW 4.8
Windows 7 (64-bit) MSVC 2015, MSVC 2013, MinGW 5.3
, MinGW 4.9, MinGW 4.8
Windows 7 (32-bit) MSVC 2015, MSVC 2013, MinGW 5.3
, MinGW 4.9, MinGW 4.8
Mobile Platforms: Android, iOS, WinRT
Windows Phone 8.1 (arm) MSVC 2013
Windows Runtime (x86, x86_64,
arm)
MSVC 2015, MSVC 2013
iOS 6 and above Clang as provided by Apple
Android (API Level: 16) GCC as provided by Google
Linux/X11
openSUSE 13.1 (64-bit) GCC 4.8.1
Red Hat Enterprise Linux 6.6 (64-bit) GCC 4.9.1
Ubuntu 14.04 (64-bit) GCC 4.6.3
(Linux 32/64-bit) GCC 4.8.1, GCC 4.9.1
OS X
OS X 10.8, 10.9, 10.10, 10.11 Clang as provided by Apple
Embedded Platforms: Embedded Linux, QNX
Embedded Linux GCC
QNX 6.6.0 (armv7le and x86) As provided by QNX
7
Installation
October 5, 2018
Browser
https://www.qt.io/
 Download Qt
October 5, 2018
8
Installation
 Set up Qt
October 5, 2018
9
Installation
 Visual studio extension
October 5, 2018
10
Installation
 Visual studio extension
October 5, 2018
11
Installation
 Visual studio extension
October 5, 2018
12
Installation
 Visual studio extension
October 5, 2018
13
Qt application
 Creating a Qt application
October 5, 2018
14
Qt application
 Creating a Qt application
October 5, 2018
15
Qt application
 Creating a Qt application
October 5, 2018
16
Qt application
 Structure of Qt application
October 5, 2018
17
Qt application
 Structure of Qt application
October 5, 2018
18
Qt application
 Concept of signal and slot
SIGNALEvent(Message)
SLOTEvent handler(Function)
ON_BN_CLICKED(id, memberFxn)
connect(sender, signal, receiver, member,
Qt::ConnectionType = Qt::AutoConnection)
October 5, 2018
19
Qt application
 Concept of signal and slot
October 5, 2018
20
Qt application
 Concept of signal and slot
October 5, 2018
21
Qt application
 Concept of signal and slot
October 5, 2018
22
Qt application
 ImageShowUsingQt
October 5, 2018
23
Qt application
 QPushButton & QFileDialog
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_ImageShowUsingQt.h"
class ImageShowUsingQt : public QMainWindow
{
Q_OBJECT
public:
ImageShowUsingQt(QWidget *parent = Q_NULLPTR);
private:
Ui::ImageShowUsingQtClass ui;
};
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_ImageShowUsingQt.h"
#include "QFileDialog"
class ImageShowUsingQt : public QMainWindow
{
Q_OBJECT
public:
ImageShowUsingQt(QWidget *parent = Q_NULLPTR);
private:
Ui::ImageShowUsingQtClass ui;
private slots:
void LoadImage();
};
[ImageShowUsingQt.h]
October 5, 2018
24
Qt application
 QPushButton & QFileDialog
[ImageShowUsingQt.cpp]
#include "ImageShowUsingQt.h"
ImageShowUsingQt::ImageShowUsingQt(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
void ImageShowUsingQt::LoadImage()
{
ui.listWidget->clear();
HistoryImg.clear();
QString qsfileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "../", tr("Image Files (*.png
*.jpg *.bmp)"));
InputImg = imread(qsfileName.toStdString());
ShowImage(InputImg);
HistoryImg.push_back(InputImg);
ui.listWidget->addItem("Original Image");
}
QString getOpenFileName(QWidget *parent = Q_NULLPTR,
const QString &caption = QString(),
const QString &dir = QString(),
const QString &filter = QString(),
QString *selectedFilter = Q_NULLPTR,
Options options = Options());
October 5, 2018
25
Qt application
 QPushButton & QFileDialog
[QString & std::string]
QString -> std::string
std::string -> QString
QString qstring;
std::string stdstring;
stdstring = qstring.toStdString();
QString qstring;
std::string stdstring;
qstring.fromStdString(stdstring);
October 5, 2018
26
Qt application
 QRadioButton & QLineEdit
void ImageShowUsingQt::Processing()
{
//lineedit
lowthresh = ui.Lowvalue->text().toInt();
highthresh = ui.Highvalue->text().toInt();
//flag
//-1 : default, 0 : sobel, 1 : Canny
int flag = -1;
if (ui.SobelButton->isChecked()) flag = 0;
if (ui.CannyButton->isChecked()) flag = 1;
if (flag == -1)
{
return;
}
else if (flag == 0)
{
cvtColor(InputImg, OutputImg, CV_BGR2GRAY);
Sobel(OutputImg, OutputImg, CV_8UC1, 1, 1, 5);
cvtColor(OutputImg, OutputImg, CV_GRAY2BGR);
if (flag == -1)
{
return;
}
else if (flag == 0)
{
cvtColor(InputImg, OutputImg, CV_BGR2GRAY);
Sobel(OutputImg, OutputImg, CV_8UC1, 1, 1, 5);
cvtColor(OutputImg, OutputImg, CV_GRAY2BGR);
ShowImage(OutputImg);
HistoryImg.push_back(OutputImg);
ui.listWidget->addItem("Sobel");
}
else if (flag = 1)
{
cvtColor(InputImg, OutputImg, CV_BGR2GRAY);
Canny(OutputImg, OutputImg, lowthresh, highthresh);
cvtColor(OutputImg, OutputImg, CV_GRAY2BGR);
ShowImage(OutputImg);
HistoryImg.push_back(OutputImg);
QString th;
th.sprintf("Canny (low : %d, high : %d)", lowthresh, highthresh);
ui.listWidget->addItem(th);
}
}
October 5, 2018
27
Qt application
 QCheckBox & QComboBox
{
Mat temp;
cvtColor(InputImg, temp, CV_BGR2GRAY);
cvtColor(temp, temp, CV_GRAY2BGR);
ShowImage(temp);
}
}
October 5, 2018
28
Qt application
 QCheckBox & QComboBox
void ImageShowUsingQt::Activation()
{
int i = ui.comboBox->currentIndex();
if (i == 0)
{
ui.RedButton->setCheckable(1);
ui.BlueButton->setCheckable(1);
ui.GreenButton->setCheckable(1);
}
else
{
ui.RedButton->setCheckable(0);
ui.BlueButton->setCheckable(0);
ui.GreenButton->setCheckable(0);
}
}
October 5, 2018
29
Qt application
 Dial
October 5, 2018
30
Qt application
 Dial
void ImageShowUsingQt::IntensityControl()
{
Mat temp;
vector<Mat> Channel;
cvtColor(InputImg, temp, CV_BGR2HSV);
split(temp, Channel);
Channel[2]+=ui.dial->value();
merge(Channel, temp);
cvtColor(temp, temp, CV_HSV2BGR);
ShowImage(temp);
}
October 5, 2018
31
Qt application
 QListWidget
void ImageShowUsingQt::ShowHistory()
{
int i = ui.listWidget->currentRow();
ShowImage(HistoryImg[i]);
}
void ImageShowUsingQt::Processing()
{
//lineedit
lowthresh = ui.Lowvalue->text().toInt();
highthresh = ui.Highvalue->text().toInt();
//flag
//-1 : default, 0 : sobel, 1 : Canny
int flag = -1;
if (ui.SobelButton->isChecked()) flag = 0;
if (ui.CannyButton->isChecked()) flag = 1;
if (flag == -1)
{
return;
}
else if (flag == 0)
{
cvtColor(InputImg, OutputImg, CV_BGR2GRAY);
Sobel(OutputImg, OutputImg, CV_8UC1, 1, 1, 5);
cvtColor(OutputImg, OutputImg, CV_GRAY2BGR);
ShowImage(OutputImg);
HistoryImg.push_back(OutputImg);
ui.listWidget->addItem("Sobel");
}
else if (flag = 1)
{
cf. Processing
October 5, 2018
32
Qt application
 QGraphicsView
void ImageShowUsingQt::ShowImage(Mat image)
{
image.copyTo(LastImg);
scene.clear();
QImage qimg(image.data, image.cols, image.rows, QImage::Format_RGB888);
scene.addPixmap(QPixmap::fromImage(qimg.rgbSwapped()));
ui.graphicsView->setScene(&scene);
ui.graphicsView->show();
}
October 5, 2018
33
Qt application
 ImageShowUsingQt - Demo
October 5, 2018
Q & A

QT 프로그래밍 기초(basic of QT programming tutorial)

  • 1.
  • 2.
    October 5, 2018 2 Contents Installation Qtapplication Introduction Example
  • 3.
    October 5, 2018 3 Introduction HaavardNord(left) and Eirik Chambe-Eng(right) Qt (/kjuːt/ "cute") : a cross-platform application framework that is widely used for developing application software “Write once, compile anywhere” (WOCA) “Q” “t” Haavard's Emacs typeface Inspired by Xt (X toolkit)
  • 4.
    October 5, 2018 4 Introduction Amodern user interface that is beautiful on every screen and performs perfectly on every platform is not an option, it’s a necessity. — 8 of Top 10 Fortune 500 companies use Qt —
  • 5.
    October 5, 2018 5 Introduction Ifyou want to know just what’s possible with Qt, all you have to do is look at how some of the leading companies in more than 70 industries are powering millions of devices all over the world including Rimac, Formlabs, AMD, Ubuntu, Imaginando, Xsens, Dolby Labs, Tableau, Holoplot, Ulstein, NXP, and many more.
  • 6.
    October 5, 2018 6 Introduction Supported Platforms (Officially) Windows Windows 10 (64-bit) MSVC 2015 Windows 10 (32-bit) MSVC 2015 Windows 8.1 (64-bit) MSVC 2015, MSVC 2013, MinGW 5.3 , MinGW 4.9, MinGW 4.8 Windows 8.1 (32-bit) MSVC 2015, MSVC 2013, MinGW 5.3 , MinGW 4.9, MinGW 4.8 Windows 7 (64-bit) MSVC 2015, MSVC 2013, MinGW 5.3 , MinGW 4.9, MinGW 4.8 Windows 7 (32-bit) MSVC 2015, MSVC 2013, MinGW 5.3 , MinGW 4.9, MinGW 4.8 Mobile Platforms: Android, iOS, WinRT Windows Phone 8.1 (arm) MSVC 2013 Windows Runtime (x86, x86_64, arm) MSVC 2015, MSVC 2013 iOS 6 and above Clang as provided by Apple Android (API Level: 16) GCC as provided by Google Linux/X11 openSUSE 13.1 (64-bit) GCC 4.8.1 Red Hat Enterprise Linux 6.6 (64-bit) GCC 4.9.1 Ubuntu 14.04 (64-bit) GCC 4.6.3 (Linux 32/64-bit) GCC 4.8.1, GCC 4.9.1 OS X OS X 10.8, 10.9, 10.10, 10.11 Clang as provided by Apple Embedded Platforms: Embedded Linux, QNX Embedded Linux GCC QNX 6.6.0 (armv7le and x86) As provided by QNX
  • 7.
  • 8.
  • 9.
    October 5, 2018 9 Installation Visual studio extension
  • 10.
    October 5, 2018 10 Installation Visual studio extension
  • 11.
    October 5, 2018 11 Installation Visual studio extension
  • 12.
    October 5, 2018 12 Installation Visual studio extension
  • 13.
    October 5, 2018 13 Qtapplication  Creating a Qt application
  • 14.
    October 5, 2018 14 Qtapplication  Creating a Qt application
  • 15.
    October 5, 2018 15 Qtapplication  Creating a Qt application
  • 16.
    October 5, 2018 16 Qtapplication  Structure of Qt application
  • 17.
    October 5, 2018 17 Qtapplication  Structure of Qt application
  • 18.
    October 5, 2018 18 Qtapplication  Concept of signal and slot SIGNALEvent(Message) SLOTEvent handler(Function) ON_BN_CLICKED(id, memberFxn) connect(sender, signal, receiver, member, Qt::ConnectionType = Qt::AutoConnection)
  • 19.
    October 5, 2018 19 Qtapplication  Concept of signal and slot
  • 20.
    October 5, 2018 20 Qtapplication  Concept of signal and slot
  • 21.
    October 5, 2018 21 Qtapplication  Concept of signal and slot
  • 22.
    October 5, 2018 22 Qtapplication  ImageShowUsingQt
  • 23.
    October 5, 2018 23 Qtapplication  QPushButton & QFileDialog #pragma once #include <QtWidgets/QMainWindow> #include "ui_ImageShowUsingQt.h" class ImageShowUsingQt : public QMainWindow { Q_OBJECT public: ImageShowUsingQt(QWidget *parent = Q_NULLPTR); private: Ui::ImageShowUsingQtClass ui; }; #pragma once #include <QtWidgets/QMainWindow> #include "ui_ImageShowUsingQt.h" #include "QFileDialog" class ImageShowUsingQt : public QMainWindow { Q_OBJECT public: ImageShowUsingQt(QWidget *parent = Q_NULLPTR); private: Ui::ImageShowUsingQtClass ui; private slots: void LoadImage(); }; [ImageShowUsingQt.h]
  • 24.
    October 5, 2018 24 Qtapplication  QPushButton & QFileDialog [ImageShowUsingQt.cpp] #include "ImageShowUsingQt.h" ImageShowUsingQt::ImageShowUsingQt(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); } void ImageShowUsingQt::LoadImage() { ui.listWidget->clear(); HistoryImg.clear(); QString qsfileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "../", tr("Image Files (*.png *.jpg *.bmp)")); InputImg = imread(qsfileName.toStdString()); ShowImage(InputImg); HistoryImg.push_back(InputImg); ui.listWidget->addItem("Original Image"); } QString getOpenFileName(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = Q_NULLPTR, Options options = Options());
  • 25.
    October 5, 2018 25 Qtapplication  QPushButton & QFileDialog [QString & std::string] QString -> std::string std::string -> QString QString qstring; std::string stdstring; stdstring = qstring.toStdString(); QString qstring; std::string stdstring; qstring.fromStdString(stdstring);
  • 26.
    October 5, 2018 26 Qtapplication  QRadioButton & QLineEdit void ImageShowUsingQt::Processing() { //lineedit lowthresh = ui.Lowvalue->text().toInt(); highthresh = ui.Highvalue->text().toInt(); //flag //-1 : default, 0 : sobel, 1 : Canny int flag = -1; if (ui.SobelButton->isChecked()) flag = 0; if (ui.CannyButton->isChecked()) flag = 1; if (flag == -1) { return; } else if (flag == 0) { cvtColor(InputImg, OutputImg, CV_BGR2GRAY); Sobel(OutputImg, OutputImg, CV_8UC1, 1, 1, 5); cvtColor(OutputImg, OutputImg, CV_GRAY2BGR); if (flag == -1) { return; } else if (flag == 0) { cvtColor(InputImg, OutputImg, CV_BGR2GRAY); Sobel(OutputImg, OutputImg, CV_8UC1, 1, 1, 5); cvtColor(OutputImg, OutputImg, CV_GRAY2BGR); ShowImage(OutputImg); HistoryImg.push_back(OutputImg); ui.listWidget->addItem("Sobel"); } else if (flag = 1) { cvtColor(InputImg, OutputImg, CV_BGR2GRAY); Canny(OutputImg, OutputImg, lowthresh, highthresh); cvtColor(OutputImg, OutputImg, CV_GRAY2BGR); ShowImage(OutputImg); HistoryImg.push_back(OutputImg); QString th; th.sprintf("Canny (low : %d, high : %d)", lowthresh, highthresh); ui.listWidget->addItem(th); } }
  • 27.
    October 5, 2018 27 Qtapplication  QCheckBox & QComboBox { Mat temp; cvtColor(InputImg, temp, CV_BGR2GRAY); cvtColor(temp, temp, CV_GRAY2BGR); ShowImage(temp); } }
  • 28.
    October 5, 2018 28 Qtapplication  QCheckBox & QComboBox void ImageShowUsingQt::Activation() { int i = ui.comboBox->currentIndex(); if (i == 0) { ui.RedButton->setCheckable(1); ui.BlueButton->setCheckable(1); ui.GreenButton->setCheckable(1); } else { ui.RedButton->setCheckable(0); ui.BlueButton->setCheckable(0); ui.GreenButton->setCheckable(0); } }
  • 29.
    October 5, 2018 29 Qtapplication  Dial
  • 30.
    October 5, 2018 30 Qtapplication  Dial void ImageShowUsingQt::IntensityControl() { Mat temp; vector<Mat> Channel; cvtColor(InputImg, temp, CV_BGR2HSV); split(temp, Channel); Channel[2]+=ui.dial->value(); merge(Channel, temp); cvtColor(temp, temp, CV_HSV2BGR); ShowImage(temp); }
  • 31.
    October 5, 2018 31 Qtapplication  QListWidget void ImageShowUsingQt::ShowHistory() { int i = ui.listWidget->currentRow(); ShowImage(HistoryImg[i]); } void ImageShowUsingQt::Processing() { //lineedit lowthresh = ui.Lowvalue->text().toInt(); highthresh = ui.Highvalue->text().toInt(); //flag //-1 : default, 0 : sobel, 1 : Canny int flag = -1; if (ui.SobelButton->isChecked()) flag = 0; if (ui.CannyButton->isChecked()) flag = 1; if (flag == -1) { return; } else if (flag == 0) { cvtColor(InputImg, OutputImg, CV_BGR2GRAY); Sobel(OutputImg, OutputImg, CV_8UC1, 1, 1, 5); cvtColor(OutputImg, OutputImg, CV_GRAY2BGR); ShowImage(OutputImg); HistoryImg.push_back(OutputImg); ui.listWidget->addItem("Sobel"); } else if (flag = 1) { cf. Processing
  • 32.
    October 5, 2018 32 Qtapplication  QGraphicsView void ImageShowUsingQt::ShowImage(Mat image) { image.copyTo(LastImg); scene.clear(); QImage qimg(image.data, image.cols, image.rows, QImage::Format_RGB888); scene.addPixmap(QPixmap::fromImage(qimg.rgbSwapped())); ui.graphicsView->setScene(&scene); ui.graphicsView->show(); }
  • 33.
    October 5, 2018 33 Qtapplication  ImageShowUsingQt - Demo
  • 34.