CopperSpice API  1.7.2
Global Declarations

Header file for fundamental global declarations. More...

Macros

#define CS_VERSION
 
#define CS_VERSION_CHECK(major, minor, patch)
 
#define CS_VERSION_STR
 
#define csPrintable(str)
 
#define Q_ARG(type, value)
 
#define Q_ASSERT(cond)
 
#define Q_ASSERT_X(cond, where, what)
 
#define Q_BIG_ENDIAN
 
#define Q_BYTE_ORDER
 
#define Q_CC_CLANG
 
#define Q_CC_EDG
 
#define Q_CC_GNU
 
#define Q_CC_INTEL
 
#define Q_CC_MIPS
 
#define Q_CC_PGI
 
#define Q_CHECK_PTR(pointer)
 
#define Q_DECL_EXPORT
 
#define Q_DECL_IMPORT
 
#define Q_FUNC_INFO
 
#define Q_INT64_C(literal)
 
#define Q_LIKELY(expr)
 
#define Q_LITTLE_ENDIAN
 
#define Q_OS_BSD4
 
#define Q_OS_DARWIN
 
#define Q_OS_FREEBSD
 
#define Q_OS_LINUX
 
#define Q_OS_NETBSD
 
#define Q_OS_OPENBSD
 
#define Q_OS_UNIX
 
#define Q_OS_WIN
 
#define Q_OS_WIN32
 
#define Q_OS_WIN64
 
#define Q_RETURN_ARG(type, value)
 
#define Q_UINT64_C(literal)
 
#define Q_UNLIKELY(expr)
 
#define Q_UNUSED(name)
 
#define Q_WS_X11
 
#define QT_POINTER_SIZE
 
#define QT_TR_NOOP(source)
 
#define QT_TRANSLATE_NOOP(context, source)
 
#define QT_TRANSLATE_NOOP3(context, source, comment)
 
#define QT_TRID_NOOP(id)
 

Typedefs

typedef int16_t qint16
 
typedef int32_t qint32
 
typedef long long qint64
 
typedef int8_t qint8
 
using qintptr = std::conditional< sizeof (void *)==4, qint32, qint64 >::type
 
using qptrdiff = qintptr
 
using qreal = double
 
using QtMsgHandler = void (*)(QtMsgType, QStringView)
 
typedef uint16_t quint16
 
typedef uint32_t quint32
 
typedef unsigned long long quint64
 
typedef uint8_t quint8
 
using quintptr = std::conditional< sizeof (void *)==4, quint32, quint64 >::type
 
using uchar = unsigned char
 
using uint = unsigned int
 
using ulong = unsigned long
 
using ushort = unsigned short
 

Enums

enum  QtMsgType
 

Functions

constexpr const char * cs_mark_tr (const char *context, const char *text)
 
constexpr std::pair< const char *, const char * > cs_mark_tr (const char *context, const char *text, const char *comment)
 
constexpr const char * cs_mark_tr (const char *text)
 
constexpr const char * cs_mark_tr_id (const char *id)
 
void cs_require_version (int argc, char *argv[], const char *str)
 
QtMsgHandler csInstallMsgHandler (QtMsgHandler handler)
 
const char * csVersion ()
 
template<typename T >
T * q_check_ptr (T *ptr)
 
template<typename T >
constexpr T qAbs (const T &value)
 
template<typename T1 , typename T2 , typename T3 >
constexpr auto qBound (const T1 &min, const T2 &value, const T3 &max)
 
void qCritical (const char *msg,...)
 
void qDebug (const char *msg,...)
 
void qFatal (const char *msg,...)
 
constexpr bool qFuzzyCompare (double p1, double p2)
 
constexpr bool qFuzzyCompare (float p1, float p2)
 
QByteArray qgetenv (const char *varName)
 
template<typename T1 , typename T2 >
constexpr auto qMax (const T1 &value1, const T2 &value2)
 
template<typename T1 , typename T2 >
constexpr auto qMin (const T1 &value1, const T2 &value2)
 
bool qputenv (const char *varName, const QByteArray &value)
 
constexpr int qRound (double value)
 
constexpr int qRound (float value)
 
constexpr qint64 qRound64 (double value)
 
constexpr qint64 qRound64 (float value)
 
QString qtTrId (const char *id, std::optional< int > n=std::optional< int >())
 
bool qunsetenv (const char *varName)
 
void qWarning (const char *msg,...)
 

Detailed Description

The <QGlobal> header file includes fundamental global declarations for types, functions, and macros.

Functions

The <QGlobal> header contains several functions which can compare values or perform an operation on a value. These are template functions.

Macros

The macros in this header include platform and compiler detection as well as convenience macros for translations.

The <QGlobal> header file provides a range of macros (Q_CC_*) which are defined if the application is compiled using the specified platforms. For example, the Q_CC_GNU macro is defined if the application is compiled using GCC. The header file also declares a range of macros (Q_OS_*) that are defined for the specified platforms. For example, Q_OS_WIN which is defined for Windows. The purpose of these macros is to enable programmers to add compiler or platform specific code to their application.

Platforms

A list of all platform defines (including those which are no longer supported) can be found in the CopperSpice Overview Documentation for Platform Defines.

Types

There are using declarations in <QGlobal> which set up a type alias from primitive types to platform independent names. The purpose of the platform typedefs is to ensure the basic data types will be a consistent size on every platform.

See also
QtAlgorithms, QSysInfo

Macro Definition Documentation

CS_VERSION

This macro expands a numeric value of the form 0xMMNNPP (MM = major, NN = minor, PP = patch) that specifies the CopperSpice version number. For example, if you compile your application using CopperSpice 1.7.2, the CS_VERSION macro will expand to 0x010702.

This macro can be used to verify the which CopperSpice features are available.

#if CS_VERSION >= 0x010702
QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon);
#else
QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon);
QIcon icon(pixmap);
#endif
See also
CS_VERSION_STR, csVersion()
CS_VERSION_CHECK

Turns the major, minor, and patch numbers of a version into an integer, 0xMMNNPP (MM = major, NN = minor, PP = patch).

See also
CS_VERSION
CS_VERSION_STR

This macro expands to a string that specifies the CopperSpice version number, for example "1.7.2".

See also
CS_VERSION
csPrintable

This macro is equivalent to str.toUtf8().constData().

qWarning("%s: %s", csPrintable(key), csPrintable(value));
See also
qDebug(), qWarning(), qCritical(), qFatal()
Q_ARG

This macro takes two parameters. The first is type which is a data type used to create a QGenericArgument object. The second parameter is the value which is passed to the constructor of the QGenericArgument. This macro is most often used to pass arguments to QMetaObject::invokeMethod().

QScroller *widget = new QScroller(parent);
QRect rectangle = QRect(10, 10, 15, 50);
QMetaObject::invokeMethod(widget, "ensureVisible", Qt::DirectConnection,
Q_ARG(const QRect &, rectangle), Q_ARG(qreal, 30), Q_ARG(qreal, 95));
See also
Q_RETURN_ARG()
Q_ASSERT

Prints a warning message containing the source code file name and line number if cond is false. Q_ASSERT() is useful for testing pre and post-conditions during development. It does nothing if QT_NO_DEBUG was defined during compilation.

// file div.cpp
#include <QGlobal>
int divide(int a, int b) {
Q_ASSERT(b != 0);
return a / b;
}

If b is zero, the Q_ASSERT statement will output the following message using the qFatal() function:

ASSERT: "b == 0" in file div.cpp, line 8
Note
In order to use these macros in your application include the <QAssert> header file,
See also
Q_ASSERT_X(), qFatal()
Q_ASSERT_X

Prints the message what together with the location where, the source file name and line number if <cond is false. Q_ASSERT_X is useful for testing pre and post-conditions during development. It does nothing if QT_NO_DEBUG was defined during compilation.

// File: div.cpp
#include <QGlobal>
int divide(int a, int b) {
Q_ASSERT_X(b != 0, "divide", "division by zero");
return a / b;
}

If b is zero, the Q_ASSERT_X statement will output the following message using the qFatal() function:

ASSERT failure in divide: "division by zero", file div.cpp, line 7
Note
In order to use these macros in your application include the <QAssert> header file,
See also
Q_ASSERT(), qFatal()
Q_BIG_ENDIAN

This macro represents a value you can compare to the macro Q_BYTE_ORDER() to determine the endian-ness of your system. In a big-endian system, the most significant byte is stored at the lowest address. The other bytes follow in decreasing order of significance.

#if Q_BYTE_ORDER == Q_BIG_ENDIAN
...
#endif
See also
Q_BYTE_ORDER, Q_LITTLE_ENDIAN
Q_BYTE_ORDER

This macro can be used to determine the byte order the target platform uses for storing data in memory. It is defined by CopperSpice to be equal to either Q_LITTLE_ENDIAN or Q_BIG_ENDIAN.

#if Q_BYTE_ORDER == Q_BIG_ENDIAN
...
#endif
or
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
...
#endif
See also
Q_BIG_ENDIAN, Q_LITTLE_ENDIAN
Q_CC_CLANG

Defined if the application is compiled using LLVM clang.

Q_CC_EDG

Defined if the application is compiled using Edison Design Group C++.

Q_CC_GNU

Defined if the application is compiled using GNU C++.

Q_CC_INTEL

Defined if the application is compiled using Intel C++ for Linux, Intel C++ for Windows.

Q_CC_MIPS

Defined if the application is compiled using MIPSpro C++.

Q_CC_PGI

Defined if the application is compiled using Portland Group C++.

Q_CHECK_PTR

If pointer is nullptr a warning message containing the source code's file name and line number is printed. Q_CHECK_PTR does nothing if QT_NO_DEBUG was defined during compilation.

int *a;
Q_CHECK_PTR(a = new int[80]); // INCORRECT
a = new (nothrow) int[80]; // Right
See also
qWarning()
Q_DECL_EXPORT

This macro marks a symbol for shared library export.

See also
Q_DECL_IMPORT
Q_DECL_IMPORT

This macro declares a symbol to be an import from a shared library.

See also
Q_DECL_EXPORT
Q_FUNC_INFO

Expands to a string which is the name of the current function. With GNU GCC it is typically the function signature. With other compilers it may include the line and column number. Q_FUNC_INFO can be used with qDebug().

If this macro is used outside a function the behavior is undefined.

template<typename TInputType>
const TInputType &myMin(const TInputType &value1, const TInputType &value2)
{
qDebug() << Q_FUNC_INFO << "was called with value1:" << value1 << "value2:" << value2;
if (value1 < value2) {
return value1;
} else }
return value2;
}
}

When the above template is called with an integer type, the output will be similar to the following:

const TInputType& myMin(const TInputType &, const TInputType &)
        [with TInputType = int] was called with value1: 3 value2: 4
Q_INT64_C

Wraps the signed 64-bit integer literal in a platform independent way.

qint64 value = Q_INT64_C(932838457459459);
See also
qint64, Q_UINT64_C()
Q_LIKELY

This is a suggestion to the compiler that the condition expr, is likely to evaluate to true.

// the condition inside the "if" will be successful most of the time
for (int i = 1; i <= 365; i++) {
if (Q_LIKELY(isWorkingDay(i))) {
...
}
}
See also
Q_UNLIKELY()
Q_LITTLE_ENDIAN

This macro represents a value you can compare to the macro Q_BYTE_ORDER() to determine the endian-ness of your system. In a little-endian system, the least significant byte is stored at the lowest address. The other bytes follow in increasing order of significance.

#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
...
#endif
See also
Q_BYTE_ORDER, Q_BIG_ENDIAN
Q_OS_BSD4

Defined on any BSD 4.4 system.

Q_OS_DARWIN

Defined on Darwin OS.

Q_OS_FREEBSD

Defined on FreeBSD.

Q_OS_LINUX

Defined on Linux.

Q_OS_NETBSD

Defined on NetBSD.

Q_OS_OPENBSD

Defined on OpenBSD.

Q_OS_UNIX

Defined on any UNIX BSD/SYSV system.

Q_OS_WIN

Defined on all supported versions of Windows.

Q_OS_WIN32

Defined on all supported versions of Windows.

Q_OS_WIN64

Defined on all 64-bit versions of Windows.

Q_RETURN_ARG

This macro takes two parameters. The first is type which is a data type used to create a QGenericReturnArgument object. The second parameter is the value which is passed to the constructor of the QGenericREturnArgument. This macro is most often used to pass arguments to QMetaObject::invokeMethod().

See also
Q_ARG()
Q_UINT64_C

Provides a platform independent unsigned 64-bit integer literal.

quint64 value = Q_UINT64_C(932838457459459);
See also
quint64, Q_INT64_C()
Q_UNLIKELY

This is a suggestion to the compiler that the condition, expr is likely to evaluate to false.

bool readConfiguration(const QFile &file) {
// we expect to be asked to read an existing file
if (Q_UNLIKELY(! file.exists())) {
qWarning() << "File not found";
return false;
}
return true;
}
See also
Q_LIKELY()
Q_UNUSED

Suppress a compiler warning for the parameter name. Prefer using the following syntax.

(void) varName;
Q_WS_X11

Defined on X11.

QT_POINTER_SIZE

Expands to the size of a pointer in bytes (4 or 8). This is equivalent to sizeof(void *) but can be used in a preprocessor directive.

QT_TR_NOOP

This macro was deprecated. Refer to cs_mark_tr( const char * ).

QT_TRANSLATE_NOOP

This macro was deprecated. Refer to cs_mark_tr(const char *, const char *).

QT_TRANSLATE_NOOP3

This macro was deprecated. Refer to cs_mark_tr(const char *, const char *, const char *).

QT_TRID_NOOP

This macro was deprecated. Refer to cs_mark_tr( const char * ).

Typedef Documentation

Typedef for 16-bit signed integer. This type is guaranteed to be 16-bit on all platforms.

Typedef for 32-bit signed integer. This type is guaranteed to be 32-bit on all platforms.

Typedef for a 64-bit integer. This type is guaranteed to be 64-bit on all platforms.

Literals of this type can be created using the Q_INT64_C() macro as follows:

qint64 value = Q_INT64_C(932838457459459);
See also
Q_INT64_C(), quint64

Typedef for 8-bit signed integer. This type is guaranteed to be 8-bit on all platforms.

Integral type for representing a pointer. Typedef for either a qint32 or qint64, whichever is the same size as a pointer on the target platform. The data types qintptr and qptrdiff are signed while quintptr is unsigned.

See also
qptrdiff, qint32, qint64

Integral type for representing pointer differences. Typedef for either a qint32 or qint64, whichever is the same size as a pointer on the target platform. The data types qintptr and qptrdiff are signed while quintptr is unsigned.

See also
quintptr, qint32, qint64

Typedef for double on all platforms except for those using CPUs with ARM architectures. On ARM-based platforms qreal is a typedef for float for performance reasons.

This is a typedef for a pointer to a function with the following signature.

void myMsgHandler(QtMsgType, const char *);
See also
QtMsgType, csInstallMsgHandler()

Typedef for 16-bit unsigned integer. This type is guaranteed to be 16-bit on all platforms.

Typedef for 32-bit unsigned integer. This type is guaranteed to be 32-bit on all platforms.

Typedef for 64-bit unsigned integer. This type is guaranteed to be 64-bit on all platforms..

Literals of this type can be created using the Q_UINT64_C() macro as follows:

quint64 value = Q_UINT64_C(932838457459459);
See also
Q_UINT64_C(), qint64

Typedef for 8-bit unsigned integer. This type is guaranteed to be 8-bit on all platforms.

Integral type for representing pointer values. Typedef for either a quint32 or quint64, whichever is the same size as a pointer on the target platform. The data types qintptr and qptrdiff are signed while quintptr is unsigned.

See also
qptrdiff, quint32, quint64

Convenience typedef for unsigned char.

Convenience typedef for unsigned int.

Convenience typedef for unsigned long.

Convenience typedef for unsigned short.

Enumeration Type Documentation

enum QtMsgType

This enum describes the messages that can be sent to a message handler, QtMsgHandler. You can use the enum to identify and associate the various message types with the appropriate actions.

ConstantValueDescription
QtDebugMsg 0 A message generated by the qDebug() function.
QtWarningMsg 1 Message generated by the qWarning() function.
QtCriticalMsg 2 Message generated by the qCritical() function.
QtFatalMsg 3 Message generated by the qFatal() function.
QtSystemMsg 2 Alias for QtCriticalMsg
See also
QtMsgHandler, csInstallMsgHandler()

Function Documentation

constexpr const char * cs_mark_tr ( const char *  context,
const char *  text 
)
constexpr

The passed parameter for context is used as the name of the class that contains the call to cs_mark_tr. When lupdate is run, the passed value for text will be added to the translation file.

In the following example "FriendlyConversation" is the name of the class that contains the call to cs_mark_tr(). In the first call "Hello" is the text to be translated and in the second call "Goodbye" is the text to be translated.

static const char *greeting_strings[] = {
cs_mark_tr("FriendlyConversation", "Hello"),
cs_mark_tr("FriendlyConversation", "Goodbye")
};
QString FriendlyConversation::greeting(int type) {
return tr(greeting_strings[type]);
}
QString global_greeting(int type) {
return QCoreApplication::translate("FriendlyConversation", greeting_strings[type]);
}
See also
Internationalization
constexpr std::pair< const char *, const char * > cs_mark_tr ( const char *  context,
const char *  text,
const char *  comment 
)
constexpr

The passed parameter for context is used as the name of the class that contains the call to cs_mark_tr. When lupdate is run, the passed value for text will be added to the translation file. The comment is added to the translation file to assist the person working on the translations, it is not displayed when running your application.

struct Data {
Data(std::pair<const char *, const char *> input)
: text(input.first), comment(input.second)
{ }
const char *text;
const char *comment;
};
static Data greeting_strings[] = {
cs_mark_tr("FriendlyConversation", "Hello", "Said when people are gathering"),
cs_mark_tr("FriendlyConversation", "Goodbye", "Used when leaving a conversation")
};
QString FriendlyConversation::greeting(int type) {
return tr(greeting_strings[type].text, greeting_strings[type].comment);
}
QString global_greeting(int type) {
return QCoreApplication::translate("FriendlyConversation", greeting_strings[type].text, greeting_strings[type].comment);
}
See also
Internationalization
constexpr const char * cs_mark_tr ( const char *  text)
constexpr

Uses the name of the current class for the context. When lupdate is run, the passed value for text will be added to the translation file.

In the following example "FriendlyConversation" is the name of the class that contains the call to cs_mark_tr(). In the first call "Hello" is the text to be translated and in the second call "Goodbye" is the text to be translated.

QString FriendlyConversation::greeting(int type) {
static const char *greeting_strings[] = {
cs_mark_tr("Hello"),
cs_mark_tr("Goodbye")
};
return tr(greeting_strings[type]);
}
See also
Internationalization
constexpr const char * cs_mark_tr_id ( const char *  id)
constexpr

Adds the id to a translation file when processed by lupdate.

static const char * const ids[] = {
//% "This is the first text."
cs_mark_tr_id("some_1st_text"),
//% "This is the second text."
cs_mark_tr_id("some_2nd_text")
};
void TheClass::addLabels() {
for (const char *item : ids) {
new QLabel(qtTrId(item), this);
}
}
See also
qtTrId(), Internationalization
void cs_require_version ( int  argc,
char *  argv[],
const char *  str 
)

This method can be used to ensure your application is run with a new enough version of CopperSpice.

The argc and argv parameters are the main() function's argc and argv parameters. The str parameter is a string literal that specifies which version of CopperSpice the application requires, for example "1.7.2".

#include <QApplication>
#include <QMessageBox>
int main(int argc, char *argv[]) {
cs_require_version(argc, argv, "1.7.2")
QApplication app(argc, argv);
<some code>
return app.exec();
}
QtMsgHandler csInstallMsgHandler ( QtMsgHandler  handler)

Installs a message handler which must be a valid function pointer to a QtMsgHandler. This function returns a pointer to the previous message handler, which could be a nullptr.

The message handler is a function responsible for printing debug messages, warnings, critical and fatal error messages. There are multiple messages which may be printed when an internal run time error occurs. Implementing your own message handler provide full control of when messages are printed and how they are formatted.

Only one message handler can be defined at any given time. To restore the default message handler call csInstallMsgHandler(nullptr). The default message handler prints to the standard output.

If qFatal() is called the application will abort after the message handler runs. If qWarning() is called and the environment variable QT_FATAL_WARNINGS is defined, the program will also abort after the msg is displayed.

#include <qapplication.h>
#include <stdio.h>
void myMessageOutput(QtMsgType type, QStringView msg) {
switch (type) {
case QtDebugMsg:
fputs("Debug: ", stderr);
break;
case QtWarningMsg:
fputs("Warning: ", stderr);
break;
case QtCriticalMsg:
fputs("Critical: ", stderr);
break;
case QtFatalMsg:
fputs("Fatal: ", stderr);
break;
}
fwrite(msg.charData(), msg.size_storage(), 1, stderr);
fputc('\n', stderr);
fflush(stderr);
// if type == QtFatalMsg the program will abort()
}
int main(int argc, char **argv) {
csInstallMsgHandler(myMessageOutput);
QApplication app(argc, argv);
if ( an_error_happened ) {
qDebug("This is a debug message");
qWarning("Show a message for the user");
}
return app.exec();
}
See also
qDebug(), qCritical(), qFatal(), qWarning(), QtMsgType
const char * csVersion ( )

Returns the version number of CopperSpice at run time as a string, for example, "1.7.2". This value may be a different version than the version the application was compiled with.

See also
CS_VERSION_STR
template<typename T >
T * q_check_ptr ( T *  ptr)
inline

Checks if ptr is a nullptr, returns the pointer. This can be used as an inline version of Q_CHECK_PTR().

template<typename T >
T qAbs ( const T &  value)
inlineconstexpr

Compares value to the 0 of type T and returns the absolute value. Thus if T is double, then value is compared to (double) 0.

int absoluteValue;
int myValue = -4;
absoluteValue = qAbs(myValue); // absoluteValue == 4
template<typename T1 , typename T2 , typename T3 >
constexpr T & qBound ( const T1 &  min,
const T2 &  value,
const T3 &  max 
)
inlineconstexpr

Returns the value bounded by min and max. This is equivalent to qMax(min, qMin(value, max)).

int myValue = 10;
int minValue = 2;
int maxValue = 6;
int boundedValue = qBound(minValue, myValue, maxValue); // boundedValue == 6
See also
qMin(), qMax()
void qCritical ( const char *  msg,
  ... 
)

Calls the message handler with the critical message msg. If no message handler has been installed the message is printed to stderr. This function takes a format string and a list of arguments, similar to the printf() function.

To suppress or change how the message is processed you can install your own message handler using csInstallMsgHandler().

To use this function in your application include the <QLog> header file.

void load(const QString &fileName) {
QFile file(fileName);
if (! file.exists()) {
qCritical("File '%s' does not exist", csPrintable(fileName));
}
}
See also
qDebug(), qFatal(), qWarning(), csInstallMsgHandler()
void qDebug ( const char *  msg,
  ... 
)

Calls the message handler with the debug message msg. If no message handler has been installed the message is printed to stderr. This function takes a format string and a list of arguments, similar to the printf() function.

To suppress or change how the message is processed you can install your own message handler using csInstallMsgHandler().

To use this function in your application include the <QLog> header file.

qDebug("Items in list: %d", myList.size());
See also
qCritical(), qFatal(), qWarning(), csInstallMsgHandler()
void qFatal ( const char *  msg,
  ... 
)

Calls the message handler with the fatal message msg. If no message handler has been installed the message is printed to stderr. This function takes a format string and a list of arguments, similar to the printf() function.

To suppress or change how the message is processed you can install your own message handler using csInstallMsgHandler(). If qFatal() is called the application will abort after the message handler runs.

To use this function in your application include the <QLog> header file.

int divide(int a, int b) {
if (b == 0) {
// program error
qFatal("Divide: Divide by zero is not allowed");
}
return a / b;
}
See also
qDebug(), qCritical(), qWarning(), csInstallMsgHandler()
bool qFuzzyCompare ( double  p1,
double  p2 
)
inlineconstexpr

Compares the floating point value p1 and p2 and returns true if they are considered equal, otherwise false.

Comparing floating point values for exact equality does not work. The correct solution is to compare if the values are very close to each other. This is the purpose of qFuzzyCompare().

// Instead of comparing with 0.0
qFuzzyCompare(0.0,1.0e-200); // returns false
// Compare adding 1 to both values will fix the problem
qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // returns true

This method is thread-safe.

bool qFuzzyCompare ( float  p1,
float  p2 
)
inlineconstexpr

Compares the floating point value p1 and p2 and returns true if they are considered equal, otherwise false. The two numbers are compared in a relative way, where the exactness is stronger the smaller the numbers are.

This method is thread-safe.

QByteArray qgetenv ( const char *  varName)

Returns the value of the environment variable with name varName. To retrieve the variable as a const char * use QByteArray::constData(). To convert the data to a QString use QString::fromUtf8().

Note
Do not use qgetenv on Windows if the content may contain non-ASCII characters, like file names.
See also
QProcessEnvironment, qputenv(), qEnvironmentVariableIsSet(), qEnvironmentVariableIsEmpty()
template<typename T1 , typename T2 >
constexpr auto qMax ( const T1 &  value1,
const T2 &  value2 
)
inlineconstexpr

Returns the maximum of value1 and value2.

int myValue = 6;
int yourValue = 4;
int maxValue = qMax(myValue, yourValue); // maxValue == myValue
See also
qMin(), qBound()
template<typename T1 , typename T2 >
constexpr auto qMin ( const T1 &  value1,
const T2 &  value2 
)
inlineconstexpr

Returns the minimum of value1 and value2.

int myValue = 6;
int yourValue = 4;
int minValue = qMin(myValue, yourValue); // minValue == yourValue
See also
qMax(), qBound()
bool qputenv ( const char *  varName,
const QByteArray value 
)

Sets the value of the environment variable named varName. It will create the variable if it does not exist. This function returns false if the variable could not be set.

Calling this function with a nullptr for varName removes the environment variable on Windows. On Unix systems the value of the environment variable will be an empty.

It is recommended to use qunsetenv() for portability.

See also
qgetenv()
int qRound ( double  value)
inlineconstexpr

Rounds value to the nearest integer.

double valueA = 2.3;
double valueB = 2.7;
int roundedValueA = qRound(valueA);
// roundedValueA = 2
int roundedValueB = qRound(valueB);
// roundedValueB = 3
int qRound ( float  value)
inlineconstexpr

Rounds value to the nearest integer.

qint64 qRound64 ( double  value)
inlineconstexpr

Rounds value to the nearest 64-bit integer.

double valueA = 42949672960.3;
double valueB = 42949672960.7;
qint64 roundedValueA = qRound64(valueA);
// roundedValueA = 42949672960
qint64 roundedValueB = qRound64(valueB); // roundedValueB = 42949672961
qint64 qRound64 ( float  value)
inlineconstexpr

Rounds value to the nearest 64-bit integer.

QString qtTrId ( const char *  id,
std::optional< int >  n = std::optional<int>() 
)

Returns a translated string identified by id. If no translation is found the id string is returned. If a value for n is passed then all occurrences of %n in the translated string will be replaced with a decimal representation of the integer n.

The % symbol is used at the beginning of a normal C++ comment to designate the "source text" to be translated. When compiling a TS file to create the QM file, you will need to pass the -idbased command line option to the lrelease program.

//% "some text"
/*% "some text" */
//% "%n File(s) found.\n"
//% "Do you want to continue?"
QString text = qtTrId("message_200_files_found", 5);
See also
QObject::tr(), QCoreApplication::translate(), Internationalization
bool bool qunsetenv ( const char *  varName)

Deletes the variable varName from the environment. Returns true on success.

See also
qputenv(), qgetenv()
void qWarning ( const char *  msg,
  ... 
)

Calls the message handler with the warning message msg. If no message handler has been installed the message is printed to stderr. This function takes a format string and a list of arguments, similar to the printf() function.

To suppress or change how the message is processed you can install your own message handler using csInstallMsgHandler(). If qWarning() is called and the environment variable QT_FATAL_WARNINGS is defined, the program will also abort after the msg is displayed.

To use this function in your application include the <QLog> header file.

void myFunction(int value) {
if (value > 200) {
qWarning("myFunction: Invalid argument c == %d", value);
}
}
See also
qDebug(), qCritical(), qFatal(), csInstallMsgHandler()