Skip to content

Using Live Reload

Radhi Fadlillah edited this page Dec 2, 2019 · 3 revisions

To enable live reload, all we need to do is start WatchResourceDir from the Viewer. For example, open the Hello World app, then modify main.go file into like this :

package main

import (
	"log"
	"os"
	fp "path/filepath"

	"github.com/go-qamel/qamel"
)

func main() {
	// Create application
	app := qamel.NewApplication(len(os.Args), os.Args)
	app.SetApplicationDisplayName("Live Reload Example")

	// Create a QML viewer
	// Here we change the source URL into relative path
	view := qamel.NewViewerWithSource("res/main.qml")
	view.SetResizeMode(qamel.SizeRootObjectToView)
	view.SetHeight(300)
	view.SetWidth(400)
	view.Show()

	// Watch change in resource dir
	projectDir, err := os.Getwd()
	if err != nil {
		log.Fatalln("Failed to get working directory:", err)
	}

	resDir := fp.Join(projectDir, "res")
	go view.WatchResourceDir(resDir)

	// Exec app
	app.Exec()
}

Now build the app, and change the res/main.qml file on runtime. Live reload should be works now :

Screencast