Skip to content
therecipe edited this page Mar 22, 2019 · 6 revisions

The tools can be found either in $(go env GOPATH)/bin or $GOBIN and are symlinked into your PATH when installing this binding. If you use the minimal installation and/or depend on the docker images for the specific target, then you need to use -docker flag when you use these tools.

Contents

qtsetup

This tool is used for generating binding code and installing all of Qt packages, which in turn will speed up the compilation of your applications later. The use of qtsetup is rarely necessary after you are done with the inital setup, however there are some case where you may use it again :

  • To dump some environment infos by running qtsetup check [target].
  • To update the tools by running qtsetup update.
  • To upgrade the whole repo by running qtsetup upgrade (you will need to re-run the qtsetup after this).

Run qtsetup -help for more info.

qtdeploy

This tool is used to deploy your Qt applications and it's recommended to use qtdeploy instead go build. When you run this tool, it will also run qtrcc, qtmoc and qtminimal for you. When running, this tool will generate various files and it's recommended to not manually edit or remove them. To compile and deploy your app, you can use qtdeploy by running :

qtdeploy build [target] [path/to/your/project]

or if you use docker images :

qtdeploy -docker build [target] [path/to/your/project]

You can omit the path if you are currently inside the project folder. The valid targets are :

  • desktop which deploys to your system's platform.
  • windows
  • darwin
  • linux
  • android
  • android-emulator
  • ios
  • ios-simulator
  • sailfish
  • sailfish-emulator
  • rpi1
  • rpi2
  • rpi3
  • asteroid
  • ubports
  • js
  • wasm

Do note that qtdeploy is slow because it is intended to be used for deploying, and therefore takes some extra actions that may not be needed during development. To make it faster you can check FAQ. You can also run qtdeploy -help for more info.

qtrcc

This tool is a wrapper around Qt's rcc and used to bundle resources with your code. You can call it by running :

qtrcc desktop path/to/your/project

Like qtdeploy, you can omit path if you are currently inside the project folder.

By default, qtrcc will automatically bundle all resources from the qml sub-folder (path/to/your/project/qml). Futhermore qtquickcontrols2.conf files are automatically detected inside the root folder and will be bundled as well.

If you want to re-use your current .qrc file(s) instead, or simply want to have more control about your resources, then you can place your .qrc file(s) inside the root folder. Or if you need even more control, then you can just use rcc directly as well, but make sure to obtain one of these rcc_cgo_*.go files to place them alongside with your rcc generated .cpp file.

Invoking qtrcc will generate at least 3 different files and it's recommended to not manually edit or remove them. If you want to modify the *.qrc* files, you can edit it manually or with the help of the Qt Creator.

Run qtrcc -help for more info.

qtmoc

This tool is a wrapper around Qt's moc and can be used to create sub-classes of Qt classes and to extend them with your own constructors, signals, slots and properties. It's recommended that you get yourself familiar with Qt's signal and slot mechanism first.

You can call qtmoc for your entire project by running :

qtmoc desktop path/to/your/project

You can also call it for a specific sub-package :

qtmoc desktop path/to/your/sub-package

Like qtdeploy and qtrcc, you can omit path if you are currently inside the project or sub-package folder.

For this to work you need to create a moc struct first :

package main

import "github.com/therecipe/qt/core"

//this struct will let qtmoc generate the necessary Go and C++ code.
//such as the NewExampleStruct and DestroyExampleStruct functions
type exampleStruct struct {

	//let qtmoc know what class you want to sub-class
	//this can be any class that is derived from QObject
	//and could also be one of your own moc classes
	//it's important that you anonymously embed the type as a value here
	//qtmoc will ignore this struct otherwise
	core.QObject

	//this will let qtmoc know that you want to have the "init" function called
	//when you call NewExampleStruct
	_ func() `constructor:"init"`

	//this will let qtmoc know that you want a signal called "firstSignal"
	//so that the related Connect* Disconnect* functions can be created
	_ func() `signal:"firstSignal"`

	//the signal can also have parameters, but no return parameter
	//return parameters are only possible if you create a slot
	_ func(bool, int, string, []string, map[string]string) `signal:"secondSignal"`

	//you can also let the signal accept a single *core.QObject an array or a map
	_ func(*core.QObject, []*core.QObject, map[string]*core.QObject) `signal:"thirdSignal"`

	//as a special addition to the supported Go primitives, you can also use Go errors in signals/slots/properties
	_ func(error) `signal:"fourthSignal"`

	//this will let qtmoc know that you want a slot called "firstSlot"
	_ func() `slot:"firstSlot"`

	//a slot can be created in the same way as a signal, but it can additionally return a single argument
	_ func(string) string               `slot:"secondSlot"`
	_ func(*core.QObject) *core.QObject `slot:"thirdSlot"`
	_ func() error                      `slot:"fourthSlot"`

	//this will let qtmoc know that you want a property called "firstProperty"
	//there will be helper getter + setter functions and a changed signal created called:
	//FirstProperty (IsFirstProperty for bools), SetFirstProperty, FirstProperyChanged
	_ string `property:"firstProperty"`
}

//this function will be automatically called, when you use the `NewExampleStruct` function
func (s *exampleStruct) init() {
	//here you can do some initializing
	s.SetFirstProperty("defaultString")
	s.ConnectFirstSignal(func() { println("do something here") })
	s.ConnectSecondSignal(s.secondSignal)
}

func (s *exampleStruct) secondSignal(v0 bool, v1 int, v2 string, v3 []string, v4 map[string]string) {
	println("do something here")
}

There are some additions planned, such as :

  • Custom constructors (with additional input and return parameters).
  • The option to automatically connect signals/slots.
  • The option to make signals/slots/properties private.
  • Connect functions for properties.

Run qtmoc -help for more infos.

qtminimal

Usually qtminimal is not needed to be ran manually, as it is just used to reduce the overall compiled binary size, by analysing your code and regenerating a sub-set of the binding. However, if you use qtrcc or qtmoc manually, you have to run qtminimal as well :

qtminimal desktop path/to/your/project

Like the other tools, you can omit path if you are currently inside the project or sub-package folder. For more info, run qtminimal -help.

Clone this wiki locally