QML and Qt Quick
2019.04.10 23:02

QML 전역 객체 (Global Object)

조회 수 4883 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

QML에는 JavaScript의 전역객체 뿐만아니라 내장된 QML전용의 몇가지 전역객체를 제공한다. QtQuick 모듈이 import되었다면 추가 import없이 QML에 로드 된 모든 전역객체 및 helper method, enum등을 사용할 수 있다.

 

"Qt"객체는 유틸리티 함수, 속성 및 Qt 네임 스페이스에서 사용 가능한 enum을 포함한 전역 객체이다. 인스턴스화를 할 필요없다. 즉, new를 이용한 객체를 생성하지 않는다. 이것을 사용하려면 다음의 예처럼 사용할 수 있다.

import QtQuick 2.12
import QtQuick.Controls 1.4

Text{
    text: Qt.md5("https://makersweb.net")
    font.pixelSize: 25
    font.family: fonts.currentText
    color: Qt.rgba(0, 0.5, 1, 1)
}

ComboBox{
    id: fonts
    width: 150
    model: Qt.fontFamilies()
}

Qt_object.png

Enums

Qt 라이브러리 전체에서 사용되는 enum을 사용할 수 있다. 예를 들면 Qt.Key_Q, Qt.Key_1, Qt.Key_Enter 처럼 key 타입을 나타내는 열거형등을 사용할 수 있다. 

 

동적객체 생성 함수

다음 함수를 사용하면 파일이나 문자열에서 QML 항목을 동적으로 만들 수 있다. 

Qt.createComponent(url)

Qt.createQmlObject(string qml, object parent, string filepath)

 

다음은 문자열에서 QML 항목을 동적생성하는 예제이다.

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    id: window
    visible: true
    width: 640
    height: 480

    // 문자열 QML코드
    property string qmlstring: {
        "
        import QtQuick 2.12

        Rectangle{
            anchors.centerIn: parent
            width: 300
            height: 100
            border.width: 1

            Text {
                id: title
                anchors.centerIn: parent
                font.pixelSize: 20
                text: qsTr('makersweb.net')
            }
        }
        "
    }

    Text{
        text: "click me"
        font.pixelSize: 25
        anchors.centerIn: parent

        MouseArea{
            anchors.fill: parent
            onClicked: {
                // 문자열 QML코드를 동적으로 생성
                Qt.createQmlObject(qmlstring, window)
            }
        }
    }
}

 

clickme.png

makersweb.png

 

TAG •

  1. No Image notice

    Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서

    Date2019.01.05 CategoryQML and Qt Quick By운영자 Views118359
    read more
  2. No Image

    main함수 명령줄 옵션 해석

    Date2020.09.01 CategoryC++ Class Bymakersweb Views7104
    Read More
  3. No Image

    Qt 6.0의 개발 호스트 및 대상 플랫폼

    Date2020.09.16 CategoryQt 6 Bymakersweb Views6556
    Read More
  4. No Image

    Qt 6에서 QList 변경사항

    Date2020.10.08 CategoryQt 6 Bymakersweb Views4567
    Read More
  5. No Image

    QRandomGenerator 클래스를 사용하여 난수(random values) 생성

    Date2020.10.17 CategoryC++ Class Bymakersweb Views5574
    Read More
  6. No Image

    Qt 6의 비동기 API

    Date2020.10.19 CategoryQt 6 Bymakersweb Views4891
    Read More
  7. No Image

    QML과 코루틴(Coroutines)

    Date2020.11.03 CategoryQML and Qt Quick Bymakersweb Views4566
    Read More
  8. No Image

    QML 바인딩 끊김 진단

    Date2020.11.08 CategoryQML and Qt Quick Bymakersweb Views4371
    Read More
  9. Qt Quick Controls 2에 네이티브 데스크탑 스타일 추가

    Date2020.11.23 CategoryQt 6 Bymakersweb Views5312
    Read More
  10. No Image

    Qt5Compat 라이브러리를 사용하여 Qt5에서 Qt6로 포팅

    Date2020.12.05 CategoryQt 6 Bymakersweb Views4197
    Read More
  11. No Image

    그래픽 소프트웨어에서 디자인 내보내기 (Exporting Designs from Graphics Software)

    Date2020.12.25 CategoryQML and Qt Quick Byj2doll Views3849
    Read More
  12. No Image

    QThread 및 QMutex 예제

    Date2021.01.12 CategoryC++ Class Bymakersweb Views5754
    Read More
  13. No Image

    Loader를 사용하여 동적으로 QML 로드

    Date2021.01.19 CategoryQML and Qt Quick Bymakersweb Views5873
    Read More
  14. Qt 를 사용하거나 기반으로 하는 응용프로그램

    Date2021.01.30 CategoryGeneral and Desktop Bymakersweb Views9062
    Read More
  15. Qt MQTT의 pus/sub 튜토리얼

    Date2021.02.06 CategoryMobile and Embedded Bymakersweb Views6140
    Read More
  16. C++로 작성한 클래스를 QML에서 생성

    Date2021.02.10 CategoryQML and Qt Quick Bymakersweb Views9478
    Read More
  17. Qt 5 코드를 Qt 6로 포팅하기 위해 도움이 되는 Clazy Framework

    Date2021.03.01 CategoryQt 6 Bymakersweb Views4597
    Read More
  18. No Image

    QML과 JavaScript 의 숫자 관련 내장된 함수

    Date2021.03.28 CategoryQML and Qt Quick Bymakersweb Views6178
    Read More
  19. No Image

    Qt 6 에서 프로퍼티 바인딩

    Date2021.04.03 CategoryQt 6 Bymakersweb Views4110
    Read More
  20. No Image

    응용프로그램 자동실행 설정 (on Windows)

    Date2021.05.08 CategoryC++ Class Bymakersweb Views4082
    Read More
  21. No Image

    싱글 샷(Single-Shot) 시그널/슬롯 연결

    Date2021.05.12 CategoryQt 6 Bymakersweb Views6471
    Read More
Board Pagination Prev 1 5 6 7 8 9 Next
/ 9