QFlags tutorial

From Qt Wiki
Revision as of 16:32, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Simple tutorial for safe-usage QFlags

Overview

First of all we should write about macro

Q_FLAGS


This macro registers one or several flags types to the meta-object system

Example:

The

Q_DECLARE_OPERATORS_FOR_FLAGS()

macro declares global

operator|()

functions for Flags, which is of type

QFlags<T>

. The

Q_DECLARE_FLAGS()

macro does not expose the flags to the meta-object system, so they cannot be used by Qt Script. To make the flags available for these purpose, the

Q_FLAGS()

macro must be used.

Usage sample

testFlag(flag)

method checks if flag is set in

QFlags

.

Some example

Categories: