CopperSpice API
1.9.1
|
Header file for fundamental global declarations. More...
Macros | |
#define | CS_DISABLE_ASSERT |
#define | CS_DISABLE_DEBUG |
#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_PROCESSOR_ARM |
#define | Q_PROCESSOR_ARM_V5 |
#define | Q_PROCESSOR_ARM_V6 |
#define | Q_PROCESSOR_ARM_V7 |
#define | Q_PROCESSOR_ARM_V8 |
#define | Q_PROCESSOR_X86 |
#define | Q_PROCESSOR_X86_32 |
#define | Q_PROCESSOR_X86_64 |
#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 | |
using | qint16 = int16_t |
using | qint32 = int32_t |
using | qint64 = long long |
using | qint8 = int8_t |
using | qintptr = std::conditional< sizeof (void *)==4, qint32, qint64 >::type |
using | qptrdiff = qintptr |
using | qreal = double |
using | QtMsgHandler = void (*)(QtMsgType, QStringView) |
using | quint16 = uint16_t |
using | quint32 = uint32_t |
using | quint64 = unsigned long long |
using | quint8 = uint8_t |
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 | |
template<typename S = QString> | |
S | cs_mark_string_tr (const char *context, const char *text) |
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,...) |
The <QGlobal> header file includes fundamental global declarations for types, functions, and macros.
The <QGlobal> header contains several functions which can compare values or perform an operation on a value. These are templated functions.
The <QGlobal> header file provides a range of macros which are defined when your application is compiled for a particular platform. For example, the Q_CC_CLANG macro is defined if the application is compiled using clang.
There are also macros which can be used to query the target operating system like Q_OS_WIN, Q_OS_DARWIN, and Q_OS_LINUX. The purpose of these macros is to enable programmers to add compiler or platform specific code to their application.
A list of all platform defines (including those which are no longer supported) can be found in the CopperSpice Overview Documentation for Platform Defines.
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.
CS_DISABLE_ASSERT |
This macro controls if the Q_ASSERT and Q_ASSERT_X macros are enabled or disabled. By default, this macro is not defined which means Q_ASSERT and Q_ASSERT_X will be enabled.
To turn off the asserts, define CS_DISABLE_ASSERT.
CS_DISABLE_DEBUG |
This macro controls if QT_DEBUG is enabled or disabled. By default, this macro is not defined which means QT_DEBUG will be enabled.
To turn off the debug messages, define CS_DISABLE_DEBUG.
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.8.2, the CS_VERSION macro will expand to 0x010802.
This macro can be used to verify the which CopperSpice features are available.
CS_VERSION_CHECK |
Turns the major, minor, and patch numbers of a version into an integer, 0xMMNNPP (MM = major, NN = minor, PP = patch).
CS_VERSION_STR |
This macro expands to a string that specifies the CopperSpice version number, for example "1.8.2".
csPrintable |
This macro is equivalent to str.toUtf8().constData().
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().
Q_ASSERT |
This macro is used to test a variety of conditions at run time. It is advisable to have this macro enabled during development and disabled for a release build. Q_ASSERT is enabled by default. To disable, define the macro CS_DISABLE_ASSERT and then recompile. Having assert checks enabled can slow down the execution of your application.
When Q_ASSERT is enabled and the cond evaluates to false, a message will be printed and the application will terminate.
If b
is zero the Q_ASSERT statement shown above will output the following message using the qFatal() function.
Q_ASSERT_X |
Prints the message what together with the location where which is the source file name and line number if cond evaluates to false. This macro is used to test a variety of conditions at run time. To disable, define the macro CS_DISABLE_ASSERT and then recompile. Having assert checks enabled can slow down the execution of your application.
When Q_ASSERT_X is enabled and the cond evaluates to false, a message will be printed and the application will terminate.
If b
is zero the Q_ASSERT statement shown above will output the following message using the qFatal() function.
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.
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.
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. This macro does nothing if CS_DISABLE_ASSERT was defined when compiling.
Q_DECL_EXPORT |
This macro marks a symbol for shared library export.
Q_DECL_IMPORT |
This macro declares a symbol to be an import from a shared library.
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.
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.
Q_LIKELY |
This is a suggestion to the compiler that the condition expr, is likely to evaluate to true.
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.
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_PROCESSOR_ARM |
Defined when the target platform is running an ARM processor.
One of the following will also be defined based on the target architecture: Q_PROCESSOR_ARM_V5, Q_PROCESSOR_ARM_V6, Q_PROCESSOR_ARM_V7, or Q_PROCESSOR_ARM_V8.
Q_PROCESSOR_ARM_V5 |
Defined when the target platform is running an ARMv5 processor. The Q_PROCESSOR_ARM macro is also defined.
Q_PROCESSOR_ARM_V6 |
Defined when the target platform is running an ARMv6 processor. The Q_PROCESSOR_ARM macro is also defined.
Q_PROCESSOR_ARM_V7 |
Defined when the target platform is running an ARMv7 processor. The Q_PROCESSOR_ARM macro is also defined.
Q_PROCESSOR_ARM_V8 |
Defined when the target platform is running an ARMv8 processor. The Q_PROCESSOR_ARM macro is also defined.
Q_PROCESSOR_X86 |
Defined when the target platform is running an x86 or x86_64 processor.
In addition, Q_PROCESSOR_X86_32 is defined if the target platform is 32-bit. If the target platform is 64-bit, then Q_PROCESSOR_X86_64 will be defined.
Q_PROCESSOR_X86_32 |
Defined when the target platform is running on a 32-bit x86 processor. Q_PROCESSOR_X86 will also be defined.
Q_PROCESSOR_X86_64 |
Defined when the target platform is running on a 64-bit x86 processor. Q_PROCESSOR_X86 will also be defined.
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().
Q_UINT64_C |
Provides a platform independent unsigned 64-bit integer literal.
Q_UNLIKELY |
This is a suggestion to the compiler that the condition expr is likely to evaluate to false.
Q_UNUSED |
Suppress a compiler warning for the parameter name. Prefer using syntax shown below.
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 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:
Typedef for 8-bit signed integer. This type is guaranteed to be 8-bit on all platforms.
Typedef for double on all platforms.
This is a typedef for a pointer to a function with the following signature.
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:
Typedef for 8-bit unsigned integer. This type is guaranteed to be 8-bit on all platforms.
Equivalent to unsigned char.
Equivalent to unsigned int.
Equivalent to unsigned long.
Equivalent to unsigned short.
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.
Constant | Value | Description |
---|---|---|
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 |
QString cs_mark_string_tr | ( | const char * | context, |
const char * | text | ||
) |
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.
|
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.
|
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.
|
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.
|
constexpr |
Adds the id to a translation file when processed by lupdate.
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.8.2".
QtMsgHandler csInstallMsgHandler | ( | QtMsgHandler | handler | ) |
Installs a message handler which must be a valid function pointer to a QtMsgHandler. Returns a pointer to the previous message handler, which might 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.
const char * csVersion | ( | ) |
Returns the version number of CopperSpice at run time as a string, for example, "1.8.2". This value may be a different version than the version the application was compiled with.
|
inline |
Checks if ptr is a nullptr, returns the pointer. This can be used as an inline version of Q_CHECK_PTR().
|
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.
|
inlineconstexpr |
void qCritical | ( | const char * | msg, |
... | |||
) |
This function will output a critical message using msg and any number of additional arguments. The additional arguments are usually data values similar to the parameters for the printf() function.
By default the text will be sent to stderr. To change where the debug message is sent install your own message handler using csInstallMsgHandler().
void qDebug | ( | const char * | msg, |
... | |||
) |
This function will output a debug message using msg and any number of additional arguments. The additional arguments are usually data values similar to the parameters for the printf() function.
By default the text will be sent to stderr. To change where the debug message is sent install your own message handler using csInstallMsgHandler().
void qFatal | ( | const char * | msg, |
... | |||
) |
This function will output a fatal message using msg and any number of additional arguments. The additional arguments are usually data values similar to the parameters for the printf() function.
When qFatal() is called the application will abort after the message is processed.
By default the text will be sent to stderr. To change where the debug message is sent install your own message handler using csInstallMsgHandler().
|
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().
This method is thread-safe.
|
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().
|
inlineconstexpr |
|
inlineconstexpr |
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.
|
inlineconstexpr |
|
inlineconstexpr |
Rounds value to the nearest integer.
|
inlineconstexpr |
|
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" */
bool qunsetenv | ( | const char * | varName | ) |
void qWarning | ( | const char * | msg, |
... | |||
) |
This function will output a warning message using msg and any number of additional arguments. The additional arguments are usually data values similar to the parameters for the printf() function.
When qWarning() is called and the environment variable QT_FATAL_WARNINGS is defined the program will abort after the message is processed.
By default the text will be sent to stderr. To change where the debug message is sent install your own message handler using csInstallMsgHandler().