QT Global Macros and variables
QT Global functions and macros are now collected in the work as follows
qt_version: (major << +) + (minor << 8) + Patch
Detection version Number:
Qt_version_check (major, minor, Patch) ((major<<16) | ( MINOR<<8) | (patch))
When you use namespaces, some macro definitions :
Namespace Qt_namespace {}//namespace definition
# define QT_PREPEND_NAMESPACE (name):: Qt_namespace::name
# define Qt_use_namespace using NAMESPACE:: Qt_namespace;
# define Qt_begin_namespace NAMESPACE Qt_namespace {
# define Qt_end_namespace}
# define Qt_begin_include_namespace}
# define Qt_end_include_namespace NAMESPACE Qt_namespace {
# define Qt_begin_moc_namespace Qt_use_namespace
# define Qt_end_moc_namespace
# define QT_FORWARD_DECLARE_CLASS (name)/
Qt_begin_namespace class name; Qt_end_namespace/
Using Qt_prepend_namespace (name);
# define QT_FORWARD_DECLARE_STRUCT (name)/
qt_begin_namespace struct name; Qt_end_namespace/
Using Qt_prepend_namespace (name);
Q_global_static (type, name) is used to define a global static variable (thread-safe). Use it to initialize an object pointer (function pointer).
Q_global_static_with_args (type, name, arguments): ibid., can take parameters.
q_unused (): typically used in a function's arguments, indicating that the parameter is not used in the method body.
Common data types:
Qint8, Quint8, Qint16, Quint16, Qint32, Quint32, Qint64, Quint64, Qlonglong (=int64), Qulonglong (=uint64)
Quintptr, Qptrdiff, is as big as a pointer. Such as:
sizeof (void *) = = sizeof (QUINTPTR)
&& sizeof (void *) = = sizeof (Qptrdiff)
qt Useful type definitions : Uchar, ushort, uint, ULONG
Practical Inline functions : Qabs (), Qround (), QRound64 (), Qmin (), QMax (), Qbound ();
Try-catch Macro :
#ifdef qt_no_exceptions
# define Qt_try if (true)
# define Qt_catch (A) Else
# define Qt_throw (A) Qt_noop ()
# define Qt_rethrow Qt_noop ()
#else
# define Qt_try TRY
# define Qt_catch (a) CATCH (a)
# define Qt_throw (a) THROW a
# define Qt_rethrow Throw
#endif
Each qt_try corresponds to a qt_catch, and do not use exception instances in the CATCH statement block.
Debugging related Functions :
Qdebug (),
Qwarnig (),
Qcritical (),
Q_assert ()
some other functions :
This macro is used to define a class that prohibits copying
#define q_disable_copy (Class) /
Class (const class &); /
Class &operator= (const class &);
Qgetenv (), qputenv (), qintcast (double or float). Qsrand (UINT Seed), Qrand ()
2. QT Memory management functions
void *qmalloc (size_t size);
void Qfree (void *ptr);
void *qrealloc (void *ptr, size_t size);
void *qmallocaligned (size_t size, size_t alignment)
void *qreallocaligned (void *oldptr, size_t newsize, size_t oldsize, size_t Alignment)
void qfreealigned (void *ptr)
void *qmemcopy (void *dest, const void *SRC, size_t n);
void *qmemset (void *dest, int c, size_t N);
Note: the address of the array labeled-1 is out-of-bounds for the array, but this address is meaningful. This address is the address that corresponds to the forward offset of the first address of the requested array storage space (that is, the number of bytes corresponding to the current array type being offset). This address is not initialized with the array space, so the data is indeterminate. If it is an address space that is being used by a system or other application, it can be accessed, and the meaning of the data in it depends on the data written by the system or other application, but after access, It is possible to cause system or other application exceptions. If the address is not used, then is a wild address, then the data is random, meaningless
3. Environment variable setting function
Qputenv (): Similar to Putenv (), since VC2005 abolished the putenv () function, all defined this function, in the VC environment calls the alternative function, the other platform calls the standard C library function putenv ().
Qgetenv (): Gets the value of an environment variable.
4. Custom Output functions
Qtmsghandler Qinstallmsghandler (Qtmsghandler h)
Where: typedef void (*qtmsghandler) (qtmsgtype, const char *);
Use this function to customize the output of your debug information.
5. Assertions
Q_assert (BOOL test): When an assertion fails, a warning message is printed with the source file name and line number.
void q_assert_x (bool test, const char *where, const char *what)
void q_check_ptr (void *pointer): Detects an illegal pointer and prints a warning message if the pointer is 0.
6. System Information Class Qsysinfo
QT Global Macros and variables