-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathengine.go
55 lines (47 loc) · 1.74 KB
/
engine.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package qamel
// #include <stdint.h>
// #include <stdlib.h>
// #include <string.h>
// #include <stdbool.h>
// #include "engine.h"
import "C"
import "unsafe"
// Engine is the wrapper for QQMLApplicationEngine
type Engine struct {
ptr unsafe.Pointer
}
// NewEngine creates a new QQmlApplicationEngine with the given parent.
// You will have to call load() later in order to load a QML file.
func NewEngine() Engine {
ptr := C.Engine_NewEngine()
return Engine{ptr: ptr}
}
// NewEngineWithSource constructs a QQmlApplicationEngine with the given QML source.
func NewEngineWithSource(source string) Engine {
engine := NewEngine()
engine.Load(source)
return engine
}
// Load loads the root QML file located at url. The object tree defined by the file is
// created immediately for local file urls.
func (engine Engine) Load(url string) {
if engine.ptr == nil {
return
}
cURL := C.CString(url)
defer C.free(unsafe.Pointer(cURL))
C.Engine_Load(engine.ptr, cURL)
}
// ClearComponentCache clears the engine's internal component cache. This function causes the property
// metadata of all components previously loaded by the engine to be destroyed. All previously loaded
// components and the property bindings for all extant objects created from those components will cease
// to function. This function returns the engine to a state where it does not contain any loaded
// component data. This may be useful in order to reload a smaller subset of the previous component set,
// or to load a new version of a previously loaded component. Once the component cache has been cleared,
// components must be loaded before any new objects can be created.
func (engine Engine) ClearComponentCache() {
if engine.ptr == nil {
return
}
C.Engine_ClearComponentCache(engine.ptr)
}