6.12. Using Qt

Note:

For ports that are part of Qt itself, see Section 17.75, “qt-dist.

6.12.1. Ports That Require Qt

The Ports Collection provides support for Qt 5 with USES+=qt:5. Set USE_QT to the list of required Qt components (libraries, tools, plugins).

The Qt framework exports a number of variables which can be used by ports, some of them listed below:

Table 6.12. Variables Provided to Ports That Use Qt
QMAKEFull path to qmake binary.
LRELEASEFull path to lrelease utility.
MOCFull path to moc.
RCCFull path to rcc.
UICFull path to uic.
QT_INCDIRQt include directory.
QT_LIBDIRQt libraries path.
QT_PLUGINDIRQt plugins path.

6.12.2. Component Selection

Individual Qt tool and library dependencies must be specified in USE_QT. Every component can be suffixed with _build or _run, the suffix indicating whether the dependency on the component is at buildtime or runtime. If unsuffixed, the component will be depended on at both build- and runtime. Usually, library components are specified unsuffixed, tool components are mostly specified with the _build suffix and plugin components are specified with the _run suffix. The most commonly used components are listed below (all available components are listed in _USE_QT_ALL, and _USE_QT5_ONLY in /usr/ports/Mk/Uses/qt.mk):

Table 6.13. Available Qt Library Components
NameDescription
3dQt3D module
assistantQt 5 documentation browser
canvas3dQt canvas3d module
chartsQt 5 charts module
concurrentQt multi-threading module
connectivityQt connectivity (Bluetooth/NFC) module
coreQt core non-graphical module
datavis3dQt 5 3D data visualization module
dbusQt D-Bus inter-process communication module
declarativeQt declarative framework for dynamic user interfaces
designerQt 5 graphical user interface designer
diagTool for reporting diagnostic information about Qt and its environment
docQt 5 documentation
examplesQt 5 examples sourcecode
gamepadQt 5 Gamepad Module
graphicaleffectsQt Quick graphical effects
guiQt graphical user interface module
helpQt online help integration module
l10nQt localized messages
linguistQt 5 translation tool
locationQt location module
multimediaQt audio, video, radio and camera support module
networkQt network module
networkauthQt network auth module
openglQt 5-compatible OpenGL support module
pathsCommand line client to QStandardPaths
phonon4KDE multimedia framework
pixeltoolQt 5 screen magnifier
plugininfoQt5 plugin metadata dumper
printsupportQt print support module
qdbusQt command-line interface to D-Bus
qdbusviewerQt 5 graphical interface to D-Bus
qdocQt documentation generator
qdoc-dataQDoc configuration files
qevQt QWidget events introspection tool
qmakeQt Makefile generator
quickcontrolsSet of controls for building complete interfaces in Qt Quick
quickcontrols2Set of controls for building complete interfaces in Qt Quick
remoteobjectsQt5 SXCML module
scriptQt 4-compatible scripting module
scripttoolsQt Script additional components
scxmlQt5 SXCML module
sensorsQt sensors module
serialbusQt functions to access industrial bus systems
serialportQt functions to access serial ports
speechAccessibilty features for Qt5
sqlQt SQL database integration module
sql-ibaseQt InterBase/Firebird database plugin
sql-mysqlQt MySQL database plugin
sql-odbcQt Open Database Connectivity plugin
sql-pgsqlQt PostgreSQL database plugin
sql-sqlite2Qt SQLite 2 database plugin
sql-sqlite3Qt SQLite 3 database plugin
sql-tdsQt TDS Database Connectivity database plugin
svgQt SVG support module
testlibQt unit testing module
uipluginCustom Qt widget plugin interface for Qt Designer
uitoolsQt Designer UI forms support module
virtualkeyboardQt 5 Virtual Keyboard Module
waylandQt5 wrapper for Wayland
webchannelQt 5 library for integration of C++/QML with HTML/js clients
webengineQt 5 library to render web content
webkitQtWebKit with a more modern WebKit code base
websocketsQt implementation of WebSocket protocol
websockets-qmlQt implementation of WebSocket protocol (QML bindings)
webviewQt component for displaying web content
widgetsQt C++ widgets module
x11extrasQt platform-specific features for X11-based systems
xmlQt SAX and DOM implementations
xmlpatternsQt support for XPath, XQuery, XSLT and XML Schema

To determine the libraries an application depends on, run ldd on the main executable after a successful compilation.

Table 6.14. Available Qt Tool Components
NameDescription
buildtoolsbuild tools (moc, rcc), needed for almost every Qt application.
linguisttoolslocalization tools: lrelease, lupdate
qmakeMakefile generator/build utility

Table 6.15. Available Qt Plugin Components
NameDescription
imageformatsplugins for TGA, TIFF, and MNG image formats

Example 6.18. Selecting Qt 5 Components

In this example, the ported application uses the Qt 5 graphical user interface library, the Qt 5 core library, all of the Qt 5 code generation tools and Qt 5's Makefile generator. Since the gui library implies a dependency on the core library, core does not need to be specified. The Qt 5 code generation tools moc, uic and rcc, as well as the Makefile generator qmake are only needed at buildtime, thus they are specified with the _build suffix:

USES=	qt:5
USE_QT=	gui buildtools_build qmake_build

6.12.3. Using qmake

If the application provides a qmake project file (*.pro), define USES= qmake along with USE_QT. USES= qmake already implies a build dependency on qmake, therefore the qmake component can be omitted from USE_QT. Similar to CMake, qmake supports out-of-source builds, which can be enabled by specifying the outsource argument (see USES= qmake example). Also see Table 6.16, “Possible Arguments for USES= qmake.

Table 6.16. Possible Arguments for USES= qmake
VariableDescription
no_configureDo not add the configure target. This is implied by HAS_CONFIGURE=yes and GNU_CONFIGURE=yes. It is required when the build only needs the environment setup from USES= qmake, but otherwise runs qmake on its own.
no_envSuppress modification of the configure and make environments. It is only required when qmake is used to configure the software and the build fails to understand the environment setup by USES= qmake.
norecursiveDo not pass the -recursive argument to qmake.
outsourcePerform an out-of-source build.

Table 6.17. Variables for Ports That Use qmake
VariableDescription
QMAKE_ARGSPort specific qmake flags to be passed to the qmake binary.
QMAKE_ENVEnvironment variables to be set for the qmake binary. The default is ${CONFIGURE_ENV}.
QMAKE_SOURCE_PATHPath to qmake project files (.pro). The default is ${WRKSRC} if an out-of-source build is requested, empty otherwise.

When using USES= qmake, these settings are deployed:

CONFIGURE_ARGS+=	--with-qt-includes=${QT_INCDIR} \
			--with-qt-libraries=${QT_LIBDIR} \
			--with-extra-libs=${LOCALBASE}/lib \
			--with-extra-includes=${LOCALBASE}/include

CONFIGURE_ENV+=	QTDIR="${QT_PREFIX}" QMAKE="${QMAKE}" \
		MOC="${MOC}" RCC="${RCC}" UIC="${UIC}" \
		QMAKESPEC="${QMAKESPEC}"

PLIST_SUB+=	QT_INCDIR=${QT_INCDIR_REL} \
		QT_LIBDIR=${QT_LIBDIR_REL} \
		QT_PLUGINDIR=${QT_PLUGINDIR_REL}

Some configure scripts do not support the arguments above. To suppress modification of CONFIGURE_ENV and CONFIGURE_ARGS, set USES= qmake:no_env.

Example 6.19. USES= qmake Example

This snippet demonstrates the use of qmake for a Qt 5 port:

USES=	qmake:outsource qt:5
USE_QT=	buildtools_build

Qt applications are often written to be cross-platform and often X11/Unix is not the platform they are developed on, which in turn leads to certain loose ends, like:

  • Missing additional include paths. Many applications come with system tray icon support, but neglect to look for includes and/or libraries in the X11 directories. To add directories to qmake's include and library search paths via the command line, use:

    QMAKE_ARGS+=	INCLUDEPATH+=${LOCALBASE}/include \
    		LIBS+=-L${LOCALBASE}/lib
  • Bogus installation paths. Sometimes data such as icons or .desktop files are by default installed into directories which are not scanned by XDG-compatible applications. editors/texmaker is an example for this - look at patch-texmaker.pro in the files directory of that port for a template on how to remedy this directly in the qmake project file.

All FreeBSD documents are available for download at https://download.freebsd.org/ftp/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.