Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

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: