๐ QT์ฌ์ฉ์ ํ๋ก ํธ์๋ ๋์์ธ์ QT Creator์์ widget์ผ๋ก ๋ง๋ค ์ ์์ต๋๋ค.(๊ธฐ์กด ๋ฐฉ์)
When using QT, you can create front-end designs as widgets in QT Creator (existing method).
๐ QML์ QT๋ก ๋ง๋ค ์ฑ์ ๋์์ธ์ ๋ง๋๋ ์๋ก์ด ๋ฐฉ์์
๋๋ค.
QML is a new way to create designs for apps built with QT.
๐ QT Design Studio์ ์ฌ์ฉํ๋ฉด ์ง์ ๋ค ์ฝ๋ฉํ์ง์์๋ QML Code๋ฅผ ์์ฑ ํ ์ ์์ต๋๋ค.
QT Design Studio lets you generate QML code without having to code it yourself.
-๐QT Design Studio๋ Qt Creator์ค์นํ ๋ ์ด๋ฏธ ์ค์นํ์ต๋๋ค.
QT Design Studio was already installed when you installed Qt Creator.
๐ ์ค์น ์์น๋ Qt Creator์ ๋์ผํฉ๋๋ค.
The installation location is the same as Qt Creator.
๐1.QT Design Studio๋ก ๋์์ธ ๋ง๋ค๊ธฐ / Create designs with QT Design Studio
โ๏ธQT Desing Studio ํ๋ก์ ํธ ์์ฑ : Desktop ์ ํํ์
์ ํ๋ก์ ํธ ์์ฑํ์๋ฉด ๋ฉ๋๋ค.
Create a QT Design Studio project: Select Desktop and create a project.
โ๏ธ ์ข์ธก ์๋จ์ LIve Preview์ ํํ์๊ณ ์ธ๋ชจ ์์ด์ฝ์ ํด๋ฆญํ์๋ฉด ํ๋ฆฌ๋ทฐ๋ฅผ ๋ณด์ค ์ ์์ต๋๋ค.
You can see the preview by selecting LIve Preview in the upper left corner and clicking the triangle icon.

โ๏ธ QT Desing Studio ์ข์ธก ๋ฉ๋ด์์ ๊ทธ๋ฅ ํ๋ฉด์ ๋์ด๋ ๋์ผ๋ฉด ๋ฉ๋๋ค.
You can simply drag and drop it onto the screen from the left menu in QT Design Studio.
โ๏ธ ํ๋ฉด ๊ตฌ์ฑ์ด ์ ์๋๋ฉด codeํญ์์ ์ฝ๋๋ฅผ ์ง์ ์์ ํ์๋ฉด ๋ฉ๋๋ค.
If the screen configuration is not correct, you can directly edit the code in the code tab.
โ๏ธ 2D,Codeํญ์ด ์๋ณด์ด๋ฉด ๋ฉ๋ด์์ VIew->Views์ ๋ณด์๋ฉด 2D,Code ์ฒดํฌ ํ ์ ์์ต๋๋ค.
If you don’t see the 2D, Code tab, go to View->Views in the menu and check 2D, Code.



๐2.QT Creator์์ QML ์ ์ฉํ๊ธฐ / Applying QML in QT Creator
โ๏ธ QT Design Studio ํ๋ก์ ํธ ํด๋์ ๊ฐ๋ณด์๋ฉด ์ ์ ๊ฒฝ์ฐ๋ ์ด๋ ๊ฒ ๋ง๋ค์ด์ ธ ์์ต๋๋ค.
If you go to the QT Design Studio project folder, in my case it is created like this.

โ๏ธScreen01.ui.qml์ด ํ์ผ์ QT Creator์์ ์ฌ์ฉํ์๋ฉด ๋ฉ๋๋ค.
You can use this file Screen01.ui.qml in QT Creator.
โ๏ธ ์ด ํ์ผ์ QT Creator์์ ์ฌ์ฉํ ๊ฒฝ์ฐ Screen01.ui.qml ์ฝ๋ ์์ ์ด ํ์ ํ ์๋ ์์ต๋๋ค.
If you use this file in QT Creator, you may need to modify the Screen01.ui.qml code.
โ๏ธ ์ฌ๋ฌ๋ถ์ ํ๊ฒฝ์ ๋ง๊ฒ ์์ ํ์๋ฉด ๋ฉ๋๋ค.
You can modify it to suit your environment.
โ๏ธ1)QMLํ์ผ ๋ณต์ฌ ๋ฐ ๋๋ ํ ๋ฆฌ ์ ๋ฆฌ / Copy QML files and organize directories
— ์์ Screen01.ui.qmlํ์ผ์ QT Creatorํ๋ก์ ํธ ๋๋ ํ ๋ฆฌ ๋ด์ qml๋๋ ํ ๋ฆฌ๋ฅผ ๋ง๋ค๊ณ ํ์ผ์ ๋ถ์ฌ ๋ฃ์ต๋๋ค.
Create a qml directory within the QT Creator project directory and paste the reen01.ui.qml file.
— ๋๋ ํ ๋ฆฌ๋ฅผ ๋ง๋ค๊ณ ํ์ผ์ ๋ถ์ฌ๋ฃ์ด๋ QT Creator์์๋ ๋ณด์ด์ง ์์ต๋๋ค.
Even if I create a directory and paste a file into it, it is not visible in QT Creator.
–QT Creator์ ๋ณด์ด๊ฒ ๋ง๋ค๋ ค๋ฉด CmakeLists.txtํ์ผ์ ์ด์ ํด์ผ ํฉ๋๋ค.
You need to edit the CmakeLists.txt file to make it visible in QT Creator.

โ๏ธ2)CmakeLists.txt ํ์ผ ์์ / Modify the CmakeLists.txt file
— CmakeLists.txt์ qmlํ์ผ์ ์ธ์ ํ ์ ์๊ฒ ๋ค์ ๋ด์ฉ์ ์ถ๊ฐ ํฉ๋๋ค.
Add the following to CmakeLists.txt to enable qml file recognition
— ํ์ผ์ ์์ ํ๊ณ ์ ์ฅํ๋ฉด ํ๋ก์ ํธ ์ฐฝ์ ํ์ผ์ด ๋ํ๋ฉ๋๋ค.
When you edit and save a file, it will appear in the project window.
# qml ํ์ผ๋ฑ๋ก / Registering qml file
qt_add_qml_module(appexample2
URI example2
VERSION 1.0
QML_FILES
Main.qml
qml/Screen01.qml
)

3)Main.qmlํ์ผ ์์ / Modify the Main.qml file
import QtQuick
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
// UI ํ์ผ ๋ก๋ฉ / UI file loading
Loader {
anchors.fill: parent
source: "qml/Screen01.qml"
}
}
๐3.์คํ / run
โ๏ธ ๋น๋ํ๋ฉด ์ด๋ ๊ฒ ํ๋ฉด์ ํ๋ก๊ทธ๋จ์ด ์คํ๋๋ ๋ชจ์ต์ ๋ณผ ์ ์์ต๋๋ค.
When you build, you will see the program running on the screen like this.

๐4.์ ์ฒด์ฝ๋ / Full Code
โ๏ธ qml/Screen01.qml
/*
This is a UI file (.ui.qml) that is intended to be edited in Qt Design Studio only.
It is supposed to be strictly declarative and only uses a subset of QML. If you edit
this file manually, you might introduce QML code that is not supported by Qt Design Studio.
Check out https://doc.qt.io/qtcreator/creator-quick-ui-forms.html for details on .ui.qml files.
*/
import QtQuick
import QtQuick.Controls
/*-- ํ์ผ์ ์ธ์ ๋ชปํจ --*/
// Constants.qmlํ์ผ์ ๋ถ๋ฌ์ค๊ธฐ
//import "Settings.qml" as Constants
Rectangle {
// id: rectangle
// width: Constants.width
// height: Constants.height
// color: Constants.backgroundColor
// ์์ ์ง์ ์ ์ธ
property int widthConst: 1920
property int heightConst: 1080
property color backgroundColorConst: "#EAEAEA"
width: widthConst
height: heightConst
color: backgroundColorConst
Column {
id: column
width: 200
anchors.centerIn: parent
spacing: 10
Rectangle {
width: 180
height: 30
color: "white"
border.color: "black"
TextEdit {
id: textEdit
anchors.fill: parent
width: 80
height: 20
text: qsTr("์
๋ ฅ1/input1")
font.pixelSize: 12
}
}
Rectangle {
width: 180
height: 30
color: "white"
border.color: "black"
TextEdit {
id: textEdit2
width: 80
height: 20
text: qsTr("์
๋ ฅ2/input2")
font.pixelSize: 12
}
}
Text {
id: text1
text: qsTr("๊ฐ์ถ๋ ฅ/Print Value")
font.pixelSize: 12
}
Button {
id: button
text: qsTr("Button")
}
}
}
โ๏ธ main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreationFailed,
&app,
[]() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("example2", "Main");
return app.exec();
}
โ๏ธ Main.qml
import QtQuick
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
// UI ํ์ผ ๋ก๋ฉ / UI file loading
Loader {
anchors.fill: parent
source: "qml/Screen01.qml"
}
}