~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/corelib/global/qglobal.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the core module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qplatformdefs.h"
 
30
 
 
31
#include <qstring.h>
 
32
 
 
33
#include <stdio.h>
 
34
#include <stdlib.h>
 
35
#include <limits.h>
 
36
#include <stdarg.h>
 
37
#include <errno.h>
 
38
 
 
39
#if defined(Q_CC_MSVC) && !defined(Q_OS_TEMP)
 
40
#include <crtdbg.h>
 
41
#endif
 
42
 
 
43
/*!
 
44
    \class QFlag
 
45
    \brief The QFlag class is a helper data type for QFlags.
 
46
 
 
47
    It is equivalent to a plain \c int, except with respect to
 
48
    function overloading and type conversions. You should never need
 
49
    to use it in your applications.
 
50
 
 
51
    \sa QFlags
 
52
*/
 
53
 
 
54
/*!
 
55
    \fn QFlag::QFlag(int value)
 
56
 
 
57
    Constructs a QFlag object that stores the given \a value.
 
58
*/
 
59
 
 
60
/*!
 
61
    \fn QFlag::operator int() const
 
62
 
 
63
    Returns the value stored by the QFlag object.
 
64
*/
 
65
 
 
66
/*!
 
67
    \class QFlags
 
68
    \brief The QFlags class provides a type-safe way of storing
 
69
    OR-combinations of enum values.
 
70
 
 
71
    \mainclass
 
72
    \ingroup tools
 
73
 
 
74
    The QFlags<Enum> class is a template class, where Enum is an enum
 
75
    type. QFlags is used throughout Qt for storing combinations of
 
76
    enum values.
 
77
 
 
78
    The traditional C++ approach for storing OR-combinations of enum
 
79
    values is to use a \c int or \c uint variable. The inconvenient
 
80
    with that approach is that there's no type checking at all; any
 
81
    enum value can be OR'd with any other enum value and passed on to
 
82
    a function that takes a \c int or \c uint.
 
83
 
 
84
    Qt uses QFlags to provide type safety. For example, the
 
85
    Qt::Alignment type is simply a typedef for
 
86
    QFlags<Qt::AlignmentFlag>. QLabel::setAlignment() takes a
 
87
    Qt::Alignment parameter, which means that any combination of
 
88
    Qt::AlignmentFlag values is legal:
 
89
 
 
90
    \code
 
91
        label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
 
92
    \endcode
 
93
 
 
94
    If you try to pass a value from another enum, the compiler will
 
95
    report an error.
 
96
 
 
97
    If you want to use QFlags for your own enum types, you must use
 
98
    the Q_DECLARE_FLAGS() and Q_DECLARE_OPERATORS_FOR_FLAGS().
 
99
    For example:
 
100
 
 
101
    \code
 
102
        class MyClass
 
103
        {
 
104
        public:
 
105
            enum Option {
 
106
                NoOptions = 0x0,
 
107
                ShowTabs = 0x1,
 
108
                ShowAll = 0x2,
 
109
                SqueezeBlank = 0x4
 
110
            };
 
111
            Q_DECLARE_FLAGS(Options, Option)
 
112
            ...
 
113
        };
 
114
 
 
115
        Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::Options)
 
116
    \endcode
 
117
 
 
118
    You can then use the \c MyClass::Options type to store
 
119
    combinations of \c MyClass::Option values.
 
120
 
 
121
    A sensible naming convension for enum types and associated QFlags
 
122
    types is to give a singular name to the enum type (e.g., \c
 
123
    Option) and a plural name to the QFlags type (e.g., \c Options).
 
124
    When a singular name is desired for the QFlags type (e.g., \c
 
125
    Alignment), you can use \c Flag as the suffix for the enum type
 
126
    (e.g., \c AlignmentFlag).
 
127
 
 
128
    \sa QFlag
 
129
*/
 
130
 
 
131
/*!
 
132
    \typedef QFlags::enum_type
 
133
 
 
134
    Typedef for the Enum template type.
 
135
*/
 
136
 
 
137
/*!
 
138
    \fn QFlags::QFlags(const QFlags &other)
 
139
 
 
140
    Constructs a copy of \a other.
 
141
*/
 
142
 
 
143
/*!
 
144
    \fn QFlags::QFlags(Enum flag)
 
145
 
 
146
    Constructs a QFlags object storing the given \a flag.
 
147
*/
 
148
 
 
149
/*!
 
150
    \fn QFlags::QFlags(Zero zero)
 
151
 
 
152
    Constructs a QFlags object with no flags set. \a zero must be a
 
153
    literal 0 value.
 
154
*/
 
155
 
 
156
/*!
 
157
    \fn QFlags::QFlags(QFlag value)
 
158
 
 
159
    Constructs a QFlags object initialized with the given integer \a
 
160
    value.
 
161
 
 
162
    The QFlag type is a helper type. By using it here instead of \c
 
163
    int, we effectively ensure that arbitrary enum values cannot be
 
164
    cast to a QFlags, whereas untyped enum values (i.e., \c int
 
165
    values) can.
 
166
*/
 
167
 
 
168
/*!
 
169
    \fn QFlags &QFlags::operator=(const QFlags &other)
 
170
 
 
171
    Assigns \a other to this object and returns a reference to this
 
172
    object.
 
173
*/
 
174
 
 
175
/*!
 
176
    \fn QFlags &QFlags::operator&=(int mask)
 
177
 
 
178
    Performs a bitwise AND operation with \a mask and stores the
 
179
    result in this QFlags object. Returns a reference to this object.
 
180
 
 
181
    \sa operator&(), operator|=(), operator^=()
 
182
*/
 
183
 
 
184
/*!
 
185
    \fn QFlags &QFlags::operator&=(uint mask)
 
186
 
 
187
    \overload
 
188
*/
 
189
 
 
190
/*!
 
191
    \fn QFlags &QFlags::operator|=(QFlags other)
 
192
 
 
193
    Performs a bitwise OR operation with \a other and stores the
 
194
    result in this QFlags object. Returns a reference to this object.
 
195
 
 
196
    \sa operator|(), operator&=(), operator^=()
 
197
*/
 
198
 
 
199
/*!
 
200
    \fn QFlags &QFlags::operator|=(Enum other)
 
201
 
 
202
    \overload
 
203
*/
 
204
 
 
205
/*!
 
206
    \fn QFlags &QFlags::operator^=(QFlags other)
 
207
 
 
208
    Performs a bitwise XOR operation with \a other and stores the
 
209
    result in this QFlags object. Returns a reference to this object.
 
210
 
 
211
    \sa operator^(), operator&=(), operator|=()
 
212
*/
 
213
 
 
214
/*!
 
215
    \fn QFlags &QFlags::operator^=(Enum other)
 
216
 
 
217
    \overload
 
218
*/
 
219
 
 
220
/*!
 
221
    \fn QFlags::operator int() const
 
222
 
 
223
    Returns the value stored in the QFlags object as an integer.
 
224
*/
 
225
 
 
226
/*!
 
227
    \fn QFlags QFlags::operator|(QFlags other) const
 
228
 
 
229
    Returns a QFlags object containing the result of the bitwise OR
 
230
    operation on this object and \a other.
 
231
 
 
232
    \sa operator|=(), operator^(), operator&(), operator~()
 
233
*/
 
234
 
 
235
/*!
 
236
    \fn QFlags QFlags::operator|(Enum other) const
 
237
 
 
238
    \overload
 
239
*/
 
240
 
 
241
/*!
 
242
    \fn QFlags QFlags::operator^(QFlags other) const
 
243
 
 
244
    Returns a QFlags object containing the result of the bitwise XOR
 
245
    operation on this object and \a other.
 
246
 
 
247
    \sa operator^=(), operator&(), operator|(), operator~()
 
248
*/
 
249
 
 
250
/*!
 
251
    \fn QFlags QFlags::operator^(Enum other) const
 
252
 
 
253
    \overload
 
254
*/
 
255
 
 
256
/*!
 
257
    \fn QFlags QFlags::operator&(int mask) const
 
258
 
 
259
    Returns a QFlags object containing the result of the bitwise AND
 
260
    operation on this object and \a mask.
 
261
 
 
262
    \sa operator&=(), operator|(), operator^(), operator~()
 
263
*/
 
264
 
 
265
/*!
 
266
    \fn QFlags QFlags::operator&(uint mask) const
 
267
 
 
268
    \overload
 
269
*/
 
270
 
 
271
/*!
 
272
    \fn QFlags QFlags::operator&(Enum mask) const
 
273
 
 
274
    \overload
 
275
*/
 
276
 
 
277
/*!
 
278
    \fn QFlags QFlags::operator~() const
 
279
 
 
280
    Returns a QFlags object that contains the bitwise negation of
 
281
    this objec;t.
 
282
 
 
283
    \sa operator&(), operator|(), operator^()
 
284
*/
 
285
 
 
286
/*!
 
287
    \fn bool QFlags::operator!() const
 
288
 
 
289
    Returns true if no flag is set (i.e., if the value stored by the
 
290
    QFlags object is 0); otherwise returns false.
 
291
*/
 
292
 
 
293
/*!
 
294
    \macro Q_DECLARE_FLAGS(Flags, Enum)
 
295
    \relates QFlags
 
296
 
 
297
    The Q_DECLARE_FLAGS() macro expands to
 
298
 
 
299
    \code
 
300
        typedef QFlags<Enum> Flags;
 
301
    \endcode
 
302
 
 
303
    \a Enum is the name of an existing enum type, whereas \a Flags is
 
304
    the name of the QFlags<\e{Enum}> typedef.
 
305
 
 
306
    See the QFlags documentation for details.
 
307
 
 
308
    \sa Q_DECLARE_OPERATORS_FOR_FLAGS()
 
309
*/
 
310
 
 
311
/*!
 
312
    \macro Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
 
313
    \relates QFlags
 
314
 
 
315
    The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global \c
 
316
    operator|() functions for \a Flags, which is of type QFlags<T>.
 
317
 
 
318
    See the QFlags documentation for details.
 
319
 
 
320
    \sa Q_DECLARE_FLAGS()
 
321
*/
 
322
 
 
323
/*!
 
324
    \headerfile <QtGlobal>
 
325
    \title Global Qt Declarations
 
326
 
 
327
    \brief The <QtGlobal> header file provides basic declarations and is included by all other Qt headers.
 
328
 
 
329
    \sa <QtAlgorithms>
 
330
*/
 
331
 
 
332
/*!
 
333
    \typedef qreal
 
334
    \relates <QtGlobal>
 
335
 
 
336
    Typedef for \c double.
 
337
*/
 
338
 
 
339
/*! \typedef uchar
 
340
    \relates <QtGlobal>
 
341
 
 
342
    Convenience typedef for \c{unsigned char}.
 
343
*/
 
344
 
 
345
/*! \typedef ushort
 
346
    \relates <QtGlobal>
 
347
 
 
348
    Convenience typedef for \c{unsigned short}.
 
349
*/
 
350
 
 
351
/*! \typedef uint
 
352
    \relates <QtGlobal>
 
353
 
 
354
    Convenience typedef for \c{unsigned int}.
 
355
*/
 
356
 
 
357
/*! \typedef ulong
 
358
    \relates <QtGlobal>
 
359
 
 
360
    Convenience typedef for \c{unsigned long}.
 
361
*/
 
362
 
 
363
/*! \typedef qint8
 
364
    \relates <QtGlobal>
 
365
 
 
366
    Typedef for \c{signed char}. This type is guaranteed to be 8-bit
 
367
    on all platforms supported by Qt.
 
368
*/
 
369
 
 
370
/*! \typedef quint8
 
371
    \relates <QtGlobal>
 
372
 
 
373
    Typedef for \c{unsigned signed char}. This type is guaranteed to
 
374
    be 8-bit on all platforms supported by Qt.
 
375
*/
 
376
 
 
377
/*! \typedef qint16
 
378
    \relates <QtGlobal>
 
379
 
 
380
    Typedef for \c{signed short}. This type is guaranteed to be
 
381
    16-bit on all platforms supported by Qt.
 
382
*/
 
383
 
 
384
/*! \typedef quint16
 
385
    \relates <QtGlobal>
 
386
 
 
387
    Typedef for \c{unsigned signed short}. This type is guaranteed to
 
388
    be 16-bit on all platforms supported by Qt.
 
389
*/
 
390
 
 
391
/*! \typedef qint32
 
392
    \relates <QtGlobal>
 
393
 
 
394
    Typedef for \c{signed int}. This type is guaranteed to be 32-bit
 
395
    on all platforms supported by Qt.
 
396
*/
 
397
 
 
398
/*! \typedef quint32
 
399
    \relates <QtGlobal>
 
400
 
 
401
    Typedef for \c{unsigned signed int}. This type is guaranteed to
 
402
    be 32-bit on all platforms supported by Qt.
 
403
*/
 
404
 
 
405
/*! \typedef qint64
 
406
    \relates <QtGlobal>
 
407
 
 
408
    Typedef for \c{long long int} (\c __int64 on Windows). This type
 
409
    is guaranteed to be 64-bit on all platforms supported by Qt.
 
410
 
 
411
    Literals of that type can be created using the Q_INT64_C() macro:
 
412
 
 
413
    \code
 
414
        qint64 value = Q_INT64_C(932838457459459);
 
415
    \endcode
 
416
 
 
417
    \sa Q_INT64_C(), quint64
 
418
*/
 
419
 
 
420
/*! \typedef quint64
 
421
    \relates <QtGlobal>
 
422
 
 
423
    Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
 
424
    Windows). This type is guaranteed to be 64-bit on all platforms
 
425
    supported by Qt.
 
426
 
 
427
    Literals of that type can be created using the Q_UINT64_C()
 
428
    macro:
 
429
 
 
430
    \code
 
431
        quint64 value = Q_UINT64_C(932838457459459);
 
432
    \endcode
 
433
 
 
434
    \sa Q_UINT64_C(), qint64
 
435
*/
 
436
 
 
437
/*! \macro qint64 Q_INT64_C(literal)
 
438
    \relates <QtGlobal>
 
439
 
 
440
    Wraps the signed 64-bit integer \a literal in a
 
441
    platform-independent way. For example:
 
442
 
 
443
    \code
 
444
        qint64 value = Q_INT64_C(932838457459459);
 
445
    \endcode
 
446
 
 
447
    \sa qint64, Q_UINT64_C()
 
448
*/
 
449
 
 
450
/*! \macro quint64 Q_UINT64_C(literal)
 
451
    \relates <QtGlobal>
 
452
 
 
453
    Wraps the unsigned 64-bit integer \a literal in a
 
454
    platform-independent way. For example:
 
455
 
 
456
    \code
 
457
        quint64 value = Q_UINT64_C(932838457459459);
 
458
    \endcode
 
459
 
 
460
    \sa quint64, Q_INT64_C()
 
461
*/
 
462
 
 
463
/*! \typedef qlonglong
 
464
    \relates <QtGlobal>
 
465
 
 
466
    Typedef for \c{long long int} (\c __int64 on Windows). This is
 
467
    the same as \l qint64.
 
468
 
 
469
    \sa Q_INT64_C(), qulonglong
 
470
*/
 
471
 
 
472
/*! \typedef qulonglong
 
473
    \relates <QtGlobal>
 
474
 
 
475
    Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
 
476
    Windows). This is the same as \l quint64.
 
477
 
 
478
    \sa Q_UINT64_C(), qlonglong
 
479
*/
 
480
 
 
481
/*! \fn const T &qAbs(const T &value)
 
482
    \relates <QtGlobal>
 
483
 
 
484
    Returns the absolute value of \a value.
 
485
*/
 
486
 
 
487
/*! \fn int qRound(double value)
 
488
    \relates <QtGlobal>
 
489
 
 
490
    Rounds \a value up to the nearest integer.
 
491
*/
 
492
 
 
493
/*! \fn qint64 qRound64(double value)
 
494
    \relates <QtGlobal>
 
495
 
 
496
    Rounds \a value up to the nearest 64-bit integer.
 
497
*/
 
498
 
 
499
/*! \fn const T &qMin(const T &value1, const T &value2)
 
500
    \relates <QtGlobal>
 
501
 
 
502
    Returns the minimum of \a value1 and \a value2.
 
503
 
 
504
    \sa qMax(), qBound()
 
505
*/
 
506
 
 
507
/*! \fn const T &qMax(const T &value1, const T &value2)
 
508
    \relates <QtGlobal>
 
509
 
 
510
    Returns the maximum of \a value1 and \a value2.
 
511
 
 
512
    \sa qMin(), qBound()
 
513
*/
 
514
 
 
515
/*! \fn const T &qBound(const T &min, const T &value, const T &max)
 
516
    \relates <QtGlobal>
 
517
 
 
518
    Returns \a value bounded by \a min and \a max. This is equivalent
 
519
    to qMax(\a min, qMin(\a value, \a max)).
 
520
 
 
521
    \sa qMin(), qMax()
 
522
*/
 
523
 
 
524
/*!
 
525
    \typedef Q_INT8
 
526
    \relates <QtGlobal>
 
527
    \compat
 
528
 
 
529
    Use \l qint8 instead.
 
530
*/
 
531
 
 
532
/*!
 
533
    \typedef Q_UINT8
 
534
    \relates <QtGlobal>
 
535
    \compat
 
536
 
 
537
    Use \l quint8 instead.
 
538
*/
 
539
 
 
540
/*!
 
541
    \typedef Q_INT16
 
542
    \relates <QtGlobal>
 
543
    \compat
 
544
 
 
545
    Use \l qint16 instead.
 
546
*/
 
547
 
 
548
/*!
 
549
    \typedef Q_UINT16
 
550
    \relates <QtGlobal>
 
551
    \compat
 
552
 
 
553
    Use \l quint16 instead.
 
554
*/
 
555
 
 
556
/*!
 
557
    \typedef Q_INT32
 
558
    \relates <QtGlobal>
 
559
    \compat
 
560
 
 
561
    Use \l qint32 instead.
 
562
*/
 
563
 
 
564
/*!
 
565
    \typedef Q_UINT32
 
566
    \relates <QtGlobal>
 
567
    \compat
 
568
 
 
569
    Use \l quint32 instead.
 
570
*/
 
571
 
 
572
/*!
 
573
    \typedef Q_INT64
 
574
    \relates <QtGlobal>
 
575
    \compat
 
576
 
 
577
    Use \l qint64 instead.
 
578
*/
 
579
 
 
580
/*!
 
581
    \typedef Q_UINT64
 
582
    \relates <QtGlobal>
 
583
    \compat
 
584
 
 
585
    Use \l quint64 instead.
 
586
*/
 
587
 
 
588
/*!
 
589
    \typedef Q_LLONG
 
590
    \relates <QtGlobal>
 
591
    \compat
 
592
 
 
593
    Use \l qint64 instead.
 
594
*/
 
595
 
 
596
/*!
 
597
    \typedef Q_ULLONG
 
598
    \relates <QtGlobal>
 
599
    \compat
 
600
 
 
601
    Use \l quint64 instead.
 
602
*/
 
603
 
 
604
/*!
 
605
    \typedef Q_LONG
 
606
    \relates <QtGlobal>
 
607
    \compat
 
608
 
 
609
    Use \c{void *} instead.
 
610
*/
 
611
 
 
612
/*!
 
613
    \typedef Q_ULONG
 
614
    \relates <QtGlobal>
 
615
    \compat
 
616
 
 
617
    Use \c{void *} instead.
 
618
*/
 
619
 
 
620
/*! \fn bool qSysInfo(int *wordSize, bool *bigEndian)
 
621
    \relates <QtGlobal>
 
622
 
 
623
    Use QSysInfo::WordSize and QSysInfo::ByteOrder instead.
 
624
*/
 
625
 
 
626
/*!
 
627
    \fn bool qt_winUnicode()
 
628
    \relates <QtGlobal>
 
629
 
 
630
    Use !(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) instead.
 
631
 
 
632
    \sa QSysInfo
 
633
*/
 
634
 
 
635
/*!
 
636
    \fn int qWinVersion()
 
637
    \relates <QtGlobal>
 
638
 
 
639
    Use QSysInfo::WindowsVersion instead.
 
640
 
 
641
    \sa QSysInfo
 
642
*/
 
643
 
 
644
/*!
 
645
    \fn int qMacVersion()
 
646
    \relates <QtGlobal>
 
647
 
 
648
    Use QSysInfo::MacintoshVersion instead.
 
649
 
 
650
    \sa QSysInfo
 
651
*/
 
652
 
 
653
/*!
 
654
    \relates <QtGlobal>
 
655
 
 
656
    Returns the Qt version number as a string, for example, "4.0.1" or
 
657
    "4.1.3".
 
658
 
 
659
    The \c QT_VERSION define has the numeric value in the form:
 
660
    0xMMNNPP (MM = major, NN = minor, PP = patch). For example, Qt
 
661
    4.0.1's \c QT_VERSION is 0x040001.
 
662
*/
 
663
 
 
664
const char *qVersion()
 
665
{
 
666
    return QT_VERSION_STR;
 
667
}
 
668
 
 
669
bool qSharedBuild()
 
670
{
 
671
#ifdef QT_SHARED
 
672
    return true;
 
673
#else
 
674
    return false;
 
675
#endif
 
676
}
 
677
 
 
678
/*****************************************************************************
 
679
  System detection routines
 
680
 *****************************************************************************/
 
681
 
 
682
/*!
 
683
    \class QSysInfo
 
684
    \brief The QSysInfo class provides information about the system.
 
685
 
 
686
    \list
 
687
    \o \l WordSize specifies the size of a pointer for the platform
 
688
       on which the application is compiled.
 
689
    \o \l ByteOrder specifies whether the platform is big-endian or
 
690
       little-endian.
 
691
    \o \l WindowsVersion specifies the version of the Windows operating
 
692
       system on which the application is run (Windows only)
 
693
    \o \l MacintoshVersion specifies the version of the Macintosh
 
694
       operating system on which the application is run (Mac only).
 
695
    \endlist
 
696
 
 
697
    Some constants are defined only on certain platforms. You can use
 
698
    the preprocessor symbols \c Q_WS_WIN and \c Q_WS_MAC to test that
 
699
    the application is compiled under Windows or Mac.
 
700
 
 
701
    \sa QLibraryInfo
 
702
*/
 
703
 
 
704
/*!
 
705
    \variable QSysInfo::WordSize
 
706
    \brief the size in bits of a pointer for the platform on which
 
707
           the application is compiled (32 or 64)
 
708
*/
 
709
 
 
710
/*!
 
711
    \variable QSysInfo::WindowsVersion
 
712
    \brief the version of the Windows operating system on which the
 
713
           application is run (Windows only)
 
714
*/
 
715
 
 
716
/*!
 
717
    \variable QSysInfo::MacintoshVersion
 
718
    \brief the version of the Macintosh operating system on which
 
719
           the application is run (Mac only).
 
720
*/
 
721
 
 
722
/*!
 
723
    \enum QSysInfo::Endian
 
724
 
 
725
    \value BigEndian  Big-endian byte order (also called Network byte order)
 
726
    \value LittleEndian  Little-endian byte order
 
727
    \value ByteOrder  Equals BigEndian or LittleEndian, depending on
 
728
                      the platform's byte order.
 
729
*/
 
730
 
 
731
/*!
 
732
    \enum QSysInfo::WinVersion
 
733
 
 
734
    This enum provides symbolic names for the various versions of the
 
735
    Windows operating system. On Windows, the
 
736
    QSysInfo::WindowsVersion variable gives the version of the system
 
737
    on which the application is run.
 
738
 
 
739
    MS-DOS-based versions:
 
740
 
 
741
    \value WV_32s   Windows 3.1 wth Win 32s
 
742
    \value WV_95    Windows 95
 
743
    \value WV_98    Windows 98
 
744
    \value WV_Me    Windows Me
 
745
 
 
746
    NT-based versions:
 
747
 
 
748
    \value WV_NT    Windows NT
 
749
    \value WV_2000  Windows 2000
 
750
    \value WV_XP    Windows XP
 
751
    \value WV_2003  Windows XP 2003
 
752
 
 
753
    CE-based versions:
 
754
 
 
755
    \value WV_CE    Windows CE
 
756
    \value WV_CENET Windows CE .NET
 
757
 
 
758
    The following masks can be used for testing whether a Windows
 
759
    version is MS-DOS-based, NT-based, or CE-based:
 
760
 
 
761
    \value WV_DOS_based MS-DOS-based version of Windows
 
762
    \value WV_NT_based  NT-based version of Windows
 
763
    \value WV_CE_based  CE-based version of Windows
 
764
 
 
765
    \sa MacVersion
 
766
*/
 
767
 
 
768
/*!
 
769
    \enum QSysInfo::MacVersion
 
770
 
 
771
    This enum provides symbolic names for the various versions of the
 
772
    Macintosh operating system. On Mac, the
 
773
    QSysInfo::MacintoshVersion variable gives the version of the
 
774
    system on which the application is run.
 
775
 
 
776
    \value MV_9        MacOS 9 (unsupported)
 
777
    \value MV_10_0     Mac OS X 10.0
 
778
    \value MV_10_1     Mac OS X 10.1
 
779
    \value MV_10_2     Mac OS X 10.2
 
780
    \value MV_10_3     Mac OS X 10.3
 
781
    \value MV_10_4     Mac OS X 10.4
 
782
    \value MV_Unknown  Other
 
783
 
 
784
    \sa WinVersion
 
785
*/
 
786
 
 
787
#if !defined(Q_BYTE_ORDER) && defined(QT_BUILD_QMAKE)
 
788
// needed to bootstrap qmake
 
789
static const unsigned int qt_one = 1;
 
790
const int QSysInfo::ByteOrder = ((*((unsigned char *) &qt_one) == 0) ? BigEndian : LittleEndian);
 
791
#endif
 
792
 
 
793
#if !defined(QWS) && defined(Q_OS_MAC)
 
794
 
 
795
#include <private/qcore_mac_p.h>
 
796
#include "qnamespace.h"
 
797
 
 
798
// This function has descended from Apple Source Code (FSpLocationFromFullPath),
 
799
// but changes have been made. [Creates a minimal alias from the full pathname]
 
800
Q_CORE_EXPORT OSErr qt_mac_create_fsspec(const QString &file, FSSpec *spec)
 
801
{
 
802
    FSRef fref;
 
803
    QByteArray utfs = file.toUtf8();
 
804
    OSErr ret = FSPathMakeRef((const UInt8 *)utfs.data(), &fref, NULL);
 
805
    if(ret == noErr)
 
806
        ret = FSGetCatalogInfo(&fref, kFSCatInfoNone, NULL, NULL, spec, NULL);
 
807
    return ret;
 
808
}
 
809
 
 
810
Q_CORE_EXPORT void qt_mac_to_pascal_string(QString s, Str255 str, TextEncoding encoding=0, int len=-1)
 
811
{
 
812
    if(len == -1)
 
813
        len = s.length();
 
814
#if 0
 
815
    UnicodeMapping mapping;
 
816
    mapping.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault,
 
817
                                                 kTextEncodingDefaultVariant,
 
818
                                                 kUnicode16BitFormat);
 
819
    mapping.otherEncoding = (encoding ? encoding : );
 
820
    mapping.mappingVersion = kUnicodeUseLatestMapping;
 
821
 
 
822
    UnicodeToTextInfo info;
 
823
    OSStatus err = CreateUnicodeToTextInfo(&mapping, &info);
 
824
    if(err != noErr) {
 
825
        qDebug("Qt: internal: Unable to create pascal string '%s'::%d [%ld]",
 
826
               s.left(len).latin1(), (int)encoding, err);
 
827
        return;
 
828
    }
 
829
    const int unilen = len * 2;
 
830
    const UniChar *unibuf = (UniChar *)s.unicode();
 
831
    ConvertFromUnicodeToPString(info, unilen, unibuf, str);
 
832
    DisposeUnicodeToTextInfo(&info);
 
833
#else
 
834
    Q_UNUSED(encoding);
 
835
    CFStringGetPascalString(QCFString(s), str, 256, CFStringGetSystemEncoding());
 
836
#endif
 
837
}
 
838
 
 
839
Q_CORE_EXPORT QString qt_mac_from_pascal_string(const Str255 pstr) {
 
840
    return QCFString(CFStringCreateWithPascalString(0, pstr, CFStringGetSystemEncoding()));
 
841
}
 
842
 
 
843
static QSysInfo::MacVersion macVersion()
 
844
{
 
845
    long gestalt_version;
 
846
    if (Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) {
 
847
        if (gestalt_version >= 0x1040 && gestalt_version < 0x1050)
 
848
            return QSysInfo::MV_10_4;
 
849
        else if (gestalt_version >= 0x1030 && gestalt_version < 0x1040)
 
850
            return QSysInfo::MV_10_3;
 
851
        else if (gestalt_version >= 0x1020 && gestalt_version < 0x1030)
 
852
            return QSysInfo::MV_10_2;
 
853
        else if (gestalt_version >= 0x1010 && gestalt_version < 0x1020)
 
854
            return QSysInfo::MV_10_1;
 
855
        else if (gestalt_version >= 0x1000 && gestalt_version < 0x1010)
 
856
            return QSysInfo::MV_10_0;
 
857
    }
 
858
    return QSysInfo::MV_Unknown;
 
859
}
 
860
const QSysInfo::MacVersion QSysInfo::MacintoshVersion = macVersion();
 
861
#elif defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) || defined(Q_OS_TEMP)
 
862
 
 
863
#include "qt_windows.h"
 
864
 
 
865
static QSysInfo::WinVersion winVersion()
 
866
{
 
867
#ifndef VER_PLATFORM_WIN32s
 
868
#define VER_PLATFORM_WIN32s            0
 
869
#endif
 
870
#ifndef VER_PLATFORM_WIN32_WINDOWS
 
871
#define VER_PLATFORM_WIN32_WINDOWS  1
 
872
#endif
 
873
#ifndef VER_PLATFORM_WIN32_NT
 
874
#define VER_PLATFORM_WIN32_NT            2
 
875
#endif
 
876
#ifndef VER_PLATFORM_WIN32_CE
 
877
#define VER_PLATFORM_WIN32_CE            3
 
878
#endif
 
879
 
 
880
    static QSysInfo::WinVersion winver = QSysInfo::WV_NT;
 
881
#ifndef Q_OS_TEMP
 
882
    OSVERSIONINFOA osver;
 
883
    osver.dwOSVersionInfoSize = sizeof(osver);
 
884
    GetVersionExA(&osver);
 
885
#else
 
886
    DWORD qt_cever = 0;
 
887
    OSVERSIONINFOW osver;
 
888
    osver.dwOSVersionInfoSize = sizeof(osver);
 
889
    GetVersionEx(&osver);
 
890
    qt_cever = osver.dwMajorVersion * 100;
 
891
    qt_cever += osver.dwMinorVersion * 10;
 
892
#endif
 
893
    switch (osver.dwPlatformId) {
 
894
    case VER_PLATFORM_WIN32s:
 
895
        winver = QSysInfo::WV_32s;
 
896
        break;
 
897
    case VER_PLATFORM_WIN32_WINDOWS:
 
898
        // We treat Windows Me (minor 90) the same as Windows 98
 
899
        if (osver.dwMinorVersion == 90)
 
900
            winver = QSysInfo::WV_Me;
 
901
        else if (osver.dwMinorVersion == 10)
 
902
            winver = QSysInfo::WV_98;
 
903
        else
 
904
            winver = QSysInfo::WV_95;
 
905
        break;
 
906
#ifdef Q_OS_TEMP
 
907
    case VER_PLATFORM_WIN32_CE:
 
908
#ifdef Q_OS_TEMP
 
909
        if (qt_cever >= 400)
 
910
            winver = QSysInfo::WV_CENET;
 
911
        else
 
912
#endif
 
913
            winver = QSysInfo::WV_CE;
 
914
        break;
 
915
#endif
 
916
    default: // VER_PLATFORM_WIN32_NT
 
917
        if (osver.dwMajorVersion < 5) {
 
918
            winver = QSysInfo::WV_NT;
 
919
        } else if (osver.dwMinorVersion == 0) {
 
920
            winver = QSysInfo::WV_2000;
 
921
        } else if (osver.dwMinorVersion == 1) {
 
922
            winver = QSysInfo::WV_XP;
 
923
        } else if (osver.dwMinorVersion == 2) {
 
924
            winver = QSysInfo::WV_2003;
 
925
        } else {
 
926
            qWarning("Untested Windows version detected!");
 
927
            winver = QSysInfo::WV_NT_based;
 
928
        }
 
929
    }
 
930
 
 
931
    return winver;
 
932
}
 
933
 
 
934
const QSysInfo::WinVersion QSysInfo::WindowsVersion = winVersion();
 
935
 
 
936
#endif
 
937
 
 
938
 
 
939
/*!
 
940
    \macro void Q_ASSERT(bool test)
 
941
    \relates <QtGlobal>
 
942
 
 
943
    Prints a warning message containing the source code file name and
 
944
    line number if \a test is false.
 
945
 
 
946
    Q_ASSERT() is useful for testing pre- and post-conditions
 
947
    during development. It does nothing if \c QT_NO_DEBUG was defined
 
948
    during compilation.
 
949
 
 
950
    Example:
 
951
    \code
 
952
        //
 
953
        // File: div.cpp
 
954
        //
 
955
 
 
956
        #include <QtGlobal>
 
957
 
 
958
        int divide(int a, int b)
 
959
        {
 
960
            Q_ASSERT(b != 0);
 
961
            return a / b;
 
962
        }
 
963
    \endcode
 
964
 
 
965
    If \c b is zero, the Q_ASSERT statement will output the following
 
966
    message using the qFatal() function:
 
967
 
 
968
    \code
 
969
        ASSERT: "b == 0" in file div.cpp, line 9
 
970
    \endcode
 
971
 
 
972
    \sa Q_ASSERT_X(), qFatal(), {Debugging Techniques}
 
973
*/
 
974
 
 
975
/*!
 
976
    \macro void Q_ASSERT_X(bool test, const char *where, const char *what)
 
977
    \relates <QtGlobal>
 
978
 
 
979
    Prints the message \a what together with the location \a where,
 
980
    the source file name and line number if \a test is false.
 
981
 
 
982
    Q_ASSERT_X is useful for testing pre- and post-conditions during
 
983
    development. It does nothing if \c QT_NO_DEBUG was defined during
 
984
    compilation.
 
985
 
 
986
    Example:
 
987
    \code
 
988
        //
 
989
        // File: div.cpp
 
990
        //
 
991
 
 
992
        #include <QtGlobal>
 
993
 
 
994
        int divide(int a, int b)
 
995
        {
 
996
            Q_ASSERT_X(b != 0, "divide", "division by zero");
 
997
            return a/b;
 
998
        }
 
999
    \endcode
 
1000
 
 
1001
    If \c b is zero, the Q_ASSERT_X statement will output the following
 
1002
    message using the qFatal() function:
 
1003
 
 
1004
    \code
 
1005
        ASSERT failure in divide: "division by zero", file div.cpp, line 9
 
1006
    \endcode
 
1007
 
 
1008
    \sa Q_ASSERT(), qFatal(), {Debugging Techniques}
 
1009
*/
 
1010
 
 
1011
/*!
 
1012
    \macro void Q_CHECK_PTR(void *p)
 
1013
    \relates <QtGlobal>
 
1014
 
 
1015
    If \a p is 0, prints a warning message containing the source code file
 
1016
    name and line number, saying that the program ran out of memory.
 
1017
 
 
1018
    Q_CHECK_PTR does nothing if \c QT_NO_DEBUG was defined during
 
1019
    compilation.
 
1020
 
 
1021
    Example:
 
1022
    \code
 
1023
        int *a;
 
1024
 
 
1025
        Q_CHECK_PTR(a = new int[80]);  // WRONG!
 
1026
 
 
1027
        a = new (nothrow) int[80];       // Right
 
1028
        Q_CHECK_PTR(a);
 
1029
    \endcode
 
1030
 
 
1031
    \sa qWarning(), {Debugging Techniques}
 
1032
*/
 
1033
 
 
1034
 
 
1035
/*
 
1036
  The Q_CHECK_PTR macro calls this function if an allocation check
 
1037
  fails.
 
1038
*/
 
1039
void qt_check_pointer(const char *n, int l)
 
1040
{
 
1041
    qWarning("In file %s, line %d: Out of memory", n, l);
 
1042
}
 
1043
 
 
1044
/*
 
1045
  The Q_ASSERT macro calls this this function when the test fails.
 
1046
*/
 
1047
void qt_assert(const char *assertion, const char *file, int line)
 
1048
{
 
1049
    qFatal("ASSERT: \"%s\" in file %s, line %d", assertion, file, line);
 
1050
}
 
1051
 
 
1052
/*
 
1053
  The Q_ASSERT_X macro calls this this function when the test fails.
 
1054
*/
 
1055
void qt_assert_x(const char *where, const char *what, const char *file, int line)
 
1056
{
 
1057
    qFatal("ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line);
 
1058
}
 
1059
 
 
1060
 
 
1061
/*
 
1062
    Dijkstra's bisection algorithm to find the square root of an integer.
 
1063
    Deliberately not exported as part of the Qt API, but used in both
 
1064
    qsimplerichtext.cpp and qgfxraster_qws.cpp
 
1065
*/
 
1066
Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n)
 
1067
{
 
1068
    // n must be in the range 0...UINT_MAX/2-1
 
1069
    if (n >= (UINT_MAX>>2)) {
 
1070
        unsigned int r = 2 * qt_int_sqrt(n / 4);
 
1071
        unsigned int r2 = r + 1;
 
1072
        return (n >= r2 * r2) ? r2 : r;
 
1073
    }
 
1074
    uint h, p= 0, q= 1, r= n;
 
1075
    while (q <= n)
 
1076
        q <<= 2;
 
1077
    while (q != 1) {
 
1078
        q >>= 2;
 
1079
        h= p + q;
 
1080
        p >>= 1;
 
1081
        if (r >= h) {
 
1082
            p += q;
 
1083
            r -= h;
 
1084
        }
 
1085
    }
 
1086
    return p;
 
1087
}
 
1088
 
 
1089
#if defined(qMemCopy)
 
1090
#  undef qMemCopy
 
1091
#endif
 
1092
#if defined(qMemSet)
 
1093
#  undef qMemSet
 
1094
#endif
 
1095
 
 
1096
void *qMalloc(size_t size) { return ::malloc(size); }
 
1097
void qFree(void *ptr) { ::free(ptr); }
 
1098
void *qRealloc(void *ptr, size_t size) { return ::realloc(ptr, size); }
 
1099
void *qMemCopy(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); }
 
1100
void *qMemSet(void *dest, int c, size_t n) { return memset(dest, c, n); }
 
1101
 
 
1102
 
 
1103
static QtMsgHandler handler = 0;                // pointer to debug handler
 
1104
static const int QT_BUFFER_LENGTH = 8192;       // internal buffer length
 
1105
 
 
1106
#ifdef Q_CC_MWERKS
 
1107
#include <CoreServices/CoreServices.h>
 
1108
extern bool qt_is_gui_used;
 
1109
static void mac_default_handler(const char *msg)
 
1110
{
 
1111
    if (qt_is_gui_used) {
 
1112
        Str255 pmsg;
 
1113
        qt_mac_to_pascal_string(msg, pmsg);
 
1114
        DebugStr(pmsg);
 
1115
    } else {
 
1116
        fprintf(stderr, msg);
 
1117
    }
 
1118
}
 
1119
#endif // Q_CC_MWERKS
 
1120
 
 
1121
 
 
1122
QString qt_error_string(int errorCode)
 
1123
{
 
1124
    const char *s = 0;
 
1125
    QString ret;
 
1126
    if (errorCode == -1) {
 
1127
#if defined(Q_OS_WIN32)
 
1128
        errorCode = GetLastError();
 
1129
#else
 
1130
        errorCode = errno;
 
1131
#endif
 
1132
    }
 
1133
    switch (errorCode) {
 
1134
    case 0:
 
1135
        break;
 
1136
    case EACCES:
 
1137
        s = QT_TRANSLATE_NOOP("QIODevice", "Permission denied");
 
1138
        break;
 
1139
    case EMFILE:
 
1140
        s = QT_TRANSLATE_NOOP("QIODevice", "Too many open files");
 
1141
        break;
 
1142
    case ENOENT:
 
1143
        s = QT_TRANSLATE_NOOP("QIODevice", "No such file or directory");
 
1144
        break;
 
1145
    case ENOSPC:
 
1146
        s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device");
 
1147
        break;
 
1148
    default: {
 
1149
#ifdef Q_OS_WIN
 
1150
        QT_WA({
 
1151
            unsigned short *string = 0;
 
1152
            FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
 
1153
                          NULL,
 
1154
                          errorCode,
 
1155
                          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
 
1156
                          (LPTSTR)&string,
 
1157
                          0,
 
1158
                          NULL);
 
1159
            ret = QString::fromUtf16(string);
 
1160
            LocalFree((HLOCAL)string);
 
1161
        }, {
 
1162
            char *string = 0;
 
1163
            FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
 
1164
                           NULL,
 
1165
                           errorCode,
 
1166
                           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
 
1167
                           (LPSTR)&string,
 
1168
                           0,
 
1169
                           NULL);
 
1170
            ret = QString::fromLocal8Bit(string);
 
1171
            LocalFree((HLOCAL)string);
 
1172
        });
 
1173
#else
 
1174
        ret = QString::fromLocal8Bit(strerror(errorCode));
 
1175
#endif
 
1176
        break; }
 
1177
    }
 
1178
    if (s)
 
1179
        // ######## this breaks moc build currently
 
1180
//         ret = QCoreApplication::translate("QIODevice", s);
 
1181
        ret = QString::fromLatin1(s);
 
1182
    return ret.trimmed();
 
1183
}
 
1184
 
 
1185
/*!
 
1186
    \relates <QtGlobal>
 
1187
 
 
1188
    Installs a Qt message handler \a h. Returns a pointer to the
 
1189
    message handler previously defined.
 
1190
 
 
1191
    The message handler is a function that prints out debug messages,
 
1192
    warnings and fatal error messages. The Qt library (debug version)
 
1193
    contains hundreds of warning messages that are printed when
 
1194
    internal errors (usually invalid function arguments) occur. If you
 
1195
    implement your own message handler, you get total control of these
 
1196
    messages.
 
1197
 
 
1198
    The default message handler prints the message to the standard
 
1199
    output under X11 or to the debugger under Windows. If it is a
 
1200
    fatal message, the application aborts immediately.
 
1201
 
 
1202
    Only one message handler can be defined, since this is usually
 
1203
    done on an application-wide basis to control debug output.
 
1204
 
 
1205
    To restore the message handler, call \c qInstallMsgHandler(0).
 
1206
 
 
1207
    Example:
 
1208
    \code
 
1209
        #include <qapplication.h>
 
1210
        #include <stdio.h>
 
1211
        #include <stdlib.h>
 
1212
 
 
1213
        void myMessageOutput(QtMsgType type, const char *msg)
 
1214
        {
 
1215
            switch (type) {
 
1216
                case QtDebugMsg:
 
1217
                    fprintf(stderr, "Debug: %s\n", msg);
 
1218
                    break;
 
1219
                case QtWarningMsg:
 
1220
                    fprintf(stderr, "Warning: %s\n", msg);
 
1221
                    break;
 
1222
                case QtCriticalMsg:
 
1223
                    fprintf(stderr, "Critical: %s\n", msg);
 
1224
                    break;
 
1225
                case QtFatalMsg:
 
1226
                    fprintf(stderr, "Fatal: %s\n", msg);
 
1227
                    abort(); // deliberately core dump
 
1228
            }
 
1229
        }
 
1230
 
 
1231
        int main(int argc, char **argv)
 
1232
        {
 
1233
            qInstallMsgHandler(myMessageOutput);
 
1234
            QApplication a(argc, argv);
 
1235
            ...
 
1236
            return a.exec();
 
1237
        }
 
1238
    \endcode
 
1239
 
 
1240
    \sa qDebug(), qWarning(), qFatal(), {Debugging Techniques}
 
1241
*/
 
1242
QtMsgHandler qInstallMsgHandler(QtMsgHandler h)
 
1243
{
 
1244
    QtMsgHandler old = handler;
 
1245
    handler = h;
 
1246
    return old;
 
1247
}
 
1248
 
 
1249
 
 
1250
void qt_message_output(QtMsgType msgType, const char *buf)
 
1251
{
 
1252
    if (handler) {
 
1253
        (*handler)(msgType, buf);
 
1254
    } else {
 
1255
#if defined(Q_CC_MWERKS)
 
1256
        mac_default_handler(buf);
 
1257
#elif defined(Q_OS_TEMP)
 
1258
        QString fstr(buf);
 
1259
        OutputDebugString((fstr + "\n").utf16());
 
1260
#else
 
1261
        fprintf(stderr, "%s\n", buf);
 
1262
#endif
 
1263
    }
 
1264
 
 
1265
    if (msgType == QtFatalMsg
 
1266
        || (msgType == QtWarningMsg
 
1267
            && (!qgetenv("QT_FATAL_WARNINGS").isNull())) ) {
 
1268
 
 
1269
#if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR)
 
1270
        // get the current report mode
 
1271
        int reportMode = _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW);
 
1272
        _CrtSetReportMode(_CRT_ERROR, reportMode);
 
1273
        int ret = _CrtDbgReport(_CRT_ERROR, __FILE__, __LINE__, QT_VERSION_STR, buf);
 
1274
        if (ret == 0  && reportMode & _CRTDBG_MODE_WNDW)
 
1275
            return; // ignore
 
1276
        else if (ret == 1)
 
1277
            _CrtDbgBreak();
 
1278
#endif
 
1279
 
 
1280
#if defined(Q_OS_UNIX) && defined(QT_DEBUG)
 
1281
        abort(); // trap; generates core dump
 
1282
#else
 
1283
        exit(1); // goodbye cruel world
 
1284
#endif
 
1285
    }
 
1286
}
 
1287
 
 
1288
#undef qDebug
 
1289
/*!
 
1290
    \relates <QtGlobal>
 
1291
 
 
1292
    Calls the message handler with the debug message \a msg. If no
 
1293
    message handler has been installed, the message is printed to
 
1294
    stderr. Under Windows, the message is sent to the debugger. This
 
1295
    function does nothing if \c QT_NO_DEBUG_OUTPUT was defined during
 
1296
    compilation.
 
1297
 
 
1298
    If you pass the function a format string and a list of arguments,
 
1299
    it works in similar way to the C printf() function.
 
1300
 
 
1301
    Example:
 
1302
    \code
 
1303
        qDebug("my window handle = %x", myWidget->id());
 
1304
    \endcode
 
1305
 
 
1306
    A more convenient syntax is also available:
 
1307
    \code
 
1308
        qDebug() << "Brush:" << myQBrush << "Other value:" << i;
 
1309
    \endcode
 
1310
    This syntax automatically puts a single space between each item,
 
1311
    and outputs a newline at the end. It supports many C++ and Qt
 
1312
    types.
 
1313
 
 
1314
    \warning The internal buffer is limited to 8192 bytes, including
 
1315
    the '\0'-terminator.
 
1316
 
 
1317
    \warning Passing (const char *)0 as argument to qDebug might lead
 
1318
    to crashes on certain platforms due to the platform's printf() implementation.
 
1319
 
 
1320
    \sa qWarning(), qCritical(), qFatal(), qInstallMsgHandler(),
 
1321
        {Debugging Techniques}
 
1322
*/
 
1323
void qDebug(const char *msg, ...)
 
1324
{
 
1325
    char buf[QT_BUFFER_LENGTH];
 
1326
    buf[QT_BUFFER_LENGTH - 1] = '\0';
 
1327
    va_list ap;
 
1328
    va_start(ap, msg);                        // use variable arg list
 
1329
    qvsnprintf(buf, QT_BUFFER_LENGTH - 1, msg, ap);
 
1330
    va_end(ap);
 
1331
 
 
1332
    qt_message_output(QtDebugMsg, buf);
 
1333
}
 
1334
 
 
1335
#undef qWarning
 
1336
/*!
 
1337
    \relates <QtGlobal>
 
1338
 
 
1339
    Calls the message handler with the warning message \a msg. If no
 
1340
    message handler has been installed, the message is printed to
 
1341
    stderr. Under Windows, the message is sent to the debugger. This
 
1342
    function does nothing if \c QT_NO_WARNING_OUTPUT was defined
 
1343
    during compilation; it exits if the environment variable \c
 
1344
    QT_FATAL_WARNINGS is defined.
 
1345
 
 
1346
    This function takes a format string and a list of arguments,
 
1347
    similar to the C printf() function.
 
1348
 
 
1349
    Example:
 
1350
    \code
 
1351
        void f(int c)
 
1352
        {
 
1353
            if (c > 200)
 
1354
                qWarning("f: bad argument, c == %d", c);
 
1355
        }
 
1356
    \endcode
 
1357
 
 
1358
    \warning The internal buffer is limited to 8192 bytes, including
 
1359
    the '\0'-terminator.
 
1360
 
 
1361
    \warning Passing (const char *)0 as argument to qWarning might lead
 
1362
    to crashes on certain platforms due to the platforms printf implementation.
 
1363
 
 
1364
    \sa qDebug(), qCritical(), qFatal(), qInstallMsgHandler(),
 
1365
        {Debugging Techniques}
 
1366
*/
 
1367
void qWarning(const char *msg, ...)
 
1368
{
 
1369
    char buf[QT_BUFFER_LENGTH];
 
1370
    buf[QT_BUFFER_LENGTH - 1] = '\0';
 
1371
    va_list ap;
 
1372
    va_start(ap, msg); // use variable arg list
 
1373
    qvsnprintf(buf, QT_BUFFER_LENGTH - 1, msg, ap);
 
1374
    va_end(ap);
 
1375
 
 
1376
    qt_message_output(QtWarningMsg, buf);
 
1377
}
 
1378
 
 
1379
/*!
 
1380
    \relates <QtGlobal>
 
1381
 
 
1382
    Calls the message handler with the critical message \a msg. If no
 
1383
    message handler has been installed, the message is printed to
 
1384
    stderr. Under Windows, the message is sent to the debugger.
 
1385
 
 
1386
    This function takes a format string and a list of arguments, similar
 
1387
    to the C printf() function.
 
1388
 
 
1389
    Example:
 
1390
    \code
 
1391
        void load(const QString &filename)
 
1392
        {
 
1393
            QFile file(filename);
 
1394
            if (!file.exists())
 
1395
                qCritical("file '%s' does not exist!", filename.local8bit());
 
1396
        }
 
1397
    \endcode
 
1398
 
 
1399
    \warning The internal buffer is limited to 8192 bytes, including
 
1400
    the '\0'-terminator.
 
1401
 
 
1402
    \warning Passing (const char *)0 as argument to qCritical might
 
1403
    lead to crashes on certain platforms due to the platforms printf
 
1404
    implementation.
 
1405
 
 
1406
    \sa qDebug(), qWarning(), qFatal(), qInstallMsgHandler(),
 
1407
        {Debugging Techniques}
 
1408
*/
 
1409
void qCritical(const char *msg, ...)
 
1410
{
 
1411
    char buf[QT_BUFFER_LENGTH];
 
1412
    buf[QT_BUFFER_LENGTH - 1] = '\0';
 
1413
    va_list ap;
 
1414
    va_start(ap, msg); // use variable arg list
 
1415
    qvsnprintf(buf, QT_BUFFER_LENGTH - 1, msg, ap);
 
1416
    va_end(ap);
 
1417
 
 
1418
    qt_message_output(QtCriticalMsg, buf);
 
1419
}
 
1420
#ifdef QT3_SUPPORT
 
1421
void qSystemWarning(const char *msg, int code)
 
1422
   { qCritical("%s (%s)", msg, qt_error_string(code).toLocal8Bit().constData()); }
 
1423
#endif // QT3_SUPPORT
 
1424
 
 
1425
void qErrnoWarning(const char *msg, ...)
 
1426
{
 
1427
    char buf[QT_BUFFER_LENGTH];
 
1428
    buf[QT_BUFFER_LENGTH - 1] = '\0';
 
1429
    va_list ap;
 
1430
    va_start(ap, msg);
 
1431
    qvsnprintf(buf, QT_BUFFER_LENGTH - 1, msg, ap);
 
1432
    va_end(ap);
 
1433
 
 
1434
    qCritical("%s (%s)", buf, qt_error_string(-1).toLocal8Bit().constData());
 
1435
}
 
1436
 
 
1437
void qErrnoWarning(int code, const char *msg, ...)
 
1438
{
 
1439
    char buf[QT_BUFFER_LENGTH];
 
1440
    buf[QT_BUFFER_LENGTH - 1] = '\0';
 
1441
    va_list ap;
 
1442
    va_start(ap, msg);
 
1443
    qvsnprintf(buf, QT_BUFFER_LENGTH - 1, msg, ap);
 
1444
    va_end(ap);
 
1445
 
 
1446
    qCritical("%s (%s)", buf, qt_error_string(code).toLocal8Bit().constData());
 
1447
}
 
1448
 
 
1449
/*!
 
1450
    \relates <QtGlobal>
 
1451
 
 
1452
    Calls the message handler with the fatal message \a msg. If no
 
1453
    message handler has been installed, the message is printed to
 
1454
    stderr. Under Windows, the message is sent to the debugger.
 
1455
 
 
1456
    For a release library this function will exit the application
 
1457
    with return value 1. For the debug version this function will
 
1458
    abort on Unix systems to create a core dump, and report a
 
1459
    _CRT_ERROR on Windows allowing to connect a debugger to the
 
1460
    application.
 
1461
 
 
1462
    This function takes a format string and a list of arguments,
 
1463
    similar to the C printf() function.
 
1464
 
 
1465
    Example:
 
1466
    \code
 
1467
        int divide(int a, int b)
 
1468
        {
 
1469
            if (b == 0)                                // program error
 
1470
                qFatal("divide: cannot divide by zero");
 
1471
            return a / b;
 
1472
        }
 
1473
    \endcode
 
1474
 
 
1475
    \warning The internal buffer is limited to 8192 bytes, including
 
1476
    the '\0'-terminator.
 
1477
 
 
1478
    \warning Passing (const char *)0 as argument to qFatal might lead
 
1479
    to crashes on certain platforms due to the platforms printf implementation.
 
1480
 
 
1481
    \sa qDebug(), qCritical(), qWarning(), qInstallMsgHandler(),
 
1482
        {Debugging Techniques}
 
1483
*/
 
1484
void qFatal(const char *msg, ...)
 
1485
{
 
1486
    char buf[QT_BUFFER_LENGTH];
 
1487
    buf[QT_BUFFER_LENGTH - 1] = '\0';
 
1488
    va_list ap;
 
1489
    va_start(ap, msg); // use variable arg list
 
1490
    qvsnprintf(buf, QT_BUFFER_LENGTH - 1, msg, ap);
 
1491
    va_end(ap);
 
1492
 
 
1493
    qt_message_output(QtFatalMsg, buf);
 
1494
}
 
1495
 
 
1496
// getenv is declared as deprecated in VS2005. This function
 
1497
// makes use of the new secure getenv function.
 
1498
QByteArray qgetenv(const char *varName)
 
1499
{
 
1500
#if defined(_MSC_VER) && _MSC_VER >= 1400
 
1501
    size_t requiredSize;
 
1502
    QByteArray buffer;
 
1503
    getenv_s(&requiredSize, 0, 0, varName);
 
1504
    if (requiredSize == 0)
 
1505
        return buffer;
 
1506
    buffer.resize(requiredSize);
 
1507
    getenv_s(&requiredSize, buffer.data(), requiredSize, varName);
 
1508
    return buffer;
 
1509
#else
 
1510
    return QByteArray(::getenv(varName));
 
1511
#endif
 
1512
}
 
1513
 
 
1514
/*!
 
1515
    \macro foreach(variable, container)
 
1516
    \relates <QtGlobal>
 
1517
 
 
1518
    This macro is used to implement Qt's \c foreach loop. \a variable
 
1519
    is a variable name or variable definition; \a container is a Qt
 
1520
    container whose value type corresponds to the type of the
 
1521
    variable. See \l{The foreach Keyword} for details.
 
1522
 
 
1523
    If you're worried about namespace pollution, you can disable this
 
1524
    macro by adding the following line to your \c .pro file:
 
1525
 
 
1526
    \code
 
1527
        CONFIG += no_keywords
 
1528
    \endcode
 
1529
 
 
1530
    \sa Q_FOREACH()
 
1531
*/
 
1532
 
 
1533
/*!
 
1534
    \macro Q_FOREACH(variable, container)
 
1535
    \relates <QtGlobal>
 
1536
 
 
1537
    Same as foreach(\a variable, \a container).
 
1538
*/
 
1539
 
 
1540
/*!
 
1541
    \macro const char *QT_TR_NOOP(const char *sourceText)
 
1542
    \relates <QtGlobal>
 
1543
 
 
1544
    Marks the string literal \a sourceText for translation in the
 
1545
    current context. Expands to \a sourceText.
 
1546
 
 
1547
    Example:
 
1548
 
 
1549
    \code
 
1550
        QString FriendlyConversation::greeting(int type)
 
1551
        {
 
1552
            static const char *greeting_strings[] = {
 
1553
                QT_TR_NOOP("Hello"),
 
1554
                QT_TR_NOOP("Goodbye")
 
1555
            };
 
1556
            return tr(greeting_strings[type]);
 
1557
        }
 
1558
    \endcode
 
1559
 
 
1560
    \sa QT_TRANSLATE_NOOP(), {Internationalization with Qt}
 
1561
*/
 
1562
 
 
1563
/*!
 
1564
    \macro const char *QT_TRANSLATE_NOOP(const char *context, const char *sourceText)
 
1565
    \relates <QtGlobal>
 
1566
 
 
1567
    Marks the string literal \a sourceText for translation in the
 
1568
    given \a context. Expands to \a sourceText.
 
1569
 
 
1570
    Example:
 
1571
 
 
1572
    \code
 
1573
        static const char *greeting_strings[] = {
 
1574
            QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"),
 
1575
            QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye")
 
1576
        };
 
1577
 
 
1578
        QString FriendlyConversation::greeting(int type)
 
1579
        {
 
1580
            return tr(greeting_strings[type]);
 
1581
        }
 
1582
 
 
1583
        QString global_greeting(int type)
 
1584
        {
 
1585
            return qApp->translate("FriendlyConversation",
 
1586
                                   greeting_strings[type]);
 
1587
        }
 
1588
    \endcode
 
1589
 
 
1590
    \sa QT_TR_NOOP(), {Internationalization with Qt}
 
1591
*/
 
1592
 
 
1593
#ifdef QT3_SUPPORT
 
1594
#include <qlibraryinfo.h>
 
1595
static const char *qInstallLocation(QLibraryInfo::LibraryLocation loc)
 
1596
{
 
1597
    static QByteArray ret;
 
1598
    ret = QLibraryInfo::location(loc).toLatin1();
 
1599
    return ret.constData();
 
1600
}
 
1601
const char *qInstallPath()
 
1602
{
 
1603
    return qInstallLocation(QLibraryInfo::PrefixPath);
 
1604
}
 
1605
const char *qInstallPathDocs()
 
1606
{
 
1607
    return qInstallLocation(QLibraryInfo::DocumentationPath);
 
1608
}
 
1609
const char *qInstallPathHeaders()
 
1610
{
 
1611
    return qInstallLocation(QLibraryInfo::HeadersPath);
 
1612
}
 
1613
const char *qInstallPathLibs()
 
1614
{
 
1615
    return qInstallLocation(QLibraryInfo::LibrariesPath);
 
1616
}
 
1617
const char *qInstallPathBins()
 
1618
{
 
1619
    return qInstallLocation(QLibraryInfo::BinariesPath);
 
1620
}
 
1621
const char *qInstallPathPlugins()
 
1622
{
 
1623
    return qInstallLocation(QLibraryInfo::PluginsPath);
 
1624
}
 
1625
const char *qInstallPathData()
 
1626
{
 
1627
    return qInstallLocation(QLibraryInfo::DataPath);
 
1628
}
 
1629
const char *qInstallPathTranslations()
 
1630
{
 
1631
    return qInstallLocation(QLibraryInfo::TranslationsPath);
 
1632
}
 
1633
const char *qInstallPathSysconf()
 
1634
{
 
1635
    return qInstallLocation(QLibraryInfo::SettingsPath);
 
1636
}
 
1637
#endif