跳转至

QML

QML Article Link

QML Book

Example

Simple.qmlproject

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
/* File generated by Qt Creator */

import QmlProject 1.1

Project {
    mainFile: "Simple.qml"

    /* Include .qml, .js, and image files from current directory and subdirectories */
    QmlFiles {
        directory: "."
    }
    JavaScriptFiles {
        directory: "."
    }
    ImageFiles {
        directory: "."
    }
    /* List of plugin directories passed to QML runtime */
    // importPaths: [ "asset_imports" ]
}

Simple.qml

QML
1
2
3
4
5
6
7
8
import QtQuick

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
}

Hello World

QML
1
2
3
4
5
import QtQuick

Text {
    text: "Hello World!"
}

command line run

Text Only
1
c:/local/Qt/6.7.0/msvc2019_64/bin/qml.exe ./HelloWorld.qml 

typical results:

Text Only
1
PS D:\work\qt_2024_work\ModernQt\codes\QML\HelloWorld\01> c:/local/Qt/6.7.0/msvc2019_64/bin/qml.exe ./HelloWorld.qml

QML Image: Cannot open - CMake qrc

CMake
1
set(CMAKE_AUTORCC ON)

glsl Shader

Text Only
1
2
3
set path=D:\Qt\Tools\QtDesignStudio\qt6_design_studio_reduced_version\bin
qsb --glsl 100es,120,150 --hlsl 50 --msl 12    -o default.frag.qsb default.frag
qsb --glsl 100es,120,150 --hlsl 50 --msl 12 -b -o default.vert.qsb default.vert

my pc

Text Only
1
2
3
set path=c:\local\Qt\Tools\QtDesignStudio\qt6_design_studio_reduced_version\bin\
qsb --glsl 100es,120,150 --hlsl 50 --msl 12    -o default.frag.qsb default.frag
qsb --glsl 100es,120,150 --hlsl 50 --msl 12 -b -o default.vert.qsb default.vert

default.frag

C++
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#version 440

layout(location=0) in vec2 qt_TexCoord0;
layout(location=0) out vec4 fragColor;

layout(std140, binding=0) uniform buf {
    mat4 qt_Matrix;
    float qt_Opacity;
} ubuf;

layout(binding=1) uniform sampler2D source;

void main(){
    fragColor = texture(source, qt_TexCoord0) * ubuf.qt_Opacity;
}

default.vert

C++
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#version 440

layout(location=0) in vec4 qt_Vertex;
layout(location=1) in vec2 qt_MultiTexCoord0;

layout(location=0) out vec2 qt_TexCoord0;

layout(std140, binding=0) uniform buf {
    mat4 qt_Matrix;
    float qt_Opacity;
} ubuf;

out gl_PerVertex {
    vec4 gl_Position;
};

void main(){
    qt_TexCoord0 = qt_MultiTexCoord0;
    gl_Position = ubuf.qt_Matrix * qt_Vertex;
}

frag example

C++
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#version 440

layout(location=0) in vec2 qt_TexCoord0;
layout(location=0) out vec4 fragColor;

layout(std140, binding=0) uniform buf {
    mat4 qt_Matrix;
    float qt_Opacity;
} ubuf;

layout(binding=1) uniform sampler2D source;

void main(){
    vec4 tex = texture(source, qt_TexCoord0);
    fragColor = vec4(vec3(dot(tex.rgb,vec3(0.344,0.5,0.156))),tex.a) * ubuf.qt_Opacity;
}

red.frag

C++
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#version 440

layout(location=0) in vec2 qt_TexCoord0;
layout(location=0) out vec4 fragColor;

layout(std140, binding=0) uniform buf {
    mat4 qt_Matrix;
    float qt_Opacity;
} ubuf;

layout(binding=1) uniform sampler2D source;

void main(){
    fragColor = vec4(1.0,0.0,0.0,1.0);
}

frag example

C++
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#version 440

layout(location=0) in vec2 qt_TexCoord0;
layout(location=0) out vec4 fragColor;

layout(std140, binding=0) uniform buf {
    mat4 qt_Matrix;
    float qt_Opacity;

    float frequency;
    float amplitude;
    float time;
} ubuf;

layout(binding=1) uniform sampler2D source;

void main(){
    vec2 pulse = sin(ubuf.time - ubuf.frequency * qt_TexCoord0);
    vec2 coord = qt_TexCoord0 + ubuf.amplitude * vec2(pulse.x,-pulse.x);
    fragColor = texture(source, coord) * ubuf.qt_Opacity;
}

frag example

C++
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#version 440

layout(location=0) in vec2 qt_TexCoord0;
layout(location=0) out vec4 fragColor;

layout(std140, binding=0) uniform buf {
    mat4 qt_Matrix;
    float qt_Opacity;

    float frequency;
    float amplitude;
    float time;
} ubuf;

layout(binding=1) uniform sampler2D source;

void main(){
    vec2 pulse = sin(ubuf.time - ubuf.frequency * qt_TexCoord0);
    vec2 coord = qt_TexCoord0 + ubuf.amplitude * vec2(pulse.x,-pulse.x);
    fragColor = texture(source, coord) * ubuf.qt_Opacity;
}

vertex.vert example

C++
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#version 440

layout(location=0) in vec4 qt_Vertex;
layout(location=1) in vec2 qt_MultiTexCoord0;

layout(location=0) out vec2 qt_TexCoord0;

layout(std140, binding=0) uniform buf {
    mat4 qt_Matrix;
    float qt_Opacity;

    float minimize;
    float width;
    float height;
    float bend;
    float side;
} ubuf;

out gl_PerVertex {
    vec4 gl_Position;
};

void main(){
    qt_TexCoord0 = qt_MultiTexCoord0;
    vec4 pos = qt_Vertex;
    pos.y = mix(qt_Vertex.y, ubuf.height, ubuf.minimize);
    pos.x = mix(qt_Vertex.x, ubuf.width, ubuf.minimize);
    float t = pos.y / ubuf.height;
    t = ( 3.0 - 2.0 * t ) * t * t;
    //pos.x = mix(qt_Vertex.x, ubuf.side * ubuf.width, t * ubuf.bend);
    gl_Position = ubuf.qt_Matrix * pos;
}

sprite.vert example

C++
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#version 440

layout(location=0) in vec4 qt_Vertex;
layout(location=1) in vec2 qt_MultiTexCoord0;

layout(location=0) out vec2 qt_TexCoord0;

layout(std140, binding=0) uniform buf {
    mat4 qt_Matrix;
    float qt_Opacity;

    float minimize;
    float width;
    float height;
    float bend;
    float side;
} ubuf;

out gl_PerVertex {
    vec4 gl_Position;
};

void main(){
    qt_TexCoord0 = qt_MultiTexCoord0;
    vec4 pos = qt_Vertex;
    pos.y = mix(qt_Vertex.y, ubuf.height, ubuf.minimize);
    //pos.x = mix(qt_Vertex.x, ubuf.width, ubuf.minimize);
    float t = pos.y / ubuf.height;
    t = ( 3.0 - 2.0 * t ) * t * t;
    pos.x = mix(qt_Vertex.x, ubuf.side * ubuf.width, t * ubuf.bend);
    gl_Position = ubuf.qt_Matrix * pos;
}

default picture saved position

Text Only
1
c:\Users\eric\Pictures\

balsamui.exe location

Text Only
1
c:\local\Qt\Tools\QtDesignStudio\qt6_design_studio_reduced_version\bin\balsamui.exe

QML_XHR_ALLOW_FILE_READ

run.bat

Text Only
1
2
set QML_XHR_ALLOW_FILE_READ=1
"c:\local\Qt\Tools\QtCreator\bin\qtcreator.exe"

venv

Text Only
1
2
py.exe -m venv venv
venv\Scripts\activate

results

Text Only
1
2
PS D:\work\qt_2024_work\ModernQt\codes\QML\restapi\01a\restapi\restservice> venv\Scripts\activate
(venv) PS D:\work\qt_2024_work\ModernQt\codes\QML\restapi\01a\restapi\restservice>

Flask

Text Only
1
2
3
https://flask.palletsprojects.com
py.exe -m venv venv
venv\Scripts\activate

Install Flask

Text Only
1
pip install Flask

upgrade pip

Text Only
1
2
python.exe -m pip install --upgrade pip
py.exe -m pip install --upgrade pip

run flask

Text Only
1
flask --app server run

json load problem

Python
1
json.load(file('colors.json', 'r'))

error

Text Only
1
2
3
colors = json.load(file('colors.json', 'r'))
                       ^^^^
NameError: name 'file' is not defined. Did you mean: 'filter'?

Python
1
2
3
4
5
6
# Opening JSON file
f = open('data.json')

# returns JSON object as 
# a dictionary
data = json.load(f)

OfflineStorage

Text Only
1
"C:\\Users\\eric\\AppData\\Roaming\\applocalstorage\\QML\\OfflineStorage\\Databases\\d41d8cd98f00b204e9800998ecf8427e"

plugin

default

Text Only
1
2
Object class-name: MyItem
URI: com.mycompany.qmlcomponents

simple example

Text Only
1
2
Object class-name: CppModel
URI: com.eric.cppModel

cmake qtquick

Text Only
1
cmake -DCMAKE_PREFIX_PATH=c:\local\Qt\6.7.0\msvc2019_64\lib\cmake\