From 0bc02fd0d61d1e4aed9b39890d28975dff30e822 Mon Sep 17 00:00:00 2001 From: Casper van Donderen Date: Tue, 20 Mar 2012 19:37:07 +0100 Subject: Doc: Prepare for building modular QtCore docs. This change fixes most qdoc errors in QtCore. There are about 900 left. The main thing this change does is moving documentation from qtcore from /doc/src to /src/corelib/doc. Other issues resolved are mis-use of qdoc commands. Change-Id: I002d01edfb13575e8bf27ce91596a577a92562d1 Reviewed-by: Lars Knoll Reviewed-by: Jason McDonald Reviewed-by: Jerome Pasion --- src/corelib/codecs/codecs.qdoc | 14 +- src/corelib/codecs/qtextcodec.cpp | 6 +- src/corelib/doc/images/abstract-connections.png | Bin 0 -> 19849 bytes src/corelib/doc/images/brush-styles.png | Bin 0 -> 13980 bytes src/corelib/doc/images/cursor-arrow.png | Bin 0 -> 171 bytes src/corelib/doc/images/cursor-busy.png | Bin 0 -> 201 bytes src/corelib/doc/images/cursor-closedhand.png | Bin 0 -> 147 bytes src/corelib/doc/images/cursor-cross.png | Bin 0 -> 130 bytes src/corelib/doc/images/cursor-forbidden.png | Bin 0 -> 199 bytes src/corelib/doc/images/cursor-hand.png | Bin 0 -> 159 bytes src/corelib/doc/images/cursor-hsplit.png | Bin 0 -> 155 bytes src/corelib/doc/images/cursor-ibeam.png | Bin 0 -> 124 bytes src/corelib/doc/images/cursor-openhand.png | Bin 0 -> 160 bytes src/corelib/doc/images/cursor-sizeall.png | Bin 0 -> 174 bytes src/corelib/doc/images/cursor-sizeb.png | Bin 0 -> 161 bytes src/corelib/doc/images/cursor-sizef.png | Bin 0 -> 161 bytes src/corelib/doc/images/cursor-sizeh.png | Bin 0 -> 145 bytes src/corelib/doc/images/cursor-sizev.png | Bin 0 -> 141 bytes src/corelib/doc/images/cursor-uparrow.png | Bin 0 -> 132 bytes src/corelib/doc/images/cursor-vsplit.png | Bin 0 -> 161 bytes src/corelib/doc/images/cursor-wait.png | Bin 0 -> 172 bytes src/corelib/doc/images/cursor-whatsthis.png | Bin 0 -> 191 bytes src/corelib/doc/images/javaiterators1.png | Bin 0 -> 1062 bytes src/corelib/doc/images/javaiterators2.png | Bin 0 -> 2011 bytes src/corelib/doc/images/modelindex-no-parent.png | Bin 0 -> 7407 bytes .../doc/images/modelview-begin-append-columns.png | Bin 0 -> 12798 bytes .../doc/images/modelview-begin-append-rows.png | Bin 0 -> 8967 bytes .../doc/images/modelview-begin-insert-columns.png | Bin 0 -> 14476 bytes .../doc/images/modelview-begin-insert-rows.png | Bin 0 -> 12565 bytes .../doc/images/modelview-begin-remove-columns.png | Bin 0 -> 14518 bytes .../doc/images/modelview-begin-remove-rows.png | Bin 0 -> 10896 bytes src/corelib/doc/images/modelview-move-rows-1.png | Bin 0 -> 19709 bytes src/corelib/doc/images/modelview-move-rows-2.png | Bin 0 -> 19385 bytes src/corelib/doc/images/modelview-move-rows-3.png | Bin 0 -> 9281 bytes src/corelib/doc/images/modelview-move-rows-4.png | Bin 0 -> 9381 bytes src/corelib/doc/images/qeasingcurve-inback.png | Bin 0 -> 2808 bytes src/corelib/doc/images/qeasingcurve-inbounce.png | Bin 0 -> 3154 bytes src/corelib/doc/images/qeasingcurve-incirc.png | Bin 0 -> 2605 bytes src/corelib/doc/images/qeasingcurve-incubic.png | Bin 0 -> 2722 bytes src/corelib/doc/images/qeasingcurve-inelastic.png | Bin 0 -> 3304 bytes src/corelib/doc/images/qeasingcurve-inexpo.png | Bin 0 -> 2675 bytes src/corelib/doc/images/qeasingcurve-inoutback.png | Bin 0 -> 3241 bytes .../doc/images/qeasingcurve-inoutbounce.png | Bin 0 -> 3386 bytes src/corelib/doc/images/qeasingcurve-inoutcirc.png | Bin 0 -> 2843 bytes src/corelib/doc/images/qeasingcurve-inoutcubic.png | Bin 0 -> 2931 bytes .../doc/images/qeasingcurve-inoutelastic.png | Bin 0 -> 3461 bytes src/corelib/doc/images/qeasingcurve-inoutexpo.png | Bin 0 -> 3004 bytes src/corelib/doc/images/qeasingcurve-inoutquad.png | Bin 0 -> 2893 bytes src/corelib/doc/images/qeasingcurve-inoutquart.png | Bin 0 -> 2925 bytes src/corelib/doc/images/qeasingcurve-inoutquint.png | Bin 0 -> 2823 bytes src/corelib/doc/images/qeasingcurve-inoutsine.png | Bin 0 -> 2891 bytes src/corelib/doc/images/qeasingcurve-inquad.png | Bin 0 -> 2733 bytes src/corelib/doc/images/qeasingcurve-inquart.png | Bin 0 -> 2727 bytes src/corelib/doc/images/qeasingcurve-inquint.png | Bin 0 -> 2630 bytes src/corelib/doc/images/qeasingcurve-insine.png | Bin 0 -> 2567 bytes src/corelib/doc/images/qeasingcurve-linear.png | Bin 0 -> 2318 bytes src/corelib/doc/images/qeasingcurve-outback.png | Bin 0 -> 2852 bytes src/corelib/doc/images/qeasingcurve-outbounce.png | Bin 0 -> 3360 bytes src/corelib/doc/images/qeasingcurve-outcirc.png | Bin 0 -> 2796 bytes src/corelib/doc/images/qeasingcurve-outcubic.png | Bin 0 -> 2792 bytes src/corelib/doc/images/qeasingcurve-outelastic.png | Bin 0 -> 3423 bytes src/corelib/doc/images/qeasingcurve-outexpo.png | Bin 0 -> 2803 bytes src/corelib/doc/images/qeasingcurve-outinback.png | Bin 0 -> 3026 bytes .../doc/images/qeasingcurve-outinbounce.png | Bin 0 -> 3629 bytes src/corelib/doc/images/qeasingcurve-outincirc.png | Bin 0 -> 2822 bytes src/corelib/doc/images/qeasingcurve-outincubic.png | Bin 0 -> 2872 bytes .../doc/images/qeasingcurve-outinelastic.png | Bin 0 -> 3941 bytes src/corelib/doc/images/qeasingcurve-outinexpo.png | Bin 0 -> 2923 bytes src/corelib/doc/images/qeasingcurve-outinquad.png | Bin 0 -> 2858 bytes src/corelib/doc/images/qeasingcurve-outinquart.png | Bin 0 -> 2830 bytes src/corelib/doc/images/qeasingcurve-outinquint.png | Bin 0 -> 2724 bytes src/corelib/doc/images/qeasingcurve-outinsine.png | Bin 0 -> 2817 bytes src/corelib/doc/images/qeasingcurve-outquad.png | Bin 0 -> 2760 bytes src/corelib/doc/images/qeasingcurve-outquart.png | Bin 0 -> 2764 bytes src/corelib/doc/images/qeasingcurve-outquint.png | Bin 0 -> 2687 bytes src/corelib/doc/images/qeasingcurve-outsine.png | Bin 0 -> 2773 bytes src/corelib/doc/images/qimage-scaling.png | Bin 0 -> 34785 bytes src/corelib/doc/images/qline-coordinates.png | Bin 0 -> 9459 bytes src/corelib/doc/images/qline-point.png | Bin 0 -> 8484 bytes .../doc/images/qlinef-angle-identicaldirection.png | Bin 0 -> 6004 bytes .../doc/images/qlinef-angle-oppositedirection.png | Bin 0 -> 5834 bytes src/corelib/doc/images/qlinef-bounded.png | Bin 0 -> 4183 bytes src/corelib/doc/images/qlinef-normalvector.png | Bin 0 -> 9432 bytes src/corelib/doc/images/qlinef-unbounded.png | Bin 0 -> 3992 bytes src/corelib/doc/images/qpen-bevel.png | Bin 0 -> 11527 bytes src/corelib/doc/images/qpen-custom.png | Bin 0 -> 6254 bytes src/corelib/doc/images/qpen-dash.png | Bin 0 -> 8221 bytes src/corelib/doc/images/qpen-dashdot.png | Bin 0 -> 5961 bytes src/corelib/doc/images/qpen-dashdotdot.png | Bin 0 -> 5999 bytes src/corelib/doc/images/qpen-dot.png | Bin 0 -> 5386 bytes src/corelib/doc/images/qpen-flat.png | Bin 0 -> 1885 bytes src/corelib/doc/images/qpen-miter.png | Bin 0 -> 11734 bytes src/corelib/doc/images/qpen-roundcap.png | Bin 0 -> 1920 bytes src/corelib/doc/images/qpen-roundjoin.png | Bin 0 -> 11878 bytes src/corelib/doc/images/qpen-solid.png | Bin 0 -> 7416 bytes src/corelib/doc/images/qpen-square.png | Bin 0 -> 2651 bytes src/corelib/doc/images/qrect-coordinates.png | Bin 0 -> 22218 bytes src/corelib/doc/images/qrect-diagram-one.png | Bin 0 -> 9616 bytes src/corelib/doc/images/qrect-diagram-three.png | Bin 0 -> 9458 bytes src/corelib/doc/images/qrect-diagram-two.png | Bin 0 -> 9378 bytes src/corelib/doc/images/qrect-diagram-zero.png | Bin 0 -> 5198 bytes src/corelib/doc/images/qrect-intersect.png | Bin 0 -> 8742 bytes src/corelib/doc/images/qrect-unite.png | Bin 0 -> 4626 bytes src/corelib/doc/images/qrectf-coordinates.png | Bin 0 -> 21749 bytes src/corelib/doc/images/qrectf-diagram-one.png | Bin 0 -> 9594 bytes src/corelib/doc/images/qrectf-diagram-three.png | Bin 0 -> 9392 bytes src/corelib/doc/images/qrectf-diagram-two.png | Bin 0 -> 9387 bytes .../doc/images/qsortfilterproxymodel-sorting.png | Bin 0 -> 11005 bytes src/corelib/doc/images/qurl-authority.png | Bin 0 -> 5099 bytes src/corelib/doc/images/qurl-authority2.png | Bin 0 -> 2350 bytes src/corelib/doc/images/qurl-authority3.png | Bin 0 -> 3552 bytes src/corelib/doc/images/qurl-fragment.png | Bin 0 -> 2333 bytes src/corelib/doc/images/qurl-ftppath.png | Bin 0 -> 1974 bytes src/corelib/doc/images/qurl-mailtopath.png | Bin 0 -> 1679 bytes src/corelib/doc/images/qurl-querystring.png | Bin 0 -> 2955 bytes src/corelib/doc/images/stliterators1.png | Bin 0 -> 1671 bytes src/corelib/doc/images/thread_clock.png | Bin 0 -> 5964 bytes src/corelib/doc/images/threadsandobjects.png | Bin 0 -> 66096 bytes src/corelib/doc/images/threadvisual-example.png | Bin 0 -> 16823 bytes src/corelib/doc/qtcore.qdocconf | 90 ++ src/corelib/doc/snippets/buffer/buffer.cpp | 124 +++ .../doc/snippets/code/doc_src_containers.cpp | 275 ++++++ src/corelib/doc/snippets/code/doc_src_groups.cpp | 66 ++ .../doc/snippets/code/doc_src_objecttrees.cpp | 60 ++ .../doc/snippets/code/doc_src_properties.cpp | 132 +++ .../doc/snippets/code/doc_src_qalgorithms.cpp | 354 ++++++++ src/corelib/doc/snippets/code/doc_src_qcache.cpp | 57 ++ .../doc/snippets/code/doc_src_qiterator.cpp | 420 +++++++++ .../doc/snippets/code/doc_src_qnamespace.cpp | 59 ++ .../doc/snippets/code/doc_src_qnamespace.qdoc | 43 + src/corelib/doc/snippets/code/doc_src_qpair.cpp | 55 ++ src/corelib/doc/snippets/code/doc_src_qplugin.cpp | 64 ++ src/corelib/doc/snippets/code/doc_src_qplugin.pro | 44 + src/corelib/doc/snippets/code/doc_src_qset.cpp | 166 ++++ src/corelib/doc/snippets/code/doc_src_qtcore.cpp | 43 + .../doc/snippets/code/doc_src_qvarlengtharray.cpp | 78 ++ .../doc/snippets/code/qlogging/qlogging.cpp | 54 ++ .../code/src_corelib_codecs_qtextcodec.cpp | 75 ++ .../code/src_corelib_concurrent_qthreadpool.cpp | 53 ++ .../snippets/code/src_corelib_global_qglobal.cpp | 585 ++++++++++++ .../code/src_corelib_io_qabstractfileengine.cpp | 120 +++ .../snippets/code/src_corelib_io_qdatastream.cpp | 121 +++ .../doc/snippets/code/src_corelib_io_qdir.cpp | 175 ++++ .../snippets/code/src_corelib_io_qdiriterator.cpp | 52 ++ .../doc/snippets/code/src_corelib_io_qfile.cpp | 75 ++ .../doc/snippets/code/src_corelib_io_qfileinfo.cpp | 146 +++ .../doc/snippets/code/src_corelib_io_qiodevice.cpp | 99 ++ .../doc/snippets/code/src_corelib_io_qprocess.cpp | 134 +++ .../doc/snippets/code/src_corelib_io_qsettings.cpp | 316 +++++++ .../snippets/code/src_corelib_io_qtemporarydir.cpp | 53 ++ .../code/src_corelib_io_qtemporaryfile.cpp | 53 ++ .../snippets/code/src_corelib_io_qtextstream.cpp | 129 +++ .../doc/snippets/code/src_corelib_io_qurl.cpp | 87 ++ ...src_corelib_kernel_qabstracteventdispatcher.cpp | 43 + .../code/src_corelib_kernel_qabstractitemmodel.cpp | 99 ++ .../code/src_corelib_kernel_qcoreapplication.cpp | 126 +++ .../code/src_corelib_kernel_qmetaobject.cpp | 136 +++ .../snippets/code/src_corelib_kernel_qmetatype.cpp | 114 +++ .../snippets/code/src_corelib_kernel_qmimedata.cpp | 108 +++ .../snippets/code/src_corelib_kernel_qobject.cpp | 493 ++++++++++ .../code/src_corelib_kernel_qsystemsemaphore.cpp | 61 ++ .../snippets/code/src_corelib_kernel_qtimer.cpp | 52 ++ .../snippets/code/src_corelib_kernel_qvariant.cpp | 136 +++ .../code/src_corelib_mimetype_qmimedatabase.cpp | 47 + .../snippets/code/src_corelib_plugin_qlibrary.cpp | 84 ++ .../doc/snippets/code/src_corelib_plugin_quuid.cpp | 44 + .../src_corelib_statemachine_qstatemachine.cpp | 55 ++ .../snippets/code/src_corelib_thread_qatomic.cpp | 98 ++ .../snippets/code/src_corelib_thread_qmutex.cpp | 193 ++++ .../code/src_corelib_thread_qmutexpool.cpp | 61 ++ .../code/src_corelib_thread_qreadwritelock.cpp | 109 +++ .../code/src_corelib_thread_qsemaphore.cpp | 73 ++ .../snippets/code/src_corelib_thread_qthread.cpp | 56 ++ .../src_corelib_thread_qwaitcondition_unix.cpp | 89 ++ .../snippets/code/src_corelib_tools_qbitarray.cpp | 176 ++++ .../snippets/code/src_corelib_tools_qbytearray.cpp | 421 +++++++++ .../snippets/code/src_corelib_tools_qdatetime.cpp | 146 +++ .../code/src_corelib_tools_qeasingcurve.cpp | 44 + .../doc/snippets/code/src_corelib_tools_qhash.cpp | 299 ++++++ .../code/src_corelib_tools_qlinkedlist.cpp | 204 +++++ .../snippets/code/src_corelib_tools_qlistdata.cpp | 267 ++++++ .../snippets/code/src_corelib_tools_qlocale.cpp | 95 ++ .../doc/snippets/code/src_corelib_tools_qmap.cpp | 313 +++++++ .../doc/snippets/code/src_corelib_tools_qpoint.cpp | 149 +++ .../doc/snippets/code/src_corelib_tools_qqueue.cpp | 48 + .../doc/snippets/code/src_corelib_tools_qrect.cpp | 50 ++ .../snippets/code/src_corelib_tools_qregexp.cpp | 224 +++++ .../code/src_corelib_tools_qregularexpression.cpp | 289 ++++++ .../code/src_corelib_tools_qscopedpointer.cpp | 138 +++ .../doc/snippets/code/src_corelib_tools_qsize.cpp | 136 +++ .../snippets/code/src_corelib_tools_qstring.cpp | 94 ++ .../snippets/code/src_corelib_tools_qtimeline.cpp | 55 ++ .../snippets/code/src_corelib_tools_qvector.cpp | 183 ++++ .../snippets/code/src_corelib_xml_qxmlstream.cpp | 67 ++ .../snippets/code/src_gui_dialogs_qmessagebox.cpp | 148 +++ .../code/src_gui_itemviews_qidentityproxymodel.cpp | 64 ++ .../code/src_gui_itemviews_qitemselectionmodel.cpp | 50 ++ src/corelib/doc/snippets/file/file.cpp | 123 +++ src/corelib/doc/snippets/fileinfo/main.cpp | 92 ++ src/corelib/doc/snippets/ntfsp.cpp | 50 ++ src/corelib/doc/snippets/pointer/pointer.cpp | 60 ++ src/corelib/doc/snippets/process/process.cpp | 76 ++ src/corelib/doc/snippets/qdebug/qdebugsnippet.cpp | 73 ++ src/corelib/doc/snippets/qdir-listfiles/main.cpp | 62 ++ src/corelib/doc/snippets/qdir-namefilters/main.cpp | 65 ++ src/corelib/doc/snippets/qelapsedtimer/main.cpp | 111 +++ .../doc/snippets/qmetaobject-invokable/main.cpp | 52 ++ .../qmetaobject-invokable.pro | 3 + .../doc/snippets/qmetaobject-invokable/window.cpp | 57 ++ .../doc/snippets/qmetaobject-invokable/window.h | 58 ++ .../doc/snippets/qprocess-environment/main.cpp | 73 ++ .../snippets/qprocess/qprocess-simpleexecution.cpp | 66 ++ .../doc/snippets/qsignalmapper/buttonwidget.cpp | 66 ++ .../doc/snippets/qsignalmapper/buttonwidget.h | 67 ++ .../qsortfilterproxymodel-details/main.cpp | 99 ++ src/corelib/doc/snippets/qstack/main.cpp | 55 ++ src/corelib/doc/snippets/qstring/main.cpp | 997 +++++++++++++++++++++ src/corelib/doc/snippets/qstring/stringbuilder.cpp | 62 ++ src/corelib/doc/snippets/qstringlist/main.cpp | 170 ++++ src/corelib/doc/snippets/qstringlistmodel/main.cpp | 66 ++ src/corelib/doc/snippets/qtcast/qtcast.cpp | 79 ++ src/corelib/doc/snippets/qxmlstreamwriter/main.cpp | 76 ++ src/corelib/doc/snippets/settings/settings.cpp | 184 ++++ src/corelib/doc/snippets/sharedemployee/employee.h | 94 ++ src/corelib/doc/snippets/sharedemployee/main.cpp | 50 ++ .../doc/snippets/signalmapper/filereader.cpp | 107 +++ .../doc/snippets/signalsandslots/lcdnumber.h | 88 ++ .../snippets/signalsandslots/signalsandslots.cpp | 84 ++ .../doc/snippets/signalsandslots/signalsandslots.h | 89 ++ src/corelib/doc/snippets/streaming/main.cpp | 108 +++ src/corelib/doc/snippets/streaming/streaming.pro | 2 + src/corelib/doc/snippets/threads/threads.cpp | 117 +++ src/corelib/doc/snippets/threads/threads.h | 51 ++ src/corelib/doc/snippets/timers/timers.cpp | 78 ++ src/corelib/doc/src/containers.qdoc | 803 +++++++++++++++++ src/corelib/doc/src/datastreamformat.qdoc | 373 ++++++++ src/corelib/doc/src/implicit-sharing.qdoc | 138 +++ src/corelib/doc/src/json.qdoc | 118 +++ src/corelib/doc/src/objectmodel/metaobjects.qdoc | 137 +++ src/corelib/doc/src/objectmodel/object.qdoc | 124 +++ src/corelib/doc/src/objectmodel/objecttrees.qdoc | 102 +++ src/corelib/doc/src/objectmodel/properties.qdoc | 273 ++++++ .../doc/src/objectmodel/signalsandslots.qdoc | 468 ++++++++++ src/corelib/doc/src/qtcore.qdoc | 42 + src/corelib/doc/src/threads-basics.qdoc | 572 ++++++++++++ src/corelib/doc/src/threads.qdoc | 705 +++++++++++++++ src/corelib/global/qglobal.cpp | 203 ++--- src/corelib/global/qlogging.cpp | 78 +- src/corelib/global/qnamespace.qdoc | 16 +- src/corelib/io/qabstractfileengine.cpp | 20 +- src/corelib/io/qbuffer.cpp | 10 +- src/corelib/io/qdatastream.cpp | 26 +- src/corelib/io/qdebug.cpp | 6 +- src/corelib/io/qdir.cpp | 62 +- src/corelib/io/qdiriterator.cpp | 2 +- src/corelib/io/qfile.cpp | 22 +- src/corelib/io/qfileinfo.cpp | 34 +- src/corelib/io/qiodevice.cpp | 56 +- src/corelib/io/qprocess.cpp | 30 +- src/corelib/io/qresource.cpp | 2 +- src/corelib/io/qsettings.cpp | 104 +-- src/corelib/io/qstandardpaths.cpp | 2 +- src/corelib/io/qtemporarydir.cpp | 2 +- src/corelib/io/qtemporaryfile.cpp | 2 +- src/corelib/io/qtextstream.cpp | 38 +- src/corelib/io/qurl.cpp | 28 +- src/corelib/itemmodels/qabstractitemmodel.cpp | 48 +- src/corelib/itemmodels/qidentityproxymodel.cpp | 2 +- src/corelib/itemmodels/qitemselectionmodel.cpp | 12 +- src/corelib/itemmodels/qsortfilterproxymodel.cpp | 16 +- src/corelib/itemmodels/qstringlistmodel.cpp | 2 +- src/corelib/json/qjsonarray.cpp | 13 +- src/corelib/json/qjsondocument.cpp | 16 +- src/corelib/json/qjsonobject.cpp | 44 +- src/corelib/kernel/qabstracteventdispatcher.cpp | 4 +- src/corelib/kernel/qbasictimer.cpp | 8 +- src/corelib/kernel/qcoreapplication.cpp | 28 +- src/corelib/kernel/qeventloop.cpp | 2 +- src/corelib/kernel/qmetaobject.cpp | 22 +- src/corelib/kernel/qmetaobjectbuilder.cpp | 4 +- src/corelib/kernel/qmetatype.cpp | 30 +- src/corelib/kernel/qmetatype.h | 25 + src/corelib/kernel/qmimedata.cpp | 16 +- src/corelib/kernel/qobject.cpp | 120 +-- src/corelib/kernel/qobjectcleanuphandler.cpp | 2 +- src/corelib/kernel/qpointer.cpp | 6 +- src/corelib/kernel/qsharedmemory.cpp | 14 +- src/corelib/kernel/qsignalmapper.cpp | 10 +- src/corelib/kernel/qsystemsemaphore.cpp | 6 +- src/corelib/kernel/qtimer.cpp | 16 +- src/corelib/kernel/qtranslator.cpp | 2 +- src/corelib/kernel/qvariant.cpp | 20 +- src/corelib/mimetypes/qmimedatabase.cpp | 2 +- src/corelib/plugin/qlibrary.cpp | 10 +- src/corelib/plugin/qplugin.qdoc | 10 +- src/corelib/plugin/quuid.cpp | 6 +- src/corelib/statemachine/qstatemachine.cpp | 4 +- src/corelib/thread/qatomic.cpp | 77 +- src/corelib/thread/qatomic.h | 4 +- src/corelib/thread/qmutex.cpp | 42 +- src/corelib/thread/qmutex.h | 1 - src/corelib/thread/qmutexpool.cpp | 4 +- src/corelib/thread/qreadwritelock.cpp | 24 +- src/corelib/thread/qsemaphore.cpp | 8 +- src/corelib/thread/qthread.cpp | 12 +- src/corelib/thread/qthread_win.cpp | 2 +- src/corelib/thread/qthreadpool.cpp | 2 +- src/corelib/thread/qthreadstorage.cpp | 6 +- src/corelib/thread/qwaitcondition.qdoc | 8 +- src/corelib/tools/qalgorithms.qdoc | 52 +- src/corelib/tools/qbitarray.cpp | 34 +- src/corelib/tools/qbytearray.cpp | 98 +- src/corelib/tools/qcache.qdoc | 6 +- src/corelib/tools/qdatetime.cpp | 56 +- src/corelib/tools/qeasingcurve.cpp | 180 ++-- src/corelib/tools/qelapsedtimer.cpp | 6 +- src/corelib/tools/qelapsedtimer_generic.cpp | 4 +- src/corelib/tools/qhash.cpp | 56 +- src/corelib/tools/qiterator.qdoc | 104 +-- src/corelib/tools/qlinkedlist.cpp | 40 +- src/corelib/tools/qlist.cpp | 58 +- src/corelib/tools/qlocale.cpp | 8 +- src/corelib/tools/qlocale.qdoc | 8 +- src/corelib/tools/qmap.cpp | 60 +- src/corelib/tools/qpair.qdoc | 12 +- src/corelib/tools/qpoint.cpp | 42 +- src/corelib/tools/qqueue.cpp | 2 +- src/corelib/tools/qrect.cpp | 6 +- src/corelib/tools/qregexp.cpp | 50 +- src/corelib/tools/qregularexpression.cpp | 64 +- src/corelib/tools/qscopedpointer.cpp | 12 +- src/corelib/tools/qset.qdoc | 30 +- src/corelib/tools/qshareddata.cpp | 18 +- src/corelib/tools/qsize.cpp | 24 +- src/corelib/tools/qstack.cpp | 2 +- src/corelib/tools/qstring.cpp | 262 +++--- src/corelib/tools/qstringbuilder.cpp | 2 +- src/corelib/tools/qstringlist.cpp | 38 +- src/corelib/tools/qtimeline.cpp | 2 +- src/corelib/tools/qvarlengtharray.qdoc | 8 +- src/corelib/tools/qvector.cpp | 36 +- src/corelib/xml/qxmlstream.cpp | 12 +- src/corelib/xml/qxmlutils.cpp | 12 +- 343 files changed, 19432 insertions(+), 1504 deletions(-) create mode 100644 src/corelib/doc/images/abstract-connections.png create mode 100644 src/corelib/doc/images/brush-styles.png create mode 100644 src/corelib/doc/images/cursor-arrow.png create mode 100644 src/corelib/doc/images/cursor-busy.png create mode 100644 src/corelib/doc/images/cursor-closedhand.png create mode 100644 src/corelib/doc/images/cursor-cross.png create mode 100644 src/corelib/doc/images/cursor-forbidden.png create mode 100644 src/corelib/doc/images/cursor-hand.png create mode 100644 src/corelib/doc/images/cursor-hsplit.png create mode 100644 src/corelib/doc/images/cursor-ibeam.png create mode 100644 src/corelib/doc/images/cursor-openhand.png create mode 100644 src/corelib/doc/images/cursor-sizeall.png create mode 100644 src/corelib/doc/images/cursor-sizeb.png create mode 100644 src/corelib/doc/images/cursor-sizef.png create mode 100644 src/corelib/doc/images/cursor-sizeh.png create mode 100644 src/corelib/doc/images/cursor-sizev.png create mode 100644 src/corelib/doc/images/cursor-uparrow.png create mode 100644 src/corelib/doc/images/cursor-vsplit.png create mode 100644 src/corelib/doc/images/cursor-wait.png create mode 100644 src/corelib/doc/images/cursor-whatsthis.png create mode 100644 src/corelib/doc/images/javaiterators1.png create mode 100644 src/corelib/doc/images/javaiterators2.png create mode 100644 src/corelib/doc/images/modelindex-no-parent.png create mode 100644 src/corelib/doc/images/modelview-begin-append-columns.png create mode 100644 src/corelib/doc/images/modelview-begin-append-rows.png create mode 100644 src/corelib/doc/images/modelview-begin-insert-columns.png create mode 100644 src/corelib/doc/images/modelview-begin-insert-rows.png create mode 100644 src/corelib/doc/images/modelview-begin-remove-columns.png create mode 100644 src/corelib/doc/images/modelview-begin-remove-rows.png create mode 100644 src/corelib/doc/images/modelview-move-rows-1.png create mode 100644 src/corelib/doc/images/modelview-move-rows-2.png create mode 100644 src/corelib/doc/images/modelview-move-rows-3.png create mode 100644 src/corelib/doc/images/modelview-move-rows-4.png create mode 100644 src/corelib/doc/images/qeasingcurve-inback.png create mode 100644 src/corelib/doc/images/qeasingcurve-inbounce.png create mode 100644 src/corelib/doc/images/qeasingcurve-incirc.png create mode 100644 src/corelib/doc/images/qeasingcurve-incubic.png create mode 100644 src/corelib/doc/images/qeasingcurve-inelastic.png create mode 100644 src/corelib/doc/images/qeasingcurve-inexpo.png create mode 100644 src/corelib/doc/images/qeasingcurve-inoutback.png create mode 100644 src/corelib/doc/images/qeasingcurve-inoutbounce.png create mode 100644 src/corelib/doc/images/qeasingcurve-inoutcirc.png create mode 100644 src/corelib/doc/images/qeasingcurve-inoutcubic.png create mode 100644 src/corelib/doc/images/qeasingcurve-inoutelastic.png create mode 100644 src/corelib/doc/images/qeasingcurve-inoutexpo.png create mode 100644 src/corelib/doc/images/qeasingcurve-inoutquad.png create mode 100644 src/corelib/doc/images/qeasingcurve-inoutquart.png create mode 100644 src/corelib/doc/images/qeasingcurve-inoutquint.png create mode 100644 src/corelib/doc/images/qeasingcurve-inoutsine.png create mode 100644 src/corelib/doc/images/qeasingcurve-inquad.png create mode 100644 src/corelib/doc/images/qeasingcurve-inquart.png create mode 100644 src/corelib/doc/images/qeasingcurve-inquint.png create mode 100644 src/corelib/doc/images/qeasingcurve-insine.png create mode 100644 src/corelib/doc/images/qeasingcurve-linear.png create mode 100644 src/corelib/doc/images/qeasingcurve-outback.png create mode 100644 src/corelib/doc/images/qeasingcurve-outbounce.png create mode 100644 src/corelib/doc/images/qeasingcurve-outcirc.png create mode 100644 src/corelib/doc/images/qeasingcurve-outcubic.png create mode 100644 src/corelib/doc/images/qeasingcurve-outelastic.png create mode 100644 src/corelib/doc/images/qeasingcurve-outexpo.png create mode 100644 src/corelib/doc/images/qeasingcurve-outinback.png create mode 100644 src/corelib/doc/images/qeasingcurve-outinbounce.png create mode 100644 src/corelib/doc/images/qeasingcurve-outincirc.png create mode 100644 src/corelib/doc/images/qeasingcurve-outincubic.png create mode 100644 src/corelib/doc/images/qeasingcurve-outinelastic.png create mode 100644 src/corelib/doc/images/qeasingcurve-outinexpo.png create mode 100644 src/corelib/doc/images/qeasingcurve-outinquad.png create mode 100644 src/corelib/doc/images/qeasingcurve-outinquart.png create mode 100644 src/corelib/doc/images/qeasingcurve-outinquint.png create mode 100644 src/corelib/doc/images/qeasingcurve-outinsine.png create mode 100644 src/corelib/doc/images/qeasingcurve-outquad.png create mode 100644 src/corelib/doc/images/qeasingcurve-outquart.png create mode 100644 src/corelib/doc/images/qeasingcurve-outquint.png create mode 100644 src/corelib/doc/images/qeasingcurve-outsine.png create mode 100644 src/corelib/doc/images/qimage-scaling.png create mode 100644 src/corelib/doc/images/qline-coordinates.png create mode 100644 src/corelib/doc/images/qline-point.png create mode 100644 src/corelib/doc/images/qlinef-angle-identicaldirection.png create mode 100644 src/corelib/doc/images/qlinef-angle-oppositedirection.png create mode 100644 src/corelib/doc/images/qlinef-bounded.png create mode 100644 src/corelib/doc/images/qlinef-normalvector.png create mode 100644 src/corelib/doc/images/qlinef-unbounded.png create mode 100644 src/corelib/doc/images/qpen-bevel.png create mode 100644 src/corelib/doc/images/qpen-custom.png create mode 100644 src/corelib/doc/images/qpen-dash.png create mode 100644 src/corelib/doc/images/qpen-dashdot.png create mode 100644 src/corelib/doc/images/qpen-dashdotdot.png create mode 100644 src/corelib/doc/images/qpen-dot.png create mode 100644 src/corelib/doc/images/qpen-flat.png create mode 100644 src/corelib/doc/images/qpen-miter.png create mode 100644 src/corelib/doc/images/qpen-roundcap.png create mode 100644 src/corelib/doc/images/qpen-roundjoin.png create mode 100644 src/corelib/doc/images/qpen-solid.png create mode 100644 src/corelib/doc/images/qpen-square.png create mode 100644 src/corelib/doc/images/qrect-coordinates.png create mode 100644 src/corelib/doc/images/qrect-diagram-one.png create mode 100644 src/corelib/doc/images/qrect-diagram-three.png create mode 100644 src/corelib/doc/images/qrect-diagram-two.png create mode 100644 src/corelib/doc/images/qrect-diagram-zero.png create mode 100644 src/corelib/doc/images/qrect-intersect.png create mode 100644 src/corelib/doc/images/qrect-unite.png create mode 100644 src/corelib/doc/images/qrectf-coordinates.png create mode 100644 src/corelib/doc/images/qrectf-diagram-one.png create mode 100644 src/corelib/doc/images/qrectf-diagram-three.png create mode 100644 src/corelib/doc/images/qrectf-diagram-two.png create mode 100644 src/corelib/doc/images/qsortfilterproxymodel-sorting.png create mode 100644 src/corelib/doc/images/qurl-authority.png create mode 100644 src/corelib/doc/images/qurl-authority2.png create mode 100644 src/corelib/doc/images/qurl-authority3.png create mode 100644 src/corelib/doc/images/qurl-fragment.png create mode 100644 src/corelib/doc/images/qurl-ftppath.png create mode 100644 src/corelib/doc/images/qurl-mailtopath.png create mode 100644 src/corelib/doc/images/qurl-querystring.png create mode 100644 src/corelib/doc/images/stliterators1.png create mode 100644 src/corelib/doc/images/thread_clock.png create mode 100644 src/corelib/doc/images/threadsandobjects.png create mode 100644 src/corelib/doc/images/threadvisual-example.png create mode 100644 src/corelib/doc/qtcore.qdocconf create mode 100644 src/corelib/doc/snippets/buffer/buffer.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_containers.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_groups.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_objecttrees.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_properties.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_qcache.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_qiterator.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_qnamespace.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_qnamespace.qdoc create mode 100644 src/corelib/doc/snippets/code/doc_src_qpair.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_qplugin.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_qplugin.pro create mode 100644 src/corelib/doc/snippets/code/doc_src_qset.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_qtcore.cpp create mode 100644 src/corelib/doc/snippets/code/doc_src_qvarlengtharray.cpp create mode 100644 src/corelib/doc/snippets/code/qlogging/qlogging.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_codecs_qtextcodec.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qdatastream.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qdir.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qdiriterator.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qiodevice.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qprocess.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qsettings.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qtemporarydir.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qtemporaryfile.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_kernel_qmetaobject.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_mimetype_qmimedatabase.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_plugin_qlibrary.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_plugin_quuid.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_thread_qatomic.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_thread_qmutex.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_thread_qmutexpool.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_thread_qreadwritelock.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_thread_qsemaphore.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qbitarray.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qeasingcurve.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qlinkedlist.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qlistdata.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qqueue.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qrect.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qregexp.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qregularexpression.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qscopedpointer.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qsize.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp create mode 100644 src/corelib/doc/snippets/code/src_corelib_xml_qxmlstream.cpp create mode 100644 src/corelib/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp create mode 100644 src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp create mode 100644 src/corelib/doc/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp create mode 100644 src/corelib/doc/snippets/file/file.cpp create mode 100644 src/corelib/doc/snippets/fileinfo/main.cpp create mode 100644 src/corelib/doc/snippets/ntfsp.cpp create mode 100644 src/corelib/doc/snippets/pointer/pointer.cpp create mode 100644 src/corelib/doc/snippets/process/process.cpp create mode 100644 src/corelib/doc/snippets/qdebug/qdebugsnippet.cpp create mode 100644 src/corelib/doc/snippets/qdir-listfiles/main.cpp create mode 100644 src/corelib/doc/snippets/qdir-namefilters/main.cpp create mode 100644 src/corelib/doc/snippets/qelapsedtimer/main.cpp create mode 100644 src/corelib/doc/snippets/qmetaobject-invokable/main.cpp create mode 100644 src/corelib/doc/snippets/qmetaobject-invokable/qmetaobject-invokable.pro create mode 100644 src/corelib/doc/snippets/qmetaobject-invokable/window.cpp create mode 100644 src/corelib/doc/snippets/qmetaobject-invokable/window.h create mode 100644 src/corelib/doc/snippets/qprocess-environment/main.cpp create mode 100644 src/corelib/doc/snippets/qprocess/qprocess-simpleexecution.cpp create mode 100644 src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp create mode 100644 src/corelib/doc/snippets/qsignalmapper/buttonwidget.h create mode 100644 src/corelib/doc/snippets/qsortfilterproxymodel-details/main.cpp create mode 100644 src/corelib/doc/snippets/qstack/main.cpp create mode 100644 src/corelib/doc/snippets/qstring/main.cpp create mode 100644 src/corelib/doc/snippets/qstring/stringbuilder.cpp create mode 100644 src/corelib/doc/snippets/qstringlist/main.cpp create mode 100644 src/corelib/doc/snippets/qstringlistmodel/main.cpp create mode 100644 src/corelib/doc/snippets/qtcast/qtcast.cpp create mode 100644 src/corelib/doc/snippets/qxmlstreamwriter/main.cpp create mode 100644 src/corelib/doc/snippets/settings/settings.cpp create mode 100644 src/corelib/doc/snippets/sharedemployee/employee.h create mode 100644 src/corelib/doc/snippets/sharedemployee/main.cpp create mode 100644 src/corelib/doc/snippets/signalmapper/filereader.cpp create mode 100644 src/corelib/doc/snippets/signalsandslots/lcdnumber.h create mode 100644 src/corelib/doc/snippets/signalsandslots/signalsandslots.cpp create mode 100644 src/corelib/doc/snippets/signalsandslots/signalsandslots.h create mode 100644 src/corelib/doc/snippets/streaming/main.cpp create mode 100644 src/corelib/doc/snippets/streaming/streaming.pro create mode 100644 src/corelib/doc/snippets/threads/threads.cpp create mode 100644 src/corelib/doc/snippets/threads/threads.h create mode 100644 src/corelib/doc/snippets/timers/timers.cpp create mode 100644 src/corelib/doc/src/containers.qdoc create mode 100644 src/corelib/doc/src/datastreamformat.qdoc create mode 100644 src/corelib/doc/src/implicit-sharing.qdoc create mode 100644 src/corelib/doc/src/json.qdoc create mode 100644 src/corelib/doc/src/objectmodel/metaobjects.qdoc create mode 100644 src/corelib/doc/src/objectmodel/object.qdoc create mode 100644 src/corelib/doc/src/objectmodel/objecttrees.qdoc create mode 100644 src/corelib/doc/src/objectmodel/properties.qdoc create mode 100644 src/corelib/doc/src/objectmodel/signalsandslots.qdoc create mode 100644 src/corelib/doc/src/qtcore.qdoc create mode 100644 src/corelib/doc/src/threads-basics.qdoc create mode 100644 src/corelib/doc/src/threads.qdoc (limited to 'src') diff --git a/src/corelib/codecs/codecs.qdoc b/src/corelib/codecs/codecs.qdoc index 669072f789..05714b2253 100644 --- a/src/corelib/codecs/codecs.qdoc +++ b/src/corelib/codecs/codecs.qdoc @@ -68,8 +68,8 @@ for Qt. \legalese - Copyright (C) 2000 Ming-Che Chuang \BR - Copyright (C) 2002 James Su, Turbolinux Inc. \BR + Copyright (C) 2000 Ming-Che Chuang + Copyright (C) 2002 James Su, Turbolinux Inc. Copyright (C) 2002 Anthony Fok, ThizLinux Laboratory Ltd. Redistribution and use in source and binary forms, with or without @@ -137,9 +137,9 @@ for the various Big5 CharMapML tables. \legalese - Copyright (C) 2000 Ming-Che Chuang \BR - Copyright (C) 2001, 2002 James Su, Turbolinux Inc. \BR - Copyright (C) 2002 WU Yi, HancomLinux Inc. \BR + Copyright (C) 2000 Ming-Che Chuang + Copyright (C) 2001, 2002 James Su, Turbolinux Inc. + Copyright (C) 2002 WU Yi, HancomLinux Inc. Copyright (C) 2001, 2002 Anthony Fok, ThizLinux Laboratory Ltd. Redistribution and use in source and binary forms, with or without @@ -307,8 +307,8 @@ The copyright notice for their code follows: \legalese - Copyright (C) 2000 TurboLinux, Inc. Written by Justin Yu and Sean Chen. \BR - Copyright (C) 2001, 2002 Turbolinux, Inc. Written by James Su. \BR + Copyright (C) 2000 TurboLinux, Inc. Written by Justin Yu and Sean Chen. + Copyright (C) 2001, 2002 Turbolinux, Inc. Written by James Su. Copyright (C) 2001, 2002 ThizLinux Laboratory Ltd. Written by Anthony Fok. Redistribution and use in source and binary forms, with or without diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 784a75bcad..b7939f1f3e 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -818,13 +818,13 @@ QTextCodec::ConverterState::~ConverterState() KOI8-R encoding, and want to convert it to Unicode. The simple way to do it is like this: - \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp 0 + \snippet code/src_corelib_codecs_qtextcodec.cpp 0 After this, \c string holds the text converted to Unicode. Converting a string from Unicode to the local encoding is just as easy: - \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp 1 + \snippet code/src_corelib_codecs_qtextcodec.cpp 1 To read or write files in various encodings, use QTextStream and its \l{QTextStream::setCodec()}{setCodec()} function. See the @@ -841,7 +841,7 @@ QTextCodec::ConverterState::~ConverterState() object for the codec and use this QTextDecoder for the whole decoding process, as shown below: - \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp 2 + \snippet code/src_corelib_codecs_qtextcodec.cpp 2 The QTextDecoder object maintains state between chunks and therefore works correctly even if a multi-byte character is split between diff --git a/src/corelib/doc/images/abstract-connections.png b/src/corelib/doc/images/abstract-connections.png new file mode 100644 index 0000000000..18d2f4e3b7 Binary files /dev/null and b/src/corelib/doc/images/abstract-connections.png differ diff --git a/src/corelib/doc/images/brush-styles.png b/src/corelib/doc/images/brush-styles.png new file mode 100644 index 0000000000..eecb006af1 Binary files /dev/null and b/src/corelib/doc/images/brush-styles.png differ diff --git a/src/corelib/doc/images/cursor-arrow.png b/src/corelib/doc/images/cursor-arrow.png new file mode 100644 index 0000000000..a69ef4eb61 Binary files /dev/null and b/src/corelib/doc/images/cursor-arrow.png differ diff --git a/src/corelib/doc/images/cursor-busy.png b/src/corelib/doc/images/cursor-busy.png new file mode 100644 index 0000000000..53717e4992 Binary files /dev/null and b/src/corelib/doc/images/cursor-busy.png differ diff --git a/src/corelib/doc/images/cursor-closedhand.png b/src/corelib/doc/images/cursor-closedhand.png new file mode 100644 index 0000000000..b78dd1dac5 Binary files /dev/null and b/src/corelib/doc/images/cursor-closedhand.png differ diff --git a/src/corelib/doc/images/cursor-cross.png b/src/corelib/doc/images/cursor-cross.png new file mode 100644 index 0000000000..fe38e74480 Binary files /dev/null and b/src/corelib/doc/images/cursor-cross.png differ diff --git a/src/corelib/doc/images/cursor-forbidden.png b/src/corelib/doc/images/cursor-forbidden.png new file mode 100644 index 0000000000..2b08c4e2a3 Binary files /dev/null and b/src/corelib/doc/images/cursor-forbidden.png differ diff --git a/src/corelib/doc/images/cursor-hand.png b/src/corelib/doc/images/cursor-hand.png new file mode 100644 index 0000000000..d2004aefa7 Binary files /dev/null and b/src/corelib/doc/images/cursor-hand.png differ diff --git a/src/corelib/doc/images/cursor-hsplit.png b/src/corelib/doc/images/cursor-hsplit.png new file mode 100644 index 0000000000..a5667e3ffb Binary files /dev/null and b/src/corelib/doc/images/cursor-hsplit.png differ diff --git a/src/corelib/doc/images/cursor-ibeam.png b/src/corelib/doc/images/cursor-ibeam.png new file mode 100644 index 0000000000..097fc5fa72 Binary files /dev/null and b/src/corelib/doc/images/cursor-ibeam.png differ diff --git a/src/corelib/doc/images/cursor-openhand.png b/src/corelib/doc/images/cursor-openhand.png new file mode 100644 index 0000000000..9181c859ed Binary files /dev/null and b/src/corelib/doc/images/cursor-openhand.png differ diff --git a/src/corelib/doc/images/cursor-sizeall.png b/src/corelib/doc/images/cursor-sizeall.png new file mode 100644 index 0000000000..69f13eb347 Binary files /dev/null and b/src/corelib/doc/images/cursor-sizeall.png differ diff --git a/src/corelib/doc/images/cursor-sizeb.png b/src/corelib/doc/images/cursor-sizeb.png new file mode 100644 index 0000000000..f37d7b91e8 Binary files /dev/null and b/src/corelib/doc/images/cursor-sizeb.png differ diff --git a/src/corelib/doc/images/cursor-sizef.png b/src/corelib/doc/images/cursor-sizef.png new file mode 100644 index 0000000000..3b127a05d3 Binary files /dev/null and b/src/corelib/doc/images/cursor-sizef.png differ diff --git a/src/corelib/doc/images/cursor-sizeh.png b/src/corelib/doc/images/cursor-sizeh.png new file mode 100644 index 0000000000..a9f40cbc3d Binary files /dev/null and b/src/corelib/doc/images/cursor-sizeh.png differ diff --git a/src/corelib/doc/images/cursor-sizev.png b/src/corelib/doc/images/cursor-sizev.png new file mode 100644 index 0000000000..1edbab27a5 Binary files /dev/null and b/src/corelib/doc/images/cursor-sizev.png differ diff --git a/src/corelib/doc/images/cursor-uparrow.png b/src/corelib/doc/images/cursor-uparrow.png new file mode 100644 index 0000000000..d3e70ef4c2 Binary files /dev/null and b/src/corelib/doc/images/cursor-uparrow.png differ diff --git a/src/corelib/doc/images/cursor-vsplit.png b/src/corelib/doc/images/cursor-vsplit.png new file mode 100644 index 0000000000..1beda2570e Binary files /dev/null and b/src/corelib/doc/images/cursor-vsplit.png differ diff --git a/src/corelib/doc/images/cursor-wait.png b/src/corelib/doc/images/cursor-wait.png new file mode 100644 index 0000000000..69056c479e Binary files /dev/null and b/src/corelib/doc/images/cursor-wait.png differ diff --git a/src/corelib/doc/images/cursor-whatsthis.png b/src/corelib/doc/images/cursor-whatsthis.png new file mode 100644 index 0000000000..b47601c378 Binary files /dev/null and b/src/corelib/doc/images/cursor-whatsthis.png differ diff --git a/src/corelib/doc/images/javaiterators1.png b/src/corelib/doc/images/javaiterators1.png new file mode 100644 index 0000000000..7dfcde0188 Binary files /dev/null and b/src/corelib/doc/images/javaiterators1.png differ diff --git a/src/corelib/doc/images/javaiterators2.png b/src/corelib/doc/images/javaiterators2.png new file mode 100644 index 0000000000..c04e3ccf88 Binary files /dev/null and b/src/corelib/doc/images/javaiterators2.png differ diff --git a/src/corelib/doc/images/modelindex-no-parent.png b/src/corelib/doc/images/modelindex-no-parent.png new file mode 100644 index 0000000000..9c6258e5d1 Binary files /dev/null and b/src/corelib/doc/images/modelindex-no-parent.png differ diff --git a/src/corelib/doc/images/modelview-begin-append-columns.png b/src/corelib/doc/images/modelview-begin-append-columns.png new file mode 100644 index 0000000000..8d13b178d8 Binary files /dev/null and b/src/corelib/doc/images/modelview-begin-append-columns.png differ diff --git a/src/corelib/doc/images/modelview-begin-append-rows.png b/src/corelib/doc/images/modelview-begin-append-rows.png new file mode 100644 index 0000000000..50d04c3e67 Binary files /dev/null and b/src/corelib/doc/images/modelview-begin-append-rows.png differ diff --git a/src/corelib/doc/images/modelview-begin-insert-columns.png b/src/corelib/doc/images/modelview-begin-insert-columns.png new file mode 100644 index 0000000000..30eeb8280e Binary files /dev/null and b/src/corelib/doc/images/modelview-begin-insert-columns.png differ diff --git a/src/corelib/doc/images/modelview-begin-insert-rows.png b/src/corelib/doc/images/modelview-begin-insert-rows.png new file mode 100644 index 0000000000..b4d6eda57d Binary files /dev/null and b/src/corelib/doc/images/modelview-begin-insert-rows.png differ diff --git a/src/corelib/doc/images/modelview-begin-remove-columns.png b/src/corelib/doc/images/modelview-begin-remove-columns.png new file mode 100644 index 0000000000..aee60e01ec Binary files /dev/null and b/src/corelib/doc/images/modelview-begin-remove-columns.png differ diff --git a/src/corelib/doc/images/modelview-begin-remove-rows.png b/src/corelib/doc/images/modelview-begin-remove-rows.png new file mode 100644 index 0000000000..8e9518718e Binary files /dev/null and b/src/corelib/doc/images/modelview-begin-remove-rows.png differ diff --git a/src/corelib/doc/images/modelview-move-rows-1.png b/src/corelib/doc/images/modelview-move-rows-1.png new file mode 100644 index 0000000000..b629a72dd4 Binary files /dev/null and b/src/corelib/doc/images/modelview-move-rows-1.png differ diff --git a/src/corelib/doc/images/modelview-move-rows-2.png b/src/corelib/doc/images/modelview-move-rows-2.png new file mode 100644 index 0000000000..674ca18f78 Binary files /dev/null and b/src/corelib/doc/images/modelview-move-rows-2.png differ diff --git a/src/corelib/doc/images/modelview-move-rows-3.png b/src/corelib/doc/images/modelview-move-rows-3.png new file mode 100644 index 0000000000..5445dd599c Binary files /dev/null and b/src/corelib/doc/images/modelview-move-rows-3.png differ diff --git a/src/corelib/doc/images/modelview-move-rows-4.png b/src/corelib/doc/images/modelview-move-rows-4.png new file mode 100644 index 0000000000..ecd65bac6c Binary files /dev/null and b/src/corelib/doc/images/modelview-move-rows-4.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inback.png b/src/corelib/doc/images/qeasingcurve-inback.png new file mode 100644 index 0000000000..0064cb341c Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inback.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inbounce.png b/src/corelib/doc/images/qeasingcurve-inbounce.png new file mode 100644 index 0000000000..eaa64f8c41 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inbounce.png differ diff --git a/src/corelib/doc/images/qeasingcurve-incirc.png b/src/corelib/doc/images/qeasingcurve-incirc.png new file mode 100644 index 0000000000..7bd0f09d41 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-incirc.png differ diff --git a/src/corelib/doc/images/qeasingcurve-incubic.png b/src/corelib/doc/images/qeasingcurve-incubic.png new file mode 100644 index 0000000000..1ac9eafba5 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-incubic.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inelastic.png b/src/corelib/doc/images/qeasingcurve-inelastic.png new file mode 100644 index 0000000000..f976b5a576 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inelastic.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inexpo.png b/src/corelib/doc/images/qeasingcurve-inexpo.png new file mode 100644 index 0000000000..1af3652985 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inexpo.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inoutback.png b/src/corelib/doc/images/qeasingcurve-inoutback.png new file mode 100644 index 0000000000..480bc051ef Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inoutback.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inoutbounce.png b/src/corelib/doc/images/qeasingcurve-inoutbounce.png new file mode 100644 index 0000000000..de623091cf Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inoutbounce.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inoutcirc.png b/src/corelib/doc/images/qeasingcurve-inoutcirc.png new file mode 100644 index 0000000000..b4be8ac21e Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inoutcirc.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inoutcubic.png b/src/corelib/doc/images/qeasingcurve-inoutcubic.png new file mode 100644 index 0000000000..49dfbef1b6 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inoutcubic.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inoutelastic.png b/src/corelib/doc/images/qeasingcurve-inoutelastic.png new file mode 100644 index 0000000000..5b0e54a019 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inoutelastic.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inoutexpo.png b/src/corelib/doc/images/qeasingcurve-inoutexpo.png new file mode 100644 index 0000000000..776984a113 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inoutexpo.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inoutquad.png b/src/corelib/doc/images/qeasingcurve-inoutquad.png new file mode 100644 index 0000000000..264333085a Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inoutquad.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inoutquart.png b/src/corelib/doc/images/qeasingcurve-inoutquart.png new file mode 100644 index 0000000000..31fc0c8852 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inoutquart.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inoutquint.png b/src/corelib/doc/images/qeasingcurve-inoutquint.png new file mode 100644 index 0000000000..4d7a745be6 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inoutquint.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inoutsine.png b/src/corelib/doc/images/qeasingcurve-inoutsine.png new file mode 100644 index 0000000000..012ff751c9 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inoutsine.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inquad.png b/src/corelib/doc/images/qeasingcurve-inquad.png new file mode 100644 index 0000000000..e697c208a5 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inquad.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inquart.png b/src/corelib/doc/images/qeasingcurve-inquart.png new file mode 100644 index 0000000000..6d6517551e Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inquart.png differ diff --git a/src/corelib/doc/images/qeasingcurve-inquint.png b/src/corelib/doc/images/qeasingcurve-inquint.png new file mode 100644 index 0000000000..faaaea71fd Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-inquint.png differ diff --git a/src/corelib/doc/images/qeasingcurve-insine.png b/src/corelib/doc/images/qeasingcurve-insine.png new file mode 100644 index 0000000000..09449034b5 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-insine.png differ diff --git a/src/corelib/doc/images/qeasingcurve-linear.png b/src/corelib/doc/images/qeasingcurve-linear.png new file mode 100644 index 0000000000..fb3aaf3541 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-linear.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outback.png b/src/corelib/doc/images/qeasingcurve-outback.png new file mode 100644 index 0000000000..83b3fa233f Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outback.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outbounce.png b/src/corelib/doc/images/qeasingcurve-outbounce.png new file mode 100644 index 0000000000..27ac979642 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outbounce.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outcirc.png b/src/corelib/doc/images/qeasingcurve-outcirc.png new file mode 100644 index 0000000000..00193700e0 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outcirc.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outcubic.png b/src/corelib/doc/images/qeasingcurve-outcubic.png new file mode 100644 index 0000000000..45477c045a Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outcubic.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outelastic.png b/src/corelib/doc/images/qeasingcurve-outelastic.png new file mode 100644 index 0000000000..1d407ed845 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outelastic.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outexpo.png b/src/corelib/doc/images/qeasingcurve-outexpo.png new file mode 100644 index 0000000000..56851554ed Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outexpo.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outinback.png b/src/corelib/doc/images/qeasingcurve-outinback.png new file mode 100644 index 0000000000..4700ab02e8 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outinback.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outinbounce.png b/src/corelib/doc/images/qeasingcurve-outinbounce.png new file mode 100644 index 0000000000..12cc1a8bd4 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outinbounce.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outincirc.png b/src/corelib/doc/images/qeasingcurve-outincirc.png new file mode 100644 index 0000000000..c8a5c86a23 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outincirc.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outincubic.png b/src/corelib/doc/images/qeasingcurve-outincubic.png new file mode 100644 index 0000000000..42af870d99 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outincubic.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outinelastic.png b/src/corelib/doc/images/qeasingcurve-outinelastic.png new file mode 100644 index 0000000000..308be57900 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outinelastic.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outinexpo.png b/src/corelib/doc/images/qeasingcurve-outinexpo.png new file mode 100644 index 0000000000..0692baa264 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outinexpo.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outinquad.png b/src/corelib/doc/images/qeasingcurve-outinquad.png new file mode 100644 index 0000000000..9e3cd83896 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outinquad.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outinquart.png b/src/corelib/doc/images/qeasingcurve-outinquart.png new file mode 100644 index 0000000000..9a3c16f122 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outinquart.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outinquint.png b/src/corelib/doc/images/qeasingcurve-outinquint.png new file mode 100644 index 0000000000..add9feb26f Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outinquint.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outinsine.png b/src/corelib/doc/images/qeasingcurve-outinsine.png new file mode 100644 index 0000000000..4bc2aaf9e3 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outinsine.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outquad.png b/src/corelib/doc/images/qeasingcurve-outquad.png new file mode 100644 index 0000000000..c505ff9e7b Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outquad.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outquart.png b/src/corelib/doc/images/qeasingcurve-outquart.png new file mode 100644 index 0000000000..6eac058d18 Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outquart.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outquint.png b/src/corelib/doc/images/qeasingcurve-outquint.png new file mode 100644 index 0000000000..77a9ad417f Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outquint.png differ diff --git a/src/corelib/doc/images/qeasingcurve-outsine.png b/src/corelib/doc/images/qeasingcurve-outsine.png new file mode 100644 index 0000000000..d135b2f98c Binary files /dev/null and b/src/corelib/doc/images/qeasingcurve-outsine.png differ diff --git a/src/corelib/doc/images/qimage-scaling.png b/src/corelib/doc/images/qimage-scaling.png new file mode 100644 index 0000000000..fcd71448f0 Binary files /dev/null and b/src/corelib/doc/images/qimage-scaling.png differ diff --git a/src/corelib/doc/images/qline-coordinates.png b/src/corelib/doc/images/qline-coordinates.png new file mode 100644 index 0000000000..ac4fb980ac Binary files /dev/null and b/src/corelib/doc/images/qline-coordinates.png differ diff --git a/src/corelib/doc/images/qline-point.png b/src/corelib/doc/images/qline-point.png new file mode 100644 index 0000000000..3bc3664a20 Binary files /dev/null and b/src/corelib/doc/images/qline-point.png differ diff --git a/src/corelib/doc/images/qlinef-angle-identicaldirection.png b/src/corelib/doc/images/qlinef-angle-identicaldirection.png new file mode 100644 index 0000000000..18d632321b Binary files /dev/null and b/src/corelib/doc/images/qlinef-angle-identicaldirection.png differ diff --git a/src/corelib/doc/images/qlinef-angle-oppositedirection.png b/src/corelib/doc/images/qlinef-angle-oppositedirection.png new file mode 100644 index 0000000000..bf52cfe011 Binary files /dev/null and b/src/corelib/doc/images/qlinef-angle-oppositedirection.png differ diff --git a/src/corelib/doc/images/qlinef-bounded.png b/src/corelib/doc/images/qlinef-bounded.png new file mode 100644 index 0000000000..136dd50304 Binary files /dev/null and b/src/corelib/doc/images/qlinef-bounded.png differ diff --git a/src/corelib/doc/images/qlinef-normalvector.png b/src/corelib/doc/images/qlinef-normalvector.png new file mode 100644 index 0000000000..b7d944f32f Binary files /dev/null and b/src/corelib/doc/images/qlinef-normalvector.png differ diff --git a/src/corelib/doc/images/qlinef-unbounded.png b/src/corelib/doc/images/qlinef-unbounded.png new file mode 100644 index 0000000000..75ead98ff2 Binary files /dev/null and b/src/corelib/doc/images/qlinef-unbounded.png differ diff --git a/src/corelib/doc/images/qpen-bevel.png b/src/corelib/doc/images/qpen-bevel.png new file mode 100644 index 0000000000..8a30779e3b Binary files /dev/null and b/src/corelib/doc/images/qpen-bevel.png differ diff --git a/src/corelib/doc/images/qpen-custom.png b/src/corelib/doc/images/qpen-custom.png new file mode 100644 index 0000000000..a2a038abe0 Binary files /dev/null and b/src/corelib/doc/images/qpen-custom.png differ diff --git a/src/corelib/doc/images/qpen-dash.png b/src/corelib/doc/images/qpen-dash.png new file mode 100644 index 0000000000..67082c3758 Binary files /dev/null and b/src/corelib/doc/images/qpen-dash.png differ diff --git a/src/corelib/doc/images/qpen-dashdot.png b/src/corelib/doc/images/qpen-dashdot.png new file mode 100644 index 0000000000..64b384660f Binary files /dev/null and b/src/corelib/doc/images/qpen-dashdot.png differ diff --git a/src/corelib/doc/images/qpen-dashdotdot.png b/src/corelib/doc/images/qpen-dashdotdot.png new file mode 100644 index 0000000000..ff1b2e69cd Binary files /dev/null and b/src/corelib/doc/images/qpen-dashdotdot.png differ diff --git a/src/corelib/doc/images/qpen-dot.png b/src/corelib/doc/images/qpen-dot.png new file mode 100644 index 0000000000..54e81c9469 Binary files /dev/null and b/src/corelib/doc/images/qpen-dot.png differ diff --git a/src/corelib/doc/images/qpen-flat.png b/src/corelib/doc/images/qpen-flat.png new file mode 100644 index 0000000000..06e2195f73 Binary files /dev/null and b/src/corelib/doc/images/qpen-flat.png differ diff --git a/src/corelib/doc/images/qpen-miter.png b/src/corelib/doc/images/qpen-miter.png new file mode 100644 index 0000000000..025e003979 Binary files /dev/null and b/src/corelib/doc/images/qpen-miter.png differ diff --git a/src/corelib/doc/images/qpen-roundcap.png b/src/corelib/doc/images/qpen-roundcap.png new file mode 100644 index 0000000000..77b22b2bab Binary files /dev/null and b/src/corelib/doc/images/qpen-roundcap.png differ diff --git a/src/corelib/doc/images/qpen-roundjoin.png b/src/corelib/doc/images/qpen-roundjoin.png new file mode 100644 index 0000000000..155e2aa8cc Binary files /dev/null and b/src/corelib/doc/images/qpen-roundjoin.png differ diff --git a/src/corelib/doc/images/qpen-solid.png b/src/corelib/doc/images/qpen-solid.png new file mode 100644 index 0000000000..e042b18017 Binary files /dev/null and b/src/corelib/doc/images/qpen-solid.png differ diff --git a/src/corelib/doc/images/qpen-square.png b/src/corelib/doc/images/qpen-square.png new file mode 100644 index 0000000000..ebc5d1e329 Binary files /dev/null and b/src/corelib/doc/images/qpen-square.png differ diff --git a/src/corelib/doc/images/qrect-coordinates.png b/src/corelib/doc/images/qrect-coordinates.png new file mode 100644 index 0000000000..2a2dae2d6c Binary files /dev/null and b/src/corelib/doc/images/qrect-coordinates.png differ diff --git a/src/corelib/doc/images/qrect-diagram-one.png b/src/corelib/doc/images/qrect-diagram-one.png new file mode 100644 index 0000000000..a893be277a Binary files /dev/null and b/src/corelib/doc/images/qrect-diagram-one.png differ diff --git a/src/corelib/doc/images/qrect-diagram-three.png b/src/corelib/doc/images/qrect-diagram-three.png new file mode 100644 index 0000000000..84fb35be6c Binary files /dev/null and b/src/corelib/doc/images/qrect-diagram-three.png differ diff --git a/src/corelib/doc/images/qrect-diagram-two.png b/src/corelib/doc/images/qrect-diagram-two.png new file mode 100644 index 0000000000..e19caacc34 Binary files /dev/null and b/src/corelib/doc/images/qrect-diagram-two.png differ diff --git a/src/corelib/doc/images/qrect-diagram-zero.png b/src/corelib/doc/images/qrect-diagram-zero.png new file mode 100644 index 0000000000..90e3db0c41 Binary files /dev/null and b/src/corelib/doc/images/qrect-diagram-zero.png differ diff --git a/src/corelib/doc/images/qrect-intersect.png b/src/corelib/doc/images/qrect-intersect.png new file mode 100644 index 0000000000..db68cd53ad Binary files /dev/null and b/src/corelib/doc/images/qrect-intersect.png differ diff --git a/src/corelib/doc/images/qrect-unite.png b/src/corelib/doc/images/qrect-unite.png new file mode 100644 index 0000000000..3f6239f405 Binary files /dev/null and b/src/corelib/doc/images/qrect-unite.png differ diff --git a/src/corelib/doc/images/qrectf-coordinates.png b/src/corelib/doc/images/qrectf-coordinates.png new file mode 100644 index 0000000000..ccc6d82063 Binary files /dev/null and b/src/corelib/doc/images/qrectf-coordinates.png differ diff --git a/src/corelib/doc/images/qrectf-diagram-one.png b/src/corelib/doc/images/qrectf-diagram-one.png new file mode 100644 index 0000000000..842289ce07 Binary files /dev/null and b/src/corelib/doc/images/qrectf-diagram-one.png differ diff --git a/src/corelib/doc/images/qrectf-diagram-three.png b/src/corelib/doc/images/qrectf-diagram-three.png new file mode 100644 index 0000000000..e05106a7e1 Binary files /dev/null and b/src/corelib/doc/images/qrectf-diagram-three.png differ diff --git a/src/corelib/doc/images/qrectf-diagram-two.png b/src/corelib/doc/images/qrectf-diagram-two.png new file mode 100644 index 0000000000..192d00df79 Binary files /dev/null and b/src/corelib/doc/images/qrectf-diagram-two.png differ diff --git a/src/corelib/doc/images/qsortfilterproxymodel-sorting.png b/src/corelib/doc/images/qsortfilterproxymodel-sorting.png new file mode 100644 index 0000000000..de99d41272 Binary files /dev/null and b/src/corelib/doc/images/qsortfilterproxymodel-sorting.png differ diff --git a/src/corelib/doc/images/qurl-authority.png b/src/corelib/doc/images/qurl-authority.png new file mode 100644 index 0000000000..54de2a792e Binary files /dev/null and b/src/corelib/doc/images/qurl-authority.png differ diff --git a/src/corelib/doc/images/qurl-authority2.png b/src/corelib/doc/images/qurl-authority2.png new file mode 100644 index 0000000000..fe8d4d87b2 Binary files /dev/null and b/src/corelib/doc/images/qurl-authority2.png differ diff --git a/src/corelib/doc/images/qurl-authority3.png b/src/corelib/doc/images/qurl-authority3.png new file mode 100644 index 0000000000..242063e935 Binary files /dev/null and b/src/corelib/doc/images/qurl-authority3.png differ diff --git a/src/corelib/doc/images/qurl-fragment.png b/src/corelib/doc/images/qurl-fragment.png new file mode 100644 index 0000000000..e93a252e7a Binary files /dev/null and b/src/corelib/doc/images/qurl-fragment.png differ diff --git a/src/corelib/doc/images/qurl-ftppath.png b/src/corelib/doc/images/qurl-ftppath.png new file mode 100644 index 0000000000..d88df4922b Binary files /dev/null and b/src/corelib/doc/images/qurl-ftppath.png differ diff --git a/src/corelib/doc/images/qurl-mailtopath.png b/src/corelib/doc/images/qurl-mailtopath.png new file mode 100644 index 0000000000..34ec153b74 Binary files /dev/null and b/src/corelib/doc/images/qurl-mailtopath.png differ diff --git a/src/corelib/doc/images/qurl-querystring.png b/src/corelib/doc/images/qurl-querystring.png new file mode 100644 index 0000000000..7c3309a5ac Binary files /dev/null and b/src/corelib/doc/images/qurl-querystring.png differ diff --git a/src/corelib/doc/images/stliterators1.png b/src/corelib/doc/images/stliterators1.png new file mode 100644 index 0000000000..6d71e4712f Binary files /dev/null and b/src/corelib/doc/images/stliterators1.png differ diff --git a/src/corelib/doc/images/thread_clock.png b/src/corelib/doc/images/thread_clock.png new file mode 100644 index 0000000000..b8a8aa0a39 Binary files /dev/null and b/src/corelib/doc/images/thread_clock.png differ diff --git a/src/corelib/doc/images/threadsandobjects.png b/src/corelib/doc/images/threadsandobjects.png new file mode 100644 index 0000000000..8357d2532a Binary files /dev/null and b/src/corelib/doc/images/threadsandobjects.png differ diff --git a/src/corelib/doc/images/threadvisual-example.png b/src/corelib/doc/images/threadvisual-example.png new file mode 100644 index 0000000000..2a49874719 Binary files /dev/null and b/src/corelib/doc/images/threadvisual-example.png differ diff --git a/src/corelib/doc/qtcore.qdocconf b/src/corelib/doc/qtcore.qdocconf new file mode 100644 index 0000000000..31b53c9254 --- /dev/null +++ b/src/corelib/doc/qtcore.qdocconf @@ -0,0 +1,90 @@ +include(../../../doc/global/qt-cpp-ignore.qdocconf) + +project = QtCore +description = Qt Core Reference Documentation +url = http://qt-project.org/doc/qt-5.0/qtcore +version = 5.0.0 + +sourceencoding = UTF-8 +outputencoding = UTF-8 +naturallanguage = en_US +qhp.projects = QtCore + +qhp.QtCore.file = qtcore.qhp +qhp.Qt.namespace = org.qt-project.qtcore.500 +qhp.Qt.virtualFolder = qdoc +qhp.Qt.indexTitle = Qt Core Reference Documentation +qhp.Qt.indexRoot = + +qhp.Qt.filterAttributes = qtcore 5.0.0 qtrefdoc +qhp.Qt.customFilters.Qt.name = QtCore 5.0.0 +qhp.Qt.customFilters.Qt.filterAttributes = qtcore 5.0.0 +qhp.Qt.subprojects = classes overviews examples +qhp.Qt.subprojects.classes.title = Classes +qhp.Qt.subprojects.classes.indexTitle = Qt Core's Classes +qhp.Qt.subprojects.classes.selectors = class fake:headerfile +qhp.Qt.subprojects.classes.sortPages = true +qhp.Qt.subprojects.overviews.title = Overviews +qhp.Qt.subprojects.overviews.indexTitle = All Overviews and HOWTOs +qhp.Qt.subprojects.overviews.selectors = fake:page,group,module +qhp.Qt.subprojects.examples.title = Qt Core Tutorials and Examples +qhp.Qt.subprojects.examples.indexTitle = Qt Core Examples +qhp.Qt.subprojects.examples.selectors = fake:example + +dita.metadata.default.author = Qt Project +dita.metadata.default.permissions = all +dita.metadata.default.publisher = Qt Project +dita.metadata.default.copyryear = 2012 +dita.metadata.default.copyrholder = Nokia +dita.metadata.default.audience = programmer + +sources.fileextensions = "*.c++ *.cc *.cpp *.cxx *.mm *.qml *.qdoc" +headers.fileextensions = "*.ch *.h *.h++ *.hh *.hpp *.hxx" + +examples.fileextensions = "*.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml *.css" +examples.imageextensions = "*.png" + +outputdir = ../../../doc/qtcore +tagfile = ../../../doc/qtcore/qtcore.tags + +HTML.generatemacrefs = "true" +HTML.nobreadcrumbs = "true" + +HTML.templatedir = . + +HTML.stylesheets = ../../../doc/global/style/offline.css + +HTML.headerstyles = \ + " \n" + +HTML.endheader = \ + "\n" \ + +defines = Q_QDOC \ + QT_.*_SUPPORT \ + QT_.*_LIB \ + QT_COMPAT \ + QT_KEYPAD_NAVIGATION \ + QT_NO_EGL \ + Q_WS_.* \ + Q_OS_.* \ + Q_BYTE_ORDER \ + QT_DEPRECATED \ + QT_DEPRECATED_* \ + Q_NO_USING_KEYWORD \ + __cplusplus \ + Q_COMPILER_INITIALIZER_LISTS + +versionsym = QT_VERSION_STR + +codeindent = 1 + +headerdirs += .. + +sourcedirs += .. + +exampledirs += ../../../examples \ + ../ \ + snippets + +imagedirs += images diff --git a/src/corelib/doc/snippets/buffer/buffer.cpp b/src/corelib/doc/snippets/buffer/buffer.cpp new file mode 100644 index 0000000000..681fb56791 --- /dev/null +++ b/src/corelib/doc/snippets/buffer/buffer.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +static void main_snippet() +{ +//! [0] + QBuffer buffer; + char ch; + + buffer.open(QBuffer::ReadWrite); + buffer.write("Qt rocks!"); + buffer.seek(0); + buffer.getChar(&ch); // ch == 'Q' + buffer.getChar(&ch); // ch == 't' + buffer.getChar(&ch); // ch == ' ' + buffer.getChar(&ch); // ch == 'r' +//! [0] +} + +static void write_datastream_snippets() +{ +//! [1] + QByteArray byteArray; + QBuffer buffer(&byteArray); + buffer.open(QIODevice::WriteOnly); + + QDataStream out(&buffer); + out << QApplication::palette(); +//! [1] +} + +static void read_datastream_snippets() +{ + QByteArray byteArray; + +//! [2] + QPalette palette; + QBuffer buffer(&byteArray); + buffer.open(QIODevice::ReadOnly); + + QDataStream in(&buffer); + in >> palette; +//! [2] +} + +static void bytearray_ptr_ctor_snippet() +{ +//! [3] + QByteArray byteArray("abc"); + QBuffer buffer(&byteArray); + buffer.open(QIODevice::WriteOnly); + buffer.seek(3); + buffer.write("def", 3); + buffer.close(); + // byteArray == "abcdef" +//! [3] +} + +static void setBuffer_snippet() +{ +//! [4] + QByteArray byteArray("abc"); + QBuffer buffer; + buffer.setBuffer(&byteArray); + buffer.open(QIODevice::WriteOnly); + buffer.seek(3); + buffer.write("def", 3); + buffer.close(); + // byteArray == "abcdef" +//! [4] +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + main_snippet(); + bytearray_ptr_ctor_snippet(); + write_datastream_snippets(); + read_datastream_snippets(); + setBuffer_snippet(); + return 0; +} diff --git a/src/corelib/doc/snippets/code/doc_src_containers.cpp b/src/corelib/doc/snippets/code/doc_src_containers.cpp new file mode 100644 index 0000000000..c74b0f79dc --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_containers.cpp @@ -0,0 +1,275 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class Employee +{ +public: + Employee() {} + Employee(const Employee &other); + + Employee &operator=(const Employee &other); + +private: + QString myName; + QDate myDateOfBirth; +}; +//! [0] + + +//! [1] +QList list; +list << "A" << "B" << "C" << "D"; + +QListIterator i(list); +while (i.hasNext()) + qDebug() << i.next(); +//! [1] + + +//! [2] +QListIterator i(list); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [2] + + +//! [3] +QMutableListIterator i(list); +while (i.hasNext()) { + if (i.next() % 2 != 0) + i.remove(); +} +//! [3] + + +//! [4] +QMutableListIterator i(list); +i.toBack(); +while (i.hasPrevious()) { + if (i.previous() % 2 != 0) + i.remove(); +} +//! [4] + + +//! [5] +QMutableListIterator i(list); +while (i.hasNext()) { + if (i.next() > 128) + i.setValue(128); +} +//! [5] + + +//! [6] +QMutableListIterator i(list); +while (i.hasNext()) + i.next() *= 2; +//! [6] + + +//! [7] +QMap map; +map.insert("Paris", "France"); +map.insert("Guatemala City", "Guatemala"); +map.insert("Mexico City", "Mexico"); +map.insert("Moscow", "Russia"); +... + +QMutableMapIterator i(map); +while (i.hasNext()) { + if (i.next().key().endsWith("City")) + i.remove(); +} +//! [7] + + +//! [8] +QMap map; +QHash hash; + +QMapIterator i(map); +while (i.hasNext()) { + i.next(); + hash.insert(i.key(), i.value()); +} +//! [8] + + +//! [9] +QMutableMapIterator i(map); +while (i.findNext(widget)) + i.remove(); +//! [9] + + +//! [10] +QList list; +list << "A" << "B" << "C" << "D"; + +QList::iterator i; +for (i = list.begin(); i != list.end(); ++i) + *i = (*i).toLower(); +//! [10] + + +//! [11] +QList list; +list << "A" << "B" << "C" << "D"; + +QList::iterator i = list.end(); +while (i != list.begin()) { + --i; + *i = (*i).toLower(); +} +//! [11] + + +//! [12] +QList::const_iterator i; +for (i = list.constBegin(); i != list.constEnd(); ++i) + qDebug() << *i; +//! [12] + + +//! [13] +QMap map; +... +QMap::const_iterator i; +for (i = map.constBegin(); i != map.constEnd(); ++i) + qDebug() << i.key() << ":" << i.value(); +//! [13] + + +//! [14] +// RIGHT +const QList sizes = splitter->sizes(); +QList::const_iterator i; +for (i = sizes.begin(); i != sizes.end(); ++i) + ... + +// WRONG +QList::const_iterator i; +for (i = splitter->sizes().begin(); + i != splitter->sizes().end(); ++i) + ... +//! [14] + + +//! [15] +QLinkedList list; +... +QString str; +foreach (str, list) + qDebug() << str; +//! [15] + + +//! [16] +QLinkedList list; +... +QLinkedListIterator i(list); +while (i.hasNext()) + qDebug() << i.next(); +//! [16] + + +//! [17] +QLinkedList list; +... +foreach (const QString &str, list) + qDebug() << str; +//! [17] + + +//! [18] +QLinkedList list; +... +foreach (const QString &str, list) { + if (str.isEmpty()) + break; + qDebug() << str; +} +//! [18] + + +//! [19] +QMap map; +... +foreach (const QString &str, map.keys()) + qDebug() << str << ":" << map.value(str); +//! [19] + + +//! [20] +QMultiMap map; +... +foreach (const QString &str, map.uniqueKeys()) { + foreach (int i, map.values(str)) + qDebug() << str << ":" << i; +} +//! [20] + + +//! [21] +forever { + ... +} +//! [21] + + +//! [22] +CONFIG += no_keywords +//! [22] + + +//! [23] +QString onlyLetters(const QString &in) +{ + QString out; + for (int j = 0; j < in.size(); ++j) { + if (in[j].isLetter()) + out += in[j]; + } + return out; +} +//! [23] diff --git a/src/corelib/doc/snippets/code/doc_src_groups.cpp b/src/corelib/doc/snippets/code/doc_src_groups.cpp new file mode 100644 index 0000000000..abfbfc59c0 --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_groups.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +void QPen::setStyle(Qt::PenStyle style) +{ + detach(); // detach from common data + d->style = style; // set the style member +} + +void QPen::detach() +{ + if (d->ref != 1) { + ... // perform a deep copy + } +} +//! [0] + + +//! [1] +QPixmap p1, p2; +p1.load("image.bmp"); +p2 = p1; // p1 and p2 share data + +QPainter paint; +paint.begin(&p2); // cuts p2 loose from p1 +paint.drawText(0,50, "Hi"); +paint.end(); +//! [1] diff --git a/src/corelib/doc/snippets/code/doc_src_objecttrees.cpp b/src/corelib/doc/snippets/code/doc_src_objecttrees.cpp new file mode 100644 index 0000000000..62d556057b --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_objecttrees.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//![0] +int main() +{ + QWidget window; + QPushButton quit("Quit", &window); + ... +} +//![0] + + +//![1] +int main() +{ + QPushButton quit("Quit"); + QWidget window; + + quit.setParent(&window); + ... +} +//![1] diff --git a/src/corelib/doc/snippets/code/doc_src_properties.cpp b/src/corelib/doc/snippets/code/doc_src_properties.cpp new file mode 100644 index 0000000000..b88fc22084 --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_properties.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +Q_PROPERTY(type name + READ getFunction + [WRITE setFunction] + [RESET resetFunction] + [NOTIFY notifySignal] + [REVISION int] + [DESIGNABLE bool] + [SCRIPTABLE bool] + [STORED bool] + [USER bool] + [CONSTANT] + [FINAL]) +//! [0] + + +//! [1] +Q_PROPERTY(bool focus READ hasFocus) +Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) +Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor) +//! [1] + + +//! [2] +Q_PROPERTY(QDate date READ getDate WRITE setDate) +//! [2] + + +//! [3] +QPushButton *button = new QPushButton; +QObject *object = button; + +button->setDown(true); +object->setProperty("down", true); +//! [3] + + +//! [4] +QObject *object = ... +const QMetaObject *metaobject = object->metaObject(); +int count = metaobject->propertyCount(); +for (int i=0; iproperty(i); + const char *name = metaproperty.name(); + QVariant value = object->property(name); + ... +} +//! [4] + + +//! [5] +class MyClass : public QObject +{ + Q_OBJECT + Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged) + Q_ENUMS(Priority) + +public: + MyClass(QObject *parent = 0); + ~MyClass(); + + enum Priority { High, Low, VeryHigh, VeryLow }; + + void setPriority(Priority priority) + { + m_priority = priority; + emit priorityChanged(priority); + } + Priority priority() const + { return m_priority; } + +signals: + void priorityChanged(Priority); + +private: + Priority m_priority; +}; +//! [5] + + +//! [6] +MyClass *myinstance = new MyClass; +QObject *object = myinstance; + +myinstance->setPriority(MyClass::VeryHigh); +object->setProperty("priority", "VeryHigh"); +//! [6] + + +//! [7] +Q_CLASSINFO("Version", "3.0.0") +//! [7] diff --git a/src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp b/src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp new file mode 100644 index 0000000000..20e64b61fa --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp @@ -0,0 +1,354 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QStringList list; +list << "one" << "two" << "three"; + +qFill(list.begin(), list.end(), "eleven"); +// list: [ "eleven", "eleven", "eleven" ] +//! [0] + + +//! [1] +qFill(list.begin() + 1, list.end(), "six"); +// list: [ "eleven", "six", "six" ] +//! [1] + + +//! [2] +QChar resolveEntity(const QString &entity) +{ + static const QLatin1String name_table[] = { + "AElig", "Aacute", ..., "zwnj" + }; + static const ushort value_table[] = { + 0x0061, 0x00c1, ..., 0x200c + }; + int N = sizeof(name_table) / sizeof(name_table[0]); + + const QLatin1String *name = qBinaryFind(name_table, name_table + N, + entity); + int index = name - name_table; + if (index == N) + return QChar(); + + return QChar(value_table[index]); +} +//! [2] + + +//! [3] +QChar resolveEntity(const QString &entity) +{ + static QMap entityMap; + + if (!entityMap) { + entityMap.insert("AElig", 0x0061); + entityMap.insert("Aacute", 0x00c1); + ... + entityMap.insert("zwnj", 0x200c); + } + return QChar(entityMap.value(entity)); +} +//! [3] + + +//! [4] +QStringList list; +list << "one" << "two" << "three"; + +QVector vect1(3); +qCopy(list.begin(), list.end(), vect1.begin()); +// vect: [ "one", "two", "three" ] + +QVector vect2(8); +qCopy(list.begin(), list.end(), vect2.begin() + 2); +// vect: [ "", "", "one", "two", "three", "", "", "" ] +//! [4] + + +//! [5] +QStringList list; +list << "one" << "two" << "three"; + +QVector vect(5); +qCopyBackward(list.begin(), list.end(), vect.end()); +// vect: [ "", "", "one", "two", "three" ] +//! [5] + + +//! [6] +QStringList list; +list << "one" << "two" << "three"; + +QVector vect(3); +vect[0] = "one"; +vect[1] = "two"; +vect[2] = "three"; + +bool ret1 = qEqual(list.begin(), list.end(), vect.begin()); +// ret1 == true + +vect[2] = "seven"; +bool ret2 = qEqual(list.begin(), list.end(), vect.begin()); +// ret2 == false +//! [6] + + +//! [7] +QStringList list; +list << "one" << "two" << "three"; + +qFill(list.begin(), list.end(), "eleven"); +// list: [ "eleven", "eleven", "eleven" ] + +qFill(list.begin() + 1, list.end(), "six"); +// list: [ "eleven", "six", "six" ] +//! [7] + + +//! [8] +QStringList list; +list << "one" << "two" << "three"; + +QStringList::iterator i1 = qFind(list.begin(), list.end(), "two"); +// i1 == list.begin() + 1 + +QStringList::iterator i2 = qFind(list.begin(), list.end(), "seventy"); +// i2 == list.end() +//! [8] + + +//! [9] +QList list; +list << 3 << 3 << 6 << 6 << 6 << 8; + +int countOf6 = 0; +qCount(list.begin(), list.end(), 6, countOf6); +// countOf6 == 3 + +int countOf7 = 0; +qCount(list.begin(), list.end(), 7, countOf7); +// countOf7 == 0 +//! [9] + + +//! [10] +double pi = 3.14; +double e = 2.71; + +qSwap(pi, e); +// pi == 2.71, e == 3.14 +//! [10] + + +//! [11] +QList list; +list << 33 << 12 << 68 << 6 << 12; +qSort(list.begin(), list.end()); +// list: [ 6, 12, 12, 33, 68 ] +//! [11] + + +//! [12] +bool caseInsensitiveLessThan(const QString &s1, const QString &s2) +{ + return s1.toLower() < s2.toLower(); +} + +int doSomething() +{ + QStringList list; + list << "AlPha" << "beTA" << "gamma" << "DELTA"; + qSort(list.begin(), list.end(), caseInsensitiveLessThan); + // list: [ "AlPha", "beTA", "DELTA", "gamma" ] +} +//! [12] + + +//! [13] +QList list; +list << 33 << 12 << 68 << 6 << 12; +qSort(list.begin(), list.end(), qGreater()); +// list: [ 68, 33, 12, 12, 6 ] +//! [13] + + +//! [14] +QStringList list; +list << "AlPha" << "beTA" << "gamma" << "DELTA"; + +QMap map; +foreach (const QString &str, list) + map.insert(str.toLower(), str); + +list = map.values(); +//! [14] + + +//! [15] +QList list; +list << 33 << 12 << 68 << 6 << 12; +qStableSort(list.begin(), list.end()); +// list: [ 6, 12, 12, 33, 68 ] +//! [15] + + +//! [16] +bool caseInsensitiveLessThan(const QString &s1, const QString &s2) +{ + return s1.toLower() < s2.toLower(); +} + +int doSomething() +{ + QStringList list; + list << "AlPha" << "beTA" << "gamma" << "DELTA"; + qStableSort(list.begin(), list.end(), caseInsensitiveLessThan); + // list: [ "AlPha", "beTA", "DELTA", "gamma" ] +} +//! [16] + + +//! [17] +QList list; +list << 33 << 12 << 68 << 6 << 12; +qStableSort(list.begin(), list.end(), qGreater()); +// list: [ 68, 33, 12, 12, 6 ] +//! [17] + + +//! [18] +QList list; +list << 3 << 3 << 6 << 6 << 6 << 8; + +QList::iterator i = qLowerBound(list.begin(), list.end(), 5); +list.insert(i, 5); +// list: [ 3, 3, 5, 6, 6, 6, 8 ] + +i = qLowerBound(list.begin(), list.end(), 12); +list.insert(i, 12); +// list: [ 3, 3, 5, 6, 6, 6, 8, 12 ] +//! [18] + + +//! [19] +QVector vect; +vect << 3 << 3 << 6 << 6 << 6 << 8; +QVector::iterator begin6 = + qLowerBound(vect.begin(), vect.end(), 6); +QVector::iterator end6 = + qUpperBound(begin6, vect.end(), 6); + +QVector::iterator i = begin6; +while (i != end6) { + *i = 7; + ++i; +} +// vect: [ 3, 3, 7, 7, 7, 8 ] +//! [19] + + +//! [20] +QList list; +list << 3 << 3 << 6 << 6 << 6 << 8; + +QList::iterator i = qUpperBound(list.begin(), list.end(), 5); +list.insert(i, 5); +// list: [ 3, 3, 5, 6, 6, 6, 8 ] + +i = qUpperBound(list.begin(), list.end(), 12); +list.insert(i, 12); +// list: [ 3, 3, 5, 6, 6, 6, 8, 12 ] +//! [20] + + +//! [21] +QVector vect; +vect << 3 << 3 << 6 << 6 << 6 << 8; +QVector::iterator begin6 = + qLowerBound(vect.begin(), vect.end(), 6); +QVector::iterator end6 = + qUpperBound(vect.begin(), vect.end(), 6); + +QVector::iterator i = begin6; +while (i != end6) { + *i = 7; + ++i; +} +// vect: [ 3, 3, 7, 7, 7, 8 ] +//! [21] + + +//! [22] +QVector vect; +vect << 3 << 3 << 6 << 6 << 6 << 8; + +QVector::iterator i = + qBinaryFind(vect.begin(), vect.end(), 6); +// i == vect.begin() + 2 (or 3 or 4) +//! [22] + + +//! [23] +QList list; +list.append(new Employee("Blackpool", "Stephen")); +list.append(new Employee("Twist", "Oliver")); + +qDeleteAll(list.begin(), list.end()); +list.clear(); +//! [23] + + +//! [24] +QList list; +list << 33 << 12 << 68 << 6 << 12; +qSort(list.begin(), list.end(), qLess()); +// list: [ 6, 12, 12, 33, 68 ] +//! [24] + + +//! [25] +QList list; +list << 33 << 12 << 68 << 6 << 12; +qSort(list.begin(), list.end(), qGreater()); +// list: [ 68, 33, 12, 12, 6 ] +//! [25] diff --git a/src/corelib/doc/snippets/code/doc_src_qcache.cpp b/src/corelib/doc/snippets/code/doc_src_qcache.cpp new file mode 100644 index 0000000000..0ba9e65531 --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_qcache.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QCache cache; +//! [0] + + +//! [1] +Employee *employee = new Employee; +employee->setId(37); +employee->setName("Richard Schmit"); +... +cache.insert(employee->id(), employee); +//! [1] + + +//! [2] +QCache cache(5000); +//! [2] diff --git a/src/corelib/doc/snippets/code/doc_src_qiterator.cpp b/src/corelib/doc/snippets/code/doc_src_qiterator.cpp new file mode 100644 index 0000000000..b96f9065cb --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_qiterator.cpp @@ -0,0 +1,420 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QList list; +... +QListIterator i(list); +while (i.hasNext()) + qDebug() << i.next(); +//! [0] + + +//! [1] +QListIterator i(list); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [1] + + +//! [2] +QLinkedList list; +... +QLinkedListIterator i(list); +while (i.hasNext()) + qDebug() << i.next(); +//! [2] + + +//! [3] +QLinkedListIterator i(list); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [3] + + +//! [4] +QVector vector; +... +QVectorIterator i(vector); +while (i.hasNext()) + qDebug() << i.next(); +//! [4] + + +//! [5] +QVectorIterator i(vector); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [5] + + +//! [6] +QSet set; +... +QSetIterator i(set); +while (i.hasNext()) + qDebug() << i.next(); +//! [6] + + +//! [7] +QSetIterator i(set); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [7] + + +//! [8] +QList list; +... +QMutableListIterator i(list); +while (i.hasNext()) + qDebug() << i.next(); +//! [8] + + +//! [9] +QMutableListIterator i(list); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [9] + + +//! [10] +QMutableListIterator i(list); +while (i.hasNext()) { + int val = i.next(); + if (val < 0) { + i.setValue(-val); + } else if (val == 0) { + i.remove(); + } +} +//! [10] + + +//! [11] +QLinkedList list; +... +QMutableLinkedListIterator i(list); +while (i.hasNext()) + qDebug() << i.next(); +//! [11] + + +//! [12] +QMutableLinkedListIterator i(list); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [12] + + +//! [13] +QMutableLinkedListIterator i(list); +while (i.hasNext()) { + int val = i.next(); + if (val < 0) { + i.setValue(-val); + } else if (val == 0) { + i.remove(); + } +} +//! [13] + + +//! [14] +QVector vector; +... +QMutableVectorIterator i(vector); +while (i.hasNext()) + qDebug() << i.next(); +//! [14] + + +//! [15] +QMutableVectorIterator i(vector); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [15] + + +//! [16] +QMutableVectorIterator i(vector); +while (i.hasNext()) { + int val = i.next(); + if (val < 0) { + i.setValue(-val); + } else if (val == 0) { + i.remove(); + } +} +//! [16] + + +//! [17] +QSet set; +... +QMutableSetIterator i(set); +while (i.hasNext()) + qDebug() << i.next(); +//! [17] + + +//! [18] +QMutableSetIterator i(set); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [18] + + +//! [19] +QMutableListIterator i(list); +while (i.hasNext()) { + int val = i.next(); + if (val < -32768 || val > 32767) + i.remove(); +} +//! [19] + + +//! [20] +QMutableLinkedListIterator i(list); +while (i.hasNext()) { + int val = i.next(); + if (val < -32768 || val > 32767) + i.remove(); +} +//! [20] + + +//! [21] +QMutableVectorIterator i(vector); +while (i.hasNext()) { + int val = i.next(); + if (val < -32768 || val > 32767) + i.remove(); +} +//! [21] + + +//! [22] +QMutableSetIterator i(set); +while (i.hasNext()) { + int val = i.next(); + if (val < -32768 || val > 32767) + i.remove(); +} +//! [22] + + +//! [23] +QMutableListIterator i(list); +while (i.hasNext()) { + double val = i.next(); + i.setValue(sqrt(val)); +} +//! [23] + + +//! [24] +QMutableLinkedListIterator i(list); +while (i.hasNext()) { + double val = i.next(); + i.setValue(sqrt(val)); +} +//! [24] + + +//! [25] +QMutableVectorIterator i(list); +while (i.hasNext()) { + double val = i.next(); + i.setValue(sqrt(val)); +} +//! [25] + + +//! [26] +QMap map; +... +QMapIterator i(map); +while (i.hasNext()) { + i.next(); + qDebug() << i.key() << ": " << i.value(); +} +//! [26] + + +//! [27] +QMapIterator i(map); +i.toBack(); +while (i.hasPrevious()) { + i.previous(); + qDebug() << i.key() << ": " << i.value(); +} +//! [27] + + +//! [28] +QMapIterator i(map); +while (i.findNext(widget)) { + qDebug() << "Found widget " << widget << " under key " + << i.key(); +} +//! [28] + + +//! [29] +QHash hash; +... +QHashIterator i(hash); +while (i.hasNext()) { + i.next(); + qDebug() << i.key() << ": " << i.value(); +} +//! [29] + + +//! [30] +QHashIterator i(hash); +i.toBack(); +while (i.hasPrevious()) { + i.previous(); + qDebug() << i.key() << ": " << i.value(); +} +//! [30] + + +//! [31] +QHashIterator i(hash); +while (i.findNext(widget)) { + qDebug() << "Found widget " << widget << " under key " + << i.key(); +} +//! [31] + + +//! [32] +QMap map; +... +QMutableMapIterator i(map); +while (i.hasNext()) { + i.next(); + qDebug() << i.key() << ": " << i.value(); +} +//! [32] + + +//! [33] +QMutableMapIterator i(map); +i.toBack(); +while (i.hasPrevious()) { + i.previous(); + qDebug() << i.key() << ": " << i.value(); +} +//! [33] + + +//! [34] +QMutableMapIterator i(map); +while (i.findNext(widget)) { + qDebug() << "Found widget " << widget << " under key " + << i.key(); +} +//! [34] + + +//! [35] +QMutableMapIterator i(map); +while (i.hasNext()) { + i.next(); + if (i.key() == i.value()) + i.remove(); +} +//! [35] + + +//! [36] +QHash hash; +... +QMutableHashIterator i(hash); +while (i.hasNext()) { + i.next(); + qDebug() << i.key() << ": " << i.value(); +} +//! [36] + + +//! [37] +QMutableHashIterator i(hash); +i.toBack(); +while (i.hasPrevious()) { + i.previous(); + qDebug() << i.key() << ": " << i.value(); +} +//! [37] + + +//! [38] +QMutableHashIterator i(hash); +while (i.findNext(widget)) { + qDebug() << "Found widget " << widget << " under key " + << i.key(); +} +//! [38] + + +//! [39] +QMutableHashIterator i(hash); +while (i.hasNext()) { + i.next(); + if (i.key() == i.value()) + i.remove(); +} +//! [39] diff --git a/src/corelib/doc/snippets/code/doc_src_qnamespace.cpp b/src/corelib/doc/snippets/code/doc_src_qnamespace.cpp new file mode 100644 index 0000000000..ec80d011c9 --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_qnamespace.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [1] +enum CustomEventPriority +{ + // An important event + ImportantEventPriority = Qt::HighEventPriority, + + // A more important event + MoreImportantEventPriority = ImportantEventPriority + 1, + + // A critical event + CriticalEventPriority = 100 * MoreImportantEventPriority, + + // Not that important + StatusEventPriority = Qt::LowEventPriority, + + // These are less important than Status events + IdleProcessingDoneEventPriority = StatusEventPriority - 1 +}; +//! [1] diff --git a/src/corelib/doc/snippets/code/doc_src_qnamespace.qdoc b/src/corelib/doc/snippets/code/doc_src_qnamespace.qdoc new file mode 100644 index 0000000000..e67b83a292 --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_qnamespace.qdoc @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QObject::connect: Cannot queue arguments of type 'MyType' +//! [0] diff --git a/src/corelib/doc/snippets/code/doc_src_qpair.cpp b/src/corelib/doc/snippets/code/doc_src_qpair.cpp new file mode 100644 index 0000000000..a29b6d02b2 --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_qpair.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QPair pair; +//! [0] + + +//! [1] +pair.first = "pi"; +pair.second = 3.14159265358979323846; +//! [1] + + +//! [2] +QList > list; +list.append(qMakePair(66, 3.14159)); +//! [2] diff --git a/src/corelib/doc/snippets/code/doc_src_qplugin.cpp b/src/corelib/doc/snippets/code/doc_src_qplugin.cpp new file mode 100644 index 0000000000..1577b2fa61 --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_qplugin.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +namespace Foo +{ + struct MyInterface { ... }; +} + +Q_DECLARE_INTERFACE(Foo::MyInterface, "org.examples.MyInterface") +//! [0] + + +//! [1] +Q_EXPORT_PLUGIN2(pnp_extrafilters, ExtraFiltersPlugin) +//! [1] + + +//! [2] +Q_IMPORT_PLUGIN(qjpeg) +//! [2] + + +//! [3] +TEMPLATE = app +QTPLUGIN += qjpeg qgif # image formats +//! [3] diff --git a/src/corelib/doc/snippets/code/doc_src_qplugin.pro b/src/corelib/doc/snippets/code/doc_src_qplugin.pro new file mode 100644 index 0000000000..e5e5311e5d --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_qplugin.pro @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#! [3] +TEMPLATE = app +QTPLUGIN += qjpeg qgif # image formats +#! [3] diff --git a/src/corelib/doc/snippets/code/doc_src_qset.cpp b/src/corelib/doc/snippets/code/doc_src_qset.cpp new file mode 100644 index 0000000000..cfd366f639 --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_qset.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QSet set; +//! [0] + + +//! [1] +set.insert("one"); +set.insert("three"); +set.insert("seven"); +//! [1] + + +//! [2] +set << "twelve" << "fifteen" << "nineteen"; +//! [2] + + +//! [3] +if (!set.contains("ninety-nine")) + ... +//! [3] + + +//! [4] +QSetIterator i(set); +while (i.hasNext()) + qDebug() << i.next(); +//! [4] + + +//! [5] +QSet::const_iterator i = set.constBegin(); +while (i != set.constEnd()) { + qDebug() << *i; + ++i; +} +//! [5] + + +//! [6] +QSet set; +... +foreach (const QString &value, set) + qDebug() << value; +//! [6] + + +//! [7] +QSet set; +set.reserve(20000); +for (int i = 0; i < 20000; ++i) + set.insert(values[i]); +//! [7] + + +//! [8] +QSet set; +set << "January" << "February" << ... << "December"; + +QSet::iterator i; +for (i = set.begin(); i != set.end(); ++i) + qDebug() << *i; +//! [8] + + +//! [9] +QSet set; +set << "January" << "February" << ... << "December"; + +QSet::iterator i = set.begin(); +while (i != set.end()) { + if ((*i).startsWith('J')) { + i = set.erase(i); + } else { + ++i; + } +} +//! [9] + + +//! [10] +QSet set; +... +QSet::iterator it = qFind(set.begin(), set.end(), "Jeanette"); +if (it != set.end()) + cout << "Found Jeanette" << endl; +//! [10] + + +//! [11] +QSet set; +set << "January" << "February" << ... << "December"; + +QSet::const_iterator i; +for (i = set.begin(); i != set.end(); ++i) + qDebug() << *i; +//! [11] + + +//! [12] +QSet set; +... +QSet::iterator it = qFind(set.begin(), set.end(), "Jeanette"); +if (it != set.constEnd()) + cout << "Found Jeanette" << endl; +//! [12] + + +//! [13] +QSet set; +set << "red" << "green" << "blue" << ... << "black"; + +QList list = set.toList(); +qSort(list); +//! [13] + + +//! [14] +QStringList list; +list << "Julia" << "Mike" << "Mike" << "Julia" << "Julia"; + +QSet set = QSet::fromList(list); +set.contains("Julia"); // returns true +set.contains("Mike"); // returns true +set.size(); // returns 2 +//! [14] diff --git a/src/corelib/doc/snippets/code/doc_src_qtcore.cpp b/src/corelib/doc/snippets/code/doc_src_qtcore.cpp new file mode 100644 index 0000000000..f00c96c6df --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_qtcore.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#include +//! [0] diff --git a/src/corelib/doc/snippets/code/doc_src_qvarlengtharray.cpp b/src/corelib/doc/snippets/code/doc_src_qvarlengtharray.cpp new file mode 100644 index 0000000000..027faa41dc --- /dev/null +++ b/src/corelib/doc/snippets/code/doc_src_qvarlengtharray.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +int myfunc(int n) +{ + int table[n + 1]; // WRONG + ... + return table[n]; +} +//! [0] + + +//! [1] +int myfunc(int n) +{ + int *table = new int[n + 1]; + ... + int ret = table[n]; + delete[] table; + return ret; +} +//! [1] + + +//! [2] +int myfunc(int n) +{ + QVarLengthArray array(n + 1); + ... + return array[n]; +} +//! [2] + + +//! [3] +QVarLengthArray array(10); +int *data = array.data(); +for (int i = 0; i < 10; ++i) + data[i] = 2 * i; +//! [3] diff --git a/src/corelib/doc/snippets/code/qlogging/qlogging.cpp b/src/corelib/doc/snippets/code/qlogging/qlogging.cpp new file mode 100644 index 0000000000..74892cdfba --- /dev/null +++ b/src/corelib/doc/snippets/code/qlogging/qlogging.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +//! [1] + void statusChanged(QDeclarativeComponent::Status status) { + if (status == QDeclarativeComponent::Error) { + foreach (const QDeclarativeError &error, component->errors()) { + const QByteArray file = error.url().toEncoded(); + QMessageLogger(file.constData(), error.line(), 0).debug() << error.description(); + } + } + } +//! [1] diff --git a/src/corelib/doc/snippets/code/src_corelib_codecs_qtextcodec.cpp b/src/corelib/doc/snippets/code/src_corelib_codecs_qtextcodec.cpp new file mode 100644 index 0000000000..78abd5ba28 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_codecs_qtextcodec.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QByteArray encodedString = "..."; +QTextCodec *codec = QTextCodec::codecForName("KOI8-R"); +QString string = codec->toUnicode(encodedString); +//! [0] + + +//! [1] +QString string = "..."; +QTextCodec *codec = QTextCodec::codecForName("KOI8-R"); +QByteArray encodedString = codec->fromUnicode(string); +//! [1] + + +//! [2] +QTextCodec *codec = QTextCodec::codecForName("Shift-JIS"); +QTextDecoder *decoder = codec->makeDecoder(); + +QString string; +while (new_data_available()) { + QByteArray chunk = get_new_data(); + string += decoder->toUnicode(chunk); +} +delete decoder; +//! [2] + + +//! [3] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QTextCodec::setCodecForTr(QTextCodec::codecForName("eucKR")); + ... +} +//! [3] diff --git a/src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp b/src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp new file mode 100644 index 0000000000..a8f9da3a7c --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class HelloWorldTask : public QRunnable +{ + void run() + { + qDebug() << "Hello world from thread" << QThread::currentThread(); + } +} + +HelloWorldTask *hello = new HelloWorldTask(); +// QThreadPool takes ownership and deletes 'hello' automatically +QThreadPool::globalInstance()->start(hello); +//! [0] diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp new file mode 100644 index 0000000000..16f6783a52 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp @@ -0,0 +1,585 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +label->setAlignment(Qt::AlignLeft | Qt::AlignTop); +//! [0] + + +//! [1] +class MyClass +{ +public: + enum Option { + NoOptions = 0x0, + ShowTabs = 0x1, + ShowAll = 0x2, + SqueezeBlank = 0x4 + }; + Q_DECLARE_FLAGS(Options, Option) + ... +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::Options) +//! [1] + +//! [meta-object flags] +Q_FLAGS(Options) +//! [meta-object flags] + +//! [2] +typedef QFlags Flags; +//! [2] + + +//! [3] +int myValue = 10; +int minValue = 2; +int maxValue = 6; + +int boundedValue = qBound(minValue, myValue, maxValue); +// boundedValue == 6 +//! [3] + + +//! [4] +if (!driver()->isOpen() || driver()->isOpenError()) { + qWarning("QSqlQuery::exec: database not open"); + return false; +} +//! [4] + + +//! [5] +qint64 value = Q_INT64_C(932838457459459); +//! [5] + + +//! [6] +quint64 value = Q_UINT64_C(932838457459459); +//! [6] + + +//! [7] +void myMsgHandler(QtMsgType, const char *); +//! [7] + + +//! [8] +qint64 value = Q_INT64_C(932838457459459); +//! [8] + + +//! [9] +quint64 value = Q_UINT64_C(932838457459459); +//! [9] + + +//! [10] +int absoluteValue; +int myValue = -4; + +absoluteValue = qAbs(myValue); +// absoluteValue == 4 +//! [10] + + +//! [11] +qreal valueA = 2.3; +qreal valueB = 2.7; + +int roundedValueA = qRound(valueA); +// roundedValueA = 2 +int roundedValueB = qRound(valueB); +// roundedValueB = 3 +//! [11] + + +//! [12] +qreal valueA = 42949672960.3; +qreal valueB = 42949672960.7; + +int roundedValueA = qRound(valueA); +// roundedValueA = 42949672960 +int roundedValueB = qRound(valueB); +// roundedValueB = 42949672961 +//! [12] + + +//! [13] +int myValue = 6; +int yourValue = 4; + +int minValue = qMin(myValue, yourValue); +// minValue == yourValue +//! [13] + + +//! [14] +int myValue = 6; +int yourValue = 4; + +int maxValue = qMax(myValue, yourValue); +// maxValue == myValue +//! [14] + + +//! [15] +int myValue = 10; +int minValue = 2; +int maxValue = 6; + +int boundedValue = qBound(minValue, myValue, maxValue); +// boundedValue == 6 +//! [15] + + +//! [16] +#if QT_VERSION >= 0x040100 + QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon); +#else + QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon); + QIcon icon(pixmap); +#endif +//! [16] + + +//! [17] +// File: div.cpp + +#include + +int divide(int a, int b) +{ + Q_ASSERT(b != 0); + return a / b; +} +//! [17] + + +//! [18] +ASSERT: "b == 0" in file div.cpp, line 7 +//! [18] + + +//! [19] +// File: div.cpp + +#include + +int divide(int a, int b) +{ + Q_ASSERT_X(b != 0, "divide", "division by zero"); + return a / b; +} +//! [19] + + +//! [20] +ASSERT failure in divide: "division by zero", file div.cpp, line 7 +//! [20] + + +//! [21] +int *a; + +Q_CHECK_PTR(a = new int[80]); // WRONG! + +a = new (nothrow) int[80]; // Right +Q_CHECK_PTR(a); +//! [21] + + +//! [22] +template +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; +} +//! [22] + + +//! [23] +#include +#include +#include + +void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const char *msg) +{ + switch (type) { + case QtDebugMsg: + fprintf(stderr, "Debug: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + break; + case QtWarningMsg: + fprintf(stderr, "Warning: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + break; + case QtCriticalMsg: + fprintf(stderr, "Critical: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + break; + case QtFatalMsg: + fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + abort(); + } +} + +int main(int argc, char **argv) +{ + qInstallMessageHandler(myMessageOutput); + QApplication app(argc, argv); + ... + return app.exec(); +} +//! [23] + + +//! [24] +qDebug("Items in list: %d", myList.size()); +//! [24] + + +//! [25] +qDebug() << "Brush:" << myQBrush << "Other value:" << i; +//! [25] + + +//! [26] +void f(int c) +{ + if (c > 200) + qWarning("f: bad argument, c == %d", c); +} +//! [26] + + +//! [27] +qWarning() << "Brush:" << myQBrush << "Other value:" +<< i; +//! [27] + + +//! [28] +void load(const QString &fileName) +{ + QFile file(fileName); + if (!file.exists()) + qCritical("File '%s' does not exist!", qPrintable(fileName)); +} +//! [28] + + +//! [29] +qCritical() << "Brush:" << myQBrush << "Other +value:" << i; +//! [29] + + +//! [30] +int divide(int a, int b) +{ + if (b == 0) // program error + qFatal("divide: cannot divide by zero"); + return a / b; +} +//! [30] + + +//! [31] +forever { + ... +} +//! [31] + + +//! [32] +CONFIG += no_keywords +//! [32] + + +//! [33] +CONFIG += no_keywords +//! [33] + + +//! [34] +QString FriendlyConversation::greeting(int type) +{ +static const char *greeting_strings[] = { + QT_TR_NOOP("Hello"), + QT_TR_NOOP("Goodbye") +}; +return tr(greeting_strings[type]); +} +//! [34] + + +//! [35] +static const char *greeting_strings[] = { + QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"), + QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye") +}; + +QString FriendlyConversation::greeting(int type) +{ + return tr(greeting_strings[type]); +} + +QString global_greeting(int type) +{ + return qApp->translate("FriendlyConversation", + greeting_strings[type]); +} +//! [35] + + +//! [36] + +static { const char *source; const char *comment; } greeting_strings[] = +{ + QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello", + "A really friendly hello"), + QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye", + "A really friendly goodbye") +}; + +QString FriendlyConversation::greeting(int type) +{ + return tr(greeting_strings[type].source, + greeting_strings[type].comment); +} + +QString global_greeting(int type) +{ + return qApp->translate("FriendlyConversation", + greeting_strings[type].source, + greeting_strings[type].comment); +} +//! [36] + + +//! [qttrid] + //% "%n fooish bar(s) found.\n" + //% "Do you want to continue?" + QString text = qtTrId("qtn_foo_bar", n); +//! [qttrid] + + +//! [qttrid_noop] +static const char * const ids[] = { + //% "This is the first text." + QT_TRID_NOOP("qtn_1st_text"), + //% "This is the second text." + QT_TRID_NOOP("qtn_2nd_text"), + 0 +}; + +void TheClass::addLabels() +{ + for (int i = 0; ids[i]; ++i) + new QLabel(qtTrId(ids[i]), this); +} +//! [qttrid_noop] + + +//! [37] +qWarning("%s: %s", qPrintable(key), qPrintable(value)); +//! [37] + + +//! [38] +struct Point2D +{ + int x; + int y; +}; + +Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE); +//! [38] + + +//! [39] +class Point2D +{ +public: + Point2D() { data = new int[2]; } + Point2D(const Point2D &other) { ... } + ~Point2D() { delete[] data; } + + Point2D &operator=(const Point2D &other) { ... } + + int x() const { return data[0]; } + int y() const { return data[1]; } + +private: + int *data; +}; + +Q_DECLARE_TYPEINFO(Point2D, Q_MOVABLE_TYPE); +//! [39] + + +//! [40] +#if Q_BYTE_ORDER == Q_BIG_ENDIAN +... +#endif + +or + +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN +... +#endif + +//! [40] + + +//! [41] + +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN +... +#endif + +//! [41] + + +//! [42] +#if Q_BYTE_ORDER == Q_BIG_ENDIAN +... +#endif + +//! [42] + +//! [begin namespace macro] +namespace QT_NAMESPACE { +//! [begin namespace macro] + +//! [end namespace macro] +} +//! [end namespace macro] + +//! [43] +class MyClass : public QObject +{ + + private: + Q_DISABLE_COPY(MyClass) +}; + +//! [43] + +//! [44] +class MyClass : public QObject +{ + + private: + MyClass(const MyClass &); + MyClass &operator=(const MyClass &); +}; +//! [44] + +//! [45] + QWidget w = QWidget(); +//! [45] + +//! [46] + // Instead of comparing with 0.0 + qFuzzyCompare(0.0,1.0e-200); // This will return false + // Compare adding 1 to both values will fix the problem + qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true +//! [46] + +//! [47] +CApaApplication *myApplicationFactory(); +//! [47] + + +//! [49] +void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *); +//! [49] + +//! [qlikely] + // the condition inside the "if" will be successful most of the times + for (int i = 1; i <= 365; i++) { + if (Q_LIKELY(isWorkingDay(i))) { + ... + } + ... + } +//! [qlikely] + +//! [qunlikely] +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; +} +//! [qunlikely] + +//! [qunreachable-enum] + enum Shapes { + Rectangle, + Triangle, + Circle, + NumShapes + }; +//! [qunreachable-enum] + +//! [qunreachable-switch] + switch (shape) { + case Rectangle: + return rectangle(); + case Triangle: + return triangle(); + case Circle: + return circle(); + case NumShapes: + Q_UNREACHABLE(); + break; + } +//! [qunreachable-switch] diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp new file mode 100644 index 0000000000..8893fbd08c --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class ZipEngineHandler : public QAbstractFileEngineHandler +{ +public: + QAbstractFileEngine *create(const QString &fileName) const; +}; + +QAbstractFileEngine *ZipEngineHandler::create(const QString &fileName) const +{ + // ZipEngineHandler returns a ZipEngine for all .zip files + return fileName.toLower().endsWith(".zip") ? new ZipEngine(fileName) : 0; +} + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + ZipEngineHandler engine; + + MainWindow window; + window.show(); + + return app.exec(); +} +//! [0] + + +//! [1] +QAbstractSocketEngine *ZipEngineHandler::create(const QString &fileName) const +{ + // ZipEngineHandler returns a ZipEngine for all .zip files + return fileName.toLower().endsWith(".zip") ? new ZipEngine(fileName) : 0; +} +//! [1] + + +//! [2] +QAbstractFileEngineIterator * +CustomFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) +{ + return new CustomFileEngineIterator(filters, filterNames); +} +//! [2] + + +//! [3] +class CustomIterator : public QAbstractFileEngineIterator +{ +public: + CustomIterator(const QStringList &nameFilters, QDir::Filters filters) + : QAbstractFileEngineIterator(nameFilters, filters), index(0) + { + // In a real iterator, these entries are fetched from the + // file system based on the value of path(). + entries << "entry1" << "entry2" << "entry3"; + } + + bool hasNext() const + { + return index < entries.size() - 1; + } + + QString next() + { + if (!hasNext()) + return QString(); + ++index; + return currentFilePath(); + } + + QString currentFileName() + { + return entries.at(index); + } + +private: + QStringList entries; + int index; +}; +//! [3] diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qdatastream.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qdatastream.cpp new file mode 100644 index 0000000000..af2d7d24bf --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qdatastream.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +void wrapInFunction() +{ + +//! [0] +QFile file("file.dat"); +file.open(QIODevice::WriteOnly); +QDataStream out(&file); // we will serialize the data into the file +out << QString("the answer is"); // serialize a string +out << (qint32)42; // serialize an integer +//! [0] + + +//! [1] +QFile file("file.dat"); +file.open(QIODevice::ReadOnly); +QDataStream in(&file); // read the data serialized from the file +QString str; +qint32 a; +in >> str >> a; // extract "the answer is" and 42 +//! [1] + + +//! [2] +stream.setVersion(QDataStream::Qt_4_0); +//! [2] + + +//! [3] +QFile file("file.xxx"); +file.open(QIODevice::WriteOnly); +QDataStream out(&file); + +// Write a header with a "magic number" and a version +out << (quint32)0xA0B0C0D0; +out << (qint32)123; + +out.setVersion(QDataStream::Qt_4_0); + +// Write the data +out << lots_of_interesting_data; +//! [3] + + +//! [4] +QFile file("file.xxx"); +file.open(QIODevice::ReadOnly); +QDataStream in(&file); + +// Read and check the header +quint32 magic; +in >> magic; +if (magic != 0xA0B0C0D0) + return XXX_BAD_FILE_FORMAT; + +// Read the version +qint32 version; +in >> version; +if (version < 100) + return XXX_BAD_FILE_TOO_OLD; +if (version > 123) + return XXX_BAD_FILE_TOO_NEW; + +if (version <= 110) + in.setVersion(QDataStream::Qt_3_2); +else + in.setVersion(QDataStream::Qt_4_0); + +// Read the data +in >> lots_of_interesting_data; +if (version >= 120) + in >> data_new_in_XXX_version_1_2; +in >> other_interesting_data; +//! [4] + + +//! [5] +QDataStream out(file); +out.setVersion(QDataStream::Qt_4_0); +//! [5] + +} diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qdir.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qdir.cpp new file mode 100644 index 0000000000..3c333e5642 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qdir.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +void wrapInFunction() +{ + +//! [0] +QDir("/home/user/Documents") +QDir("C:/Documents and Settings") +//! [0] + + +//! [1] +QDir("images/landscape.png") +//! [1] + + +//! [2] +QDir("Documents/Letters/Applications").dirName() // "Applications" +QDir().dirName() // "." +//! [2] + + +//! [3] +QDir directory("Documents/Letters"); +QString path = directory.filePath("contents.txt"); +QString absolutePath = directory.absoluteFilePath("contents.txt"); +//! [3] + + +//! [4] +QDir dir("example"); +if (!dir.exists()) + qWarning("Cannot find the example directory"); +//! [4] + + +//! [5] +QDir dir = QDir::root(); // "/" +if (!dir.cd("tmp")) { // "/tmp" + qWarning("Cannot find the \"/tmp\" directory"); +} else { + QFile file(dir.filePath("ex1.txt")); // "/tmp/ex1.txt" + if (!file.open(QIODevice::ReadWrite)) + qWarning("Cannot create the file %s", file.name()); +} +//! [5] + + +//! [6] +QString bin = "/local/bin"; // where /local/bin is a symlink to /usr/bin +QDir binDir(bin); +QString canonicalBin = binDir.canonicalPath(); +// canonicalBin now equals "/usr/bin" + +QString ls = "/local/bin/ls"; // where ls is the executable "ls" +QDir lsDir(ls); +QString canonicalLs = lsDir.canonicalPath(); +// canonicalLS now equals "/usr/bin/ls". +//! [6] + + +//! [7] +QDir dir("/home/bob"); +QString s; + +s = dir.relativeFilePath("images/file.jpg"); // s is "images/file.jpg" +s = dir.relativeFilePath("/home/mary/file.txt"); // s is "../mary/file.txt" +//! [7] + + +//! [8] +QDir::setSearchPaths("icons", QStringList(QDir::homePath() + "/images")); +QDir::setSearchPaths("docs", QStringList(":/embeddedDocuments")); +... +QPixmap pixmap("icons:undo.png"); // will look for undo.png in QDir::homePath() + "/images" +QFile file("docs:design.odf"); // will look in the :/embeddedDocuments resource path +//! [8] + + +//! [9] +QDir dir("/tmp/root_link"); +dir = dir.canonicalPath(); +if (dir.isRoot()) + qWarning("It is a root link"); +//! [9] + + +//! [10] +// The current directory is "/usr/local" +QDir d1("/usr/local/bin"); +QDir d2("bin"); +if (d1 == d2) + qDebug("They're the same"); +//! [10] + + +//! [11] +// The current directory is "/usr/local" +QDir d1("/usr/local/bin"); +d1.setFilter(QDir::Executable); +QDir d2("bin"); +if (d1 != d2) + qDebug("They differ"); +//! [11] + + +//! [12] +C:/Documents and Settings/Username +//! [12] + + +//! [13] +Q_INIT_RESOURCE(myapp); +//! [13] + + +//! [14] +inline void initMyResource() { Q_INIT_RESOURCE(myapp); } + +namespace MyNamespace +{ + ... + + void myFunction() + { + initMyResource(); + } +} +//! [14] + + +//! [15] +Q_CLEANUP_RESOURCE(myapp); +//! [15] + +} diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qdiriterator.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qdiriterator.cpp new file mode 100644 index 0000000000..bf38bb1627 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qdiriterator.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QDirIterator it("/etc", QDirIterator::Subdirectories); +while (it.hasNext()) { + qDebug() << it.next(); + + // /etc/. + // /etc/.. + // /etc/X11 + // /etc/X11/fs + // ... +} +//! [0] diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp new file mode 100644 index 0000000000..7ad24b30f1 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QFile file; +QDir::setCurrent("/tmp"); +file.setFileName("readme.txt"); +QDir::setCurrent("/home"); +file.open(QIODevice::ReadOnly); // opens "/home/readme.txt" under Unix +//! [0] + + +//! [1] +QByteArray myEncoderFunc(const QString &fileName); +//! [1] + + +//! [2] +QString myDecoderFunc(const QByteArray &localFileName); +//! [2] + + +//! [3] +#include + +void printError(const char* msg) +{ + QFile file; + file.open(stderr, QIODevice::WriteOnly); + file.write(msg, qstrlen(msg)); // write to stderr + file.close(); +} +//! [3] + + +//! [4] +CONFIG += console +//! [4] diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp new file mode 100644 index 0000000000..f565786934 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +//![newstuff] + QFileInfo fi("c:/temp/foo"); => fi.absoluteFilePath() => "C:/temp/foo" +//![newstuff] + +//! [0] +#ifdef Q_OS_UNIX + +QFileInfo info1("/home/bob/bin/untabify"); +info1.isSymLink(); // returns true +info1.absoluteFilePath(); // returns "/home/bob/bin/untabify" +info1.size(); // returns 56201 +info1.symLinkTarget(); // returns "/opt/pretty++/bin/untabify" + +QFileInfo info2(info1.symLinkTarget()); +info2.isSymLink(); // returns false +info2.absoluteFilePath(); // returns "/opt/pretty++/bin/untabify" +info2.size(); // returns 56201 + +#endif +//! [0] + + +//! [1] +#ifdef Q_OS_WIN + +QFileInfo info1("C:\\Documents and Settings\\Bob\\untabify.lnk"); +info1.isSymLink(); // returns true +info1.absoluteFilePath(); // returns "C:/Documents and Settings/Bob/untabify.lnk" +info1.size(); // returns 743 +info1.symLinkTarget(); // returns "C:/Pretty++/untabify" + +QFileInfo info2(info1.symLinkTarget()); +info2.isSymLink(); // returns false +info2.absoluteFilePath(); // returns "C:/Pretty++/untabify" +info2.size(); // returns 63942 + +#endif +//! [1] + + +//! [2] +QString absolute = "/local/bin"; +QString relative = "local/bin"; +QFileInfo absFile(absolute); +QFileInfo relFile(relative); + +QDir::setCurrent(QDir::rootPath()); +// absFile and relFile now point to the same file + +QDir::setCurrent("/tmp"); +// absFile now points to "/local/bin", +// while relFile points to "/tmp/local/bin" +//! [2] + + +//! [3] +QFileInfo fi("/tmp/archive.tar.gz"); +QString name = fi.fileName(); // name = "archive.tar.gz" +//! [3] + + +//! [4] +QFileInfo fi("/Applications/Safari.app"); +QString bundle = fi.bundleName(); // name = "Safari" +//! [4] + + +//! [5] +QFileInfo fi("/tmp/archive.tar.gz"); +QString base = fi.baseName(); // base = "archive" +//! [5] + + +//! [6] +QFileInfo fi("/tmp/archive.tar.gz"); +QString base = fi.completeBaseName(); // base = "archive.tar" +//! [6] + + +//! [7] +QFileInfo fi("/tmp/archive.tar.gz"); +QString ext = fi.completeSuffix(); // ext = "tar.gz" +//! [7] + + +//! [8] +QFileInfo fi("/tmp/archive.tar.gz"); +QString ext = fi.suffix(); // ext = "gz" +//! [8] + + +//! [9] +QFileInfo info(fileName); +if (info.isSymLink()) + fileName = info.symLinkTarget(); +//! [9] + + +//! [10] +QFileInfo fi("/tmp/archive.tar.gz"); +if (fi.permission(QFile::WriteUser | QFile::ReadGroup)) + qWarning("I can change the file; my group can read the file"); +if (fi.permission(QFile::WriteGroup | QFile::WriteOther)) + qWarning("The group or others can change the file"); +//! [10] diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qiodevice.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qiodevice.cpp new file mode 100644 index 0000000000..6018a21f89 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qiodevice.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QProcess gzip; +gzip.start("gzip", QStringList() << "-c"); +if (!gzip.waitForStarted()) + return false; + +gzip.write("uncompressed data"); + +QByteArray compressed; +while (gzip.waitForReadyRead()) + compressed += gzip.readAll(); +//! [0] + + +//! [1] +qint64 CustomDevice::bytesAvailable() const +{ + return buffer.size() + QIODevice::bytesAvailable(); +} +//! [1] + + +//! [2] +QFile file("box.txt"); +if (file.open(QFile::ReadOnly)) { + char buf[1024]; + qint64 lineLength = file.readLine(buf, sizeof(buf)); + if (lineLength != -1) { + // the line is available in buf + } +} +//! [2] + + +//! [3] +bool CustomDevice::canReadLine() const +{ + return buffer.contains('\n') || QIODevice::canReadLine(); +} +//! [3] + + +//! [4] +bool isExeFile(QFile *file) +{ + char buf[2]; + if (file->peek(buf, sizeof(buf)) == sizeof(buf)) + return (buf[0] == 'M' && buf[1] == 'Z'); + return false; +} +//! [4] + + +//! [5] +bool isExeFile(QFile *file) +{ + return file->peek(2) == "MZ"; +} +//! [5] diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qprocess.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qprocess.cpp new file mode 100644 index 0000000000..16878f41e1 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qprocess.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +void wrapInFunction() +{ + +//! [0] +QProcess builder; +builder.setProcessChannelMode(QProcess::MergedChannels); +builder.start("make", QStringList() << "-j2"); + +if (!builder.waitForFinished()) + qDebug() << "Make failed:" << builder.errorString(); +else + qDebug() << "Make output:" << builder.readAll(); +//! [0] + + +//! [1] +QProcess more; +more.start("more"); +more.write("Text to display"); +more.closeWriteChannel(); +// QProcess will emit readyRead() once "more" starts printing +//! [1] + + +//! [2] +command1 | command2 +//! [2] + + +//! [3] +QProcess process1; +QProcess process2; + +process1.setStandardOutputProcess(&process2); + +process1.start("command1"); +process2.start("command2"); +//! [3] + + +//! [4] +class SandboxProcess : public QProcess +{ + ... + protected: + void setupChildProcess(); + ... +}; + +void SandboxProcess::setupChildProcess() +{ + // Drop all privileges in the child process, and enter + // a chroot jail. +#if defined Q_OS_UNIX + ::setgroups(0, 0); + ::chroot("/etc/safe"); + ::chdir("/"); + ::setgid(safeGid); + ::setuid(safeUid); + ::umask(0); +#endif +} + +//! [4] + + +//! [5] +QProcess process; +process.start("del /s *.txt"); +// same as process.start("del", QStringList() << "/s" << "*.txt"); +... +//! [5] + + +//! [6] +QProcess process; +process.start("dir \"My Documents\""); +//! [6] + + +//! [7] +QProcess process; +process.start("dir \"\"\"My Documents\"\"\""); +//! [7] + + +//! [8] +QStringList environment = QProcess::systemEnvironment(); +// environment = {"PATH=/usr/bin:/usr/local/bin", +// "USER=greg", "HOME=/home/greg"} +//! [8] + +} diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qsettings.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qsettings.cpp new file mode 100644 index 0000000000..c9ce7561ff --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qsettings.cpp @@ -0,0 +1,316 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QSettings settings("MySoft", "Star Runner"); +QColor color = settings.value("DataPump/bgcolor").value(); +//! [0] + + +//! [1] +QSettings settings("MySoft", "Star Runner"); +QColor color = palette().background().color(); +settings.setValue("DataPump/bgcolor", color); +//! [1] + + +//! [2] +QSettings settings("/home/petra/misc/myapp.ini", + QSettings::IniFormat); +//! [2] + + +//! [3] +QSettings settings("/Users/petra/misc/myapp.plist", + QSettings::NativeFormat); +//! [3] + + +//! [4] +QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Office", + QSettings::NativeFormat); +//! [4] + + +//! [5] +settings.setValue("11.0/Outlook/Security/DontTrustInstalledFiles", 0); +//! [5] + + +//! [6] +settings.setValue("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy", "Milkyway"); +settings.setValue("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy\\Sun", "OurStar"); +settings.value("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy\\Default"); // returns "Milkyway" +//! [6] + + +//! [7] +#ifdef Q_WS_MAC + QSettings settings("grenoullelogique.fr", "Squash"); +#else + QSettings settings("Grenoulle Logique", "Squash"); +#endif +//! [7] + + +//! [8] +pos = @Point(100 100) +//! [8] + + +//! [9] +windir = C:\Windows +//! [9] + + +//! [10] +QSettings settings("Moose Tech", "Facturo-Pro"); +//! [10] + + +//! [11] +QSettings settings("Moose Soft", "Facturo-Pro"); +//! [11] + + +//! [12] +QCoreApplication::setOrganizationName("Moose Soft"); +QCoreApplication::setApplicationName("Facturo-Pro"); +QSettings settings; +//! [12] + + +//! [13] +settings.beginGroup("mainwindow"); +settings.setValue("size", win->size()); +settings.setValue("fullScreen", win->isFullScreen()); +settings.endGroup(); + +settings.beginGroup("outputpanel"); +settings.setValue("visible", panel->isVisible()); +settings.endGroup(); +//! [13] + + +//! [14] +settings.beginGroup("alpha"); +// settings.group() == "alpha" + +settings.beginGroup("beta"); +// settings.group() == "alpha/beta" + +settings.endGroup(); +// settings.group() == "alpha" + +settings.endGroup(); +// settings.group() == "" +//! [14] + + +//! [15] +struct Login { + QString userName; + QString password; +}; +QList logins; +... + +QSettings settings; +int size = settings.beginReadArray("logins"); +for (int i = 0; i < size; ++i) { + settings.setArrayIndex(i); + Login login; + login.userName = settings.value("userName").toString(); + login.password = settings.value("password").toString(); + logins.append(login); +} +settings.endArray(); +//! [15] + + +//! [16] +struct Login { + QString userName; + QString password; +}; +QList logins; +... + +QSettings settings; +settings.beginWriteArray("logins"); +for (int i = 0; i < logins.size(); ++i) { + settings.setArrayIndex(i); + settings.setValue("userName", list.at(i).userName); + settings.setValue("password", list.at(i).password); +} +settings.endArray(); +//! [16] + + +//! [17] +QSettings settings; +settings.setValue("fridge/color", Qt::white); +settings.setValue("fridge/size", QSize(32, 96)); +settings.setValue("sofa", true); +settings.setValue("tv", false); + +QStringList keys = settings.allKeys(); +// keys: ["fridge/color", "fridge/size", "sofa", "tv"] +//! [17] + + +//! [18] +settings.beginGroup("fridge"); +keys = settings.allKeys(); +// keys: ["color", "size"] +//! [18] + + +//! [19] +QSettings settings; +settings.setValue("fridge/color", Qt::white); +settings.setValue("fridge/size", QSize(32, 96)); +settings.setValue("sofa", true); +settings.setValue("tv", false); + +QStringList keys = settings.childKeys(); +// keys: ["sofa", "tv"] +//! [19] + + +//! [20] +settings.beginGroup("fridge"); +keys = settings.childKeys(); +// keys: ["color", "size"] +//! [20] + + +//! [21] +QSettings settings; +settings.setValue("fridge/color", Qt::white); +settings.setValue("fridge/size", QSize(32, 96)); +settings.setValue("sofa", true); +settings.setValue("tv", false); + +QStringList groups = settings.childGroups(); +// groups: ["fridge"] +//! [21] + + +//! [22] +settings.beginGroup("fridge"); +groups = settings.childGroups(); +// groups: [] +//! [22] + + +//! [23] +QSettings settings; +settings.setValue("interval", 30); +settings.value("interval").toInt(); // returns 30 + +settings.setValue("interval", 6.55); +settings.value("interval").toDouble(); // returns 6.55 +//! [23] + + +//! [24] +QSettings settings; +settings.setValue("ape"); +settings.setValue("monkey", 1); +settings.setValue("monkey/sea", 2); +settings.setValue("monkey/doe", 4); + +settings.remove("monkey"); +QStringList keys = settings.allKeys(); +// keys: ["ape"] +//! [24] + + +//! [25] +QSettings settings; +settings.setValue("ape"); +settings.setValue("monkey", 1); +settings.setValue("monkey/sea", 2); +settings.setValue("monkey/doe", 4); + +settings.beginGroup("monkey"); +settings.remove(""); +settings.endGroup(); + +QStringList keys = settings.allKeys(); +// keys: ["ape"] +//! [25] + + +//! [26] +QSettings settings; +settings.setValue("animal/snake", 58); +settings.value("animal/snake", 1024).toInt(); // returns 58 +settings.value("animal/zebra", 1024).toInt(); // returns 1024 +settings.value("animal/zebra").toInt(); // returns 0 +//! [26] + + +//! [27] +bool myReadFunc(QIODevice &device, QSettings::SettingsMap &map); +//! [27] + + +//! [28] +bool myWriteFunc(QIODevice &device, const QSettings::SettingsMap &map); +//! [28] + + +//! [29] +bool readXmlFile(QIODevice &device, QSettings::SettingsMap &map); +bool writeXmlFile(QIODevice &device, const QSettings::SettingsMap &map); + +int main(int argc, char *argv[]) +{ + const QSettings::Format XmlFormat = + QSettings::registerFormat("xml", readXmlFile, writeXmlFile); + + QSettings settings(XmlFormat, QSettings::UserScope, "MySoft", + "Star Runner"); + + ... +} +//! [29] diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qtemporarydir.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qtemporarydir.cpp new file mode 100644 index 0000000000..4e855f72f0 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qtemporarydir.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +{ +//! [0] + // Within a function/method... + + QTemporaryDir dir; + if (dir.isValid()) { + // dir.path() returns the unique directory path + } + + // The QTemporaryDir destructor removes the temporary directory + // as it goes out of scope. +//! [0] +} diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qtemporaryfile.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qtemporaryfile.cpp new file mode 100644 index 0000000000..2db3aace56 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qtemporaryfile.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +{ +//! [0] + // Within a function/method... + + QTemporaryFile file; + if (file.open()) { + // file.fileName() returns the unique file name + } + + // The QTemporaryFile destructor removes the temporary file + // as it goes out of scope. +//! [0] +} diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp new file mode 100644 index 0000000000..c46cbb23d3 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QFile data("output.txt"); +if (data.open(QFile::WriteOnly | QFile::Truncate)) { + QTextStream out(&data); + out << "Result: " << qSetFieldWidth(10) << left << 3.14 << 2.7; + // writes "Result: 3.14 2.7 " +} +//! [0] + + +//! [1] +QTextStream stream(stdin); +QString line; +do { + line = stream.readLine(); +} while (!line.isNull()); +//! [1] + + +//! [2] +QTextStream in("0x50 0x20"); +int firstNumber, secondNumber; + +in >> firstNumber; // firstNumber == 80 +in >> dec >> secondNumber; // secondNumber == 0 + +char ch; +in >> ch; // ch == 'x' +//! [2] + + +//! [3] +int main(int argc, char *argv[]) +{ + // read numeric arguments (123, 0x20, 4.5...) + for (int i = 1; i < argc; ++i) { + int number; + QTextStream in(argv[i]); + in >> number; + ... + } +} +//! [3] + + +//! [4] +QString str; +QTextStream in(stdin); +in >> str; +//! [4] + + +//! [5] +QString s; +QTextStream out(&s); +out.setFieldWidth(10); +out.setFieldAlignment(QTextStream::AlignCenter); +out.setPadChar('-'); +out << "Qt" << "rocks!"; +//! [5] + + +//! [6] +----Qt------rocks!-- +//! [6] + + +//! [7] +QTextStream in(file); +QChar ch1, ch2, ch3; +in >> ch1 >> ch2 >> ch3; +//! [7] + + +//! [8] +QTextStream out(stdout); +out << "Qt rocks!" << endl; +//! [8] + + +//! [9] +stream << '\n' << flush; +//! [9] + + +//! [10] +QTextStream out(&file); +out.setCodec("UTF-8"); +//! [10] diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp new file mode 100644 index 0000000000..8fd4b8ee9f --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QUrl url("http://www.example.com/List of holidays.xml"); +// url.toEncoded() == "http://www.example.com/List%20of%20holidays.xml" +//! [0] + + +//! [1] +QUrl url = QUrl::fromEncoded("http://qt.nokia.com/List%20of%20holidays.xml"); +//! [1] + + +//! [2] +bool checkUrl(const QUrl &url) { + if (!url.isValid()) { + qDebug(QString("Invalid URL: %1").arg(url.toString())); + return false; + } + + return true; +} +//! [2] + + +//! [3] +QTcpSocket sock; +sock.connectToHost(url.host(), url.port(80)); +//! [3] + + +//! [4] +http://www.example.com/cgi-bin/drawgraph.cgi?type(pie)color(green) +//! [4] + + +//! [5] +QUrl baseUrl("http://qt.nokia.com/support"); +QUrl relativeUrl("../products/solutions"); +qDebug(baseUrl.resolved(relativeUrl).toString()); +// prints "http://qt.nokia.com/products/solutions" +//! [5] + + +//! [6] +QByteArray ba = QUrl::toPercentEncoding("{a fishy string?}", "{}", "s"); +qDebug(ba.constData()); +// prints "{a fi%73hy %73tring%3F}" +//! [6] diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp new file mode 100644 index 0000000000..eba007e947 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +bool myEventFilter(void *message); +//! [0] diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp new file mode 100644 index 0000000000..aa5b23265e --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +beginInsertRows(parent, 2, 4); +//! [0] + + +//! [1] +beginInsertRows(parent, 4, 5); +//! [1] + + +//! [2] +beginRemoveRows(parent, 2, 3); +//! [2] + + +//! [3] +beginInsertColumns(parent, 4, 6); +//! [3] + + +//! [4] +beginInsertColumns(parent, 6, 8); +//! [4] + + +//! [5] +beginRemoveColumns(parent, 4, 6); +//! [5] + + +//! [6] +beginMoveRows(sourceParent, 2, 4, destinationParent, 2); +//! [6] + + +//! [7] +beginMoveRows(sourceParent, 2, 4, destinationParent, 6); +//! [7] + + +//! [8] +beginMoveRows(parent, 2, 2, parent, 0); +//! [8] + + +//! [9] +beginMoveRows(parent, 2, 2, parent, 4); +//! [9] + +//! [10] +myData.clear(); +reset(); +//! [10] + +//! [11] +beginResetModel(); +myData.clear(); +endResetModel(); +//! [11] diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp new file mode 100644 index 0000000000..8023e6a218 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QMouseEvent event(QEvent::MouseButtonPress, pos, 0, 0, 0); +QApplication::sendEvent(mainWindow, &event); +//! [0] + + +//! [1] +QPushButton *quitButton = new QPushButton("Quit"); +connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit())); +//! [1] + + +//! [2] +foreach (const QString &path, app.libraryPaths()) + do_something(path); +//! [2] + + +//! [3] +bool myEventFilter(void *message, long *result); +//! [3] + + +//! [4] +static int *global_ptr = 0; + +static void cleanup_ptr() +{ + delete [] global_ptr; + global_ptr = 0; +} + +void init_ptr() +{ + global_ptr = new int[100]; // allocate data + qAddPostRoutine(cleanup_ptr); // delete later +} +//! [4] + + +//! [5] +class MyPrivateInitStuff : public QObject +{ +public: + static MyPrivateInitStuff *initStuff(QObject *parent) + { + if (!p) + p = new MyPrivateInitStuff(parent); + return p; + } + + ~MyPrivateInitStuff() + { + // cleanup goes here + } + +private: + MyPrivateInitStuff(QObject *parent) + : QObject(parent) + { + // initialization goes here + } + + MyPrivateInitStuff *p; +}; +//! [5] + + +//! [6] +static inline QString tr(const char *sourceText, + const char *comment = 0); +static inline QString trUtf8(const char *sourceText, + const char *comment = 0); +//! [6] + + +//! [7] +class MyMfcView : public CView +{ + Q_DECLARE_TR_FUNCTIONS(MyMfcView) + +public: + MyMfcView(); + ... +}; +//! [7] diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qmetaobject.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qmetaobject.cpp new file mode 100644 index 0000000000..7c0c2c2122 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qmetaobject.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +void wrapInFunction() +{ + +//! [0] +class MyClass : public QObject +{ + Q_OBJECT + Q_CLASSINFO("author", "Sabrina Schweinsteiger") + Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/") + +public: + ... +}; +//! [0] + + +//! [1] +QByteArray normType = QMetaObject::normalizedType(" int const *"); +// normType is now "const int*" +//! [1] + + +//! [2] +QMetaObject::invokeMethod(pushButton, "animateClick", + Qt::QueuedConnection); +//! [2] + + +//! [3] +QMetaObject::invokeMethod: Unable to handle unregistered datatype 'MyType' +//! [3] + + +//! [4] +QString retVal; +QMetaObject::invokeMethod(obj, "compute", Qt::DirectConnection, + Q_RETURN_ARG(QString, retVal), + Q_ARG(QString, "sqrt"), + Q_ARG(int, 42), + Q_ARG(double, 9.7)); +//! [4] + + +//! [5] +class MyClass +{ + Q_OBJECT + Q_CLASSINFO("author", "Sabrina Schweinsteiger") + Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/") + +public: + ... +}; +//! [5] + + +//! [propertyCount] +const QMetaObject* metaObject = obj->metaObject(); +QStringList properties; +for(int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i) + properties << QString::fromLatin1(metaObject->property(i).name()); +//! [propertyCount] + + +//! [methodCount] +const QMetaObject* metaObject = obj->metaObject(); +QStringList methods; +for(int i = metaObject->methodOffset(); i < metaObject->methodCount(); ++i) + methods << QString::fromLatin1(metaObject->method(i).methodSignature()); +//! [methodCount] + +//! [6] +int methodIndex = pushButton->metaObject()->indexOfMethod("animateClick()"); +QMetaMethod method = metaObject->method(methodIndex); +method.invoke(pushButton, Qt::QueuedConnection); +//! [6] + +//! [7] +QMetaMethod::invoke: Unable to handle unregistered datatype 'MyType' +//! [7] + +//! [8] +QString retVal; +QByteArray normalizedSignature = QMetaObject::normalizedSignature("compute(QString, int, double)"); +int methodIndex = obj->metaObject()->indexOfMethod(normalizedSignature); +QMetaMethod method = metaObject->method(methodIndex); +method.invoke(obj, + Qt::DirectConnection, + Q_RETURN_ARG(QString, retVal), + Q_ARG(QString, "sqrt"), + Q_ARG(int, 42), + Q_ARG(double, 9.7)); +//! [8] + +} diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp new file mode 100644 index 0000000000..d0a7a69884 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +struct MyStruct +{ + int i; + ... +}; + +Q_DECLARE_METATYPE(MyStruct) +//! [0] + + +//! [1] +namespace MyNamespace +{ + ... +} + +Q_DECLARE_METATYPE(MyNamespace::MyStruct) +//! [1] + + +//! [2] +MyStruct s; +QVariant var; +var.setValue(s); // copy s into the variant + +... + +// retrieve the value +MyStruct s2 = var.value(); +//! [2] + + +//! [3] +int id = QMetaType::type("MyClass"); +if (id != QMetaType::UnknownType) { + void *myClassPtr = QMetaType::create(id); + ... + QMetaType::destroy(id, myClassPtr); + myClassPtr = 0; +} +//! [3] + + +//! [4] +qRegisterMetaType("MyClass"); +//! [4] + + +//! [5] +qRegisterMetaTypeStreamOperators("MyClass"); +//! [5] + + +//! [6] +QDataStream &operator<<(QDataStream &out, const MyClass &myObj); +QDataStream &operator>>(QDataStream &in, MyClass &myObj); +//! [6] + + +//! [7] +int id = qRegisterMetaType(); +//! [7] + + +//! [8] +int id = qMetaTypeId(); // id is now QMetaType::QString +id = qMetaTypeId(); // compile error if MyStruct not declared +//! [8] + +//! [9] +typedef QString CustomString; +qRegisterMetaType("CustomString"); +//! [9] diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp new file mode 100644 index 0000000000..de683cf463 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +void MyWidget::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasUrls()) + event->acceptProposedAction(); +} + +void MyWidget::dropEvent(QDropEvent *event) +{ + if (event->mimeData()->hasUrls()) { + foreach (QUrl url, event->mimeData()->urls()) { + ... + } + } +} +//! [0] + + +//! [1] +QByteArray csvData = ...; + +QMimeData *mimeData = new QMimeData; +mimeData->setData("text/csv", csvData); +//! [1] + + +//! [2] +void MyWidget::dropEvent(QDropEvent *event) +{ + const MyMimeData *myData = + qobject_cast(event->mimeData()); + if (myData) { + // access myData's data directly (not through QMimeData's API) + } +} +//! [2] + + +//! [3] +application/x-qt-windows-mime;value="" +//! [3] + + +//! [4] +application/x-qt-windows-mime;value="FileGroupDescriptor" +application/x-qt-windows-mime;value="FileContents" +//! [4] + + +//! [5] +if (event->mimeData()->hasImage()) { + QImage image = qvariant_cast(event->mimeData()->imageData()); + ... +} +//! [5] + + +//! [6] +mimeData->setImageData(QImage("beautifulfjord.png")); +//! [6] + + +//! [7] +if (event->mimeData()->hasColor()) { + QColor color = qvariant_cast(event->mimeData()->colorData()); + ... +} +//! [7] diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp new file mode 100644 index 0000000000..5b27775322 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp @@ -0,0 +1,493 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QLineEdit *lineEdit = static_cast( + qt_find_obj_child(myWidget, "QLineEdit", "my line edit")); +if (lineEdit) + lineEdit->setText("Default"); +//! [0] + + +//! [1] +QObject *obj = new QPushButton; +obj->metaObject()->className(); // returns "QPushButton" + +QPushButton::staticMetaObject.className(); // returns "QPushButton" +//! [1] + + +//! [2] +QPushButton::staticMetaObject.className(); // returns "QPushButton" + +QObject *obj = new QPushButton; +obj->metaObject()->className(); // returns "QPushButton" +//! [2] + + +//! [3] +QObject *obj = new QTimer; // QTimer inherits QObject + +QTimer *timer = qobject_cast(obj); +// timer == (QObject *)obj + +QAbstractButton *button = qobject_cast(obj); +// button == 0 +//! [3] + + +//! [4] +QTimer *timer = new QTimer; // QTimer inherits QObject +timer->inherits("QTimer"); // returns true +timer->inherits("QObject"); // returns true +timer->inherits("QAbstractButton"); // returns false + +// QVBoxLayout inherits QObject and QLayoutItem +QVBoxLayout *layout = new QVBoxLayout; +layout->inherits("QObject"); // returns true +layout->inherits("QLayoutItem"); // returns true (even though QLayoutItem is not a QObject) +//! [4] + + +//! [5] +qDebug("MyClass::setPrecision(): (%s) invalid precision %f", + qPrintable(objectName()), newPrecision); +//! [5] + + +//! [6] +class MainWindow : public QMainWindow +{ +public: + MainWindow(); + +protected: + bool eventFilter(QObject *obj, QEvent *ev); + +private: + QTextEdit *textEdit; +}; + +MainWindow::MainWindow() +{ + textEdit = new QTextEdit; + setCentralWidget(textEdit); + + textEdit->installEventFilter(this); +} + +bool MainWindow::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == textEdit) { + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + qDebug() << "Ate key press" << keyEvent->key(); + return true; + } else { + return false; + } + } else { + // pass the event on to the parent class + return QMainWindow::eventFilter(obj, event); + } +} +//! [6] + + +//! [7] +myObject->moveToThread(QApplication::instance()->thread()); +//! [7] + + +//! [8] +class MyObject : public QObject +{ + Q_OBJECT + +public: + MyObject(QObject *parent = 0); + +protected: + void timerEvent(QTimerEvent *event); +}; + +MyObject::MyObject(QObject *parent) + : QObject(parent) +{ + startTimer(50); // 50-millisecond timer + startTimer(1000); // 1-second timer + startTimer(60000); // 1-minute timer +} + +void MyObject::timerEvent(QTimerEvent *event) +{ + qDebug() << "Timer ID:" << event->timerId(); +} +//! [8] + + +//! [9] +QList list = window()->queryList("QAbstractButton")); +foreach (QObject *obj, list) + static_cast(obj)->setEnabled(false); +//! [9] + + +//! [10] +QPushButton *button = parentWidget->findChild("button1"); +//! [10] + + +//! [11] +QListWidget *list = parentWidget->findChild(); +//! [11] + + +//! [12] +QList widgets = parentWidget.findChildren("widgetname"); +//! [12] + + +//! [13] +QList allPButtons = parentWidget.findChildren(); +//! [13] + + +//! [14] +monitoredObj->installEventFilter(filterObj); +//! [14] + + +//! [15] +class KeyPressEater : public QObject +{ + Q_OBJECT + ... + +protected: + bool eventFilter(QObject *obj, QEvent *event); +}; + +bool KeyPressEater::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + qDebug("Ate key press %d", keyEvent->key()); + return true; + } else { + // standard event processing + return QObject::eventFilter(obj, event); + } +} +//! [15] + + +//! [16] +KeyPressEater *keyPressEater = new KeyPressEater(this); +QPushButton *pushButton = new QPushButton(this); +QListView *listView = new QListView(this); + +pushButton->installEventFilter(keyPressEater); +listView->installEventFilter(keyPressEater); +//! [16] + + +//! [17] +MyWindow::MyWindow() +{ + QLabel *senderLabel = new QLabel(tr("Name:")); + QLabel *recipientLabel = new QLabel(tr("Name:", "recipient")); +//! [17] +} + + +//! [18] +int n = messages.count(); +showMessage(tr("%n message(s) saved", "", n)); +//! [18] + + +//! [19] +n == 1 ? tr("%n message saved") : tr("%n messages saved") +//! [19] + + +//! [20] +label->setText(tr("F\374r \310lise")); +//! [20] + + +//! [21] +if (receivers(SIGNAL(valueChanged(QByteArray))) > 0) { + QByteArray data; + get_the_value(&data); // expensive operation + emit valueChanged(data); +} +//! [21] + + +//! [22] +QLabel *label = new QLabel; +QScrollBar *scrollBar = new QScrollBar; +QObject::connect(scrollBar, SIGNAL(valueChanged(int)), + label, SLOT(setNum(int))); +//! [22] + + +//! [23] +// WRONG +QObject::connect(scrollBar, SIGNAL(valueChanged(int value)), + label, SLOT(setNum(int value))); +//! [23] + + +//! [24] +class MyWidget : public QWidget +{ + Q_OBJECT + +public: + MyWidget(); + +signals: + void buttonClicked(); + +private: + QPushButton *myButton; +}; + +MyWidget::MyWidget() +{ + myButton = new QPushButton(this); + connect(myButton, SIGNAL(clicked()), + this, SIGNAL(buttonClicked())); +} +//! [24] + + +//! [25] +QObject::connect: Cannot queue arguments of type 'MyType' +(Make sure 'MyType' is registered using qRegisterMetaType().) +//! [25] + + +//! [26] +disconnect(myObject, 0, 0, 0); +//! [26] + + +//! [27] +myObject->disconnect(); +//! [27] + + +//! [28] +disconnect(myObject, SIGNAL(mySignal()), 0, 0); +//! [28] + + +//! [29] +myObject->disconnect(SIGNAL(mySignal())); +//! [29] + + +//! [30] +disconnect(myObject, 0, myReceiver, 0); +//! [30] + + +//! [31] +myObject->disconnect(myReceiver); +//! [31] + + +//! [32] +if (QLatin1String(signal) == SIGNAL(valueChanged(int))) { + // signal is valueChanged(int) +} +//! [32] + + +//! [33] +void on__(); +//! [33] + + +//! [34] +void on_button1_clicked(); +//! [34] + + +//! [35] +class MyClass : public QObject +{ + Q_OBJECT + Q_CLASSINFO("Author", "Pierre Gendron") + Q_CLASSINFO("URL", "http://www.my-organization.qc.ca") + +public: + ... +}; +//! [35] + + +//! [36] +Q_PROPERTY(type name + READ getFunction + [WRITE setFunction] + [RESET resetFunction] + [NOTIFY notifySignal] + [DESIGNABLE bool] + [SCRIPTABLE bool] + [STORED bool] + [USER bool] + [CONSTANT] + [FINAL]) +//! [36] + + +//! [37] +Q_PROPERTY(QString title READ title WRITE setTitle USER true) +//! [37] + + +//! [38] +class MyClass : public QObject +{ + Q_OBJECT + Q_ENUMS(Priority) + +public: + MyClass(QObject *parent = 0); + ~MyClass(); + + enum Priority { High, Low, VeryHigh, VeryLow }; + void setPriority(Priority priority); + Priority priority() const; +}; +//! [38] + + +//! [39a] +class QLibrary : public QObject +{ + ... + Q_FLAGS(LoadHint LoadHints) + ... +//! [39a] + +//! [39b] + ... +public: + enum LoadHint { + ResolveAllSymbolsHint = 0x01, + ExportExternalSymbolsHint = 0x02, + LoadArchiveMemberHint = 0x04 + }; + Q_DECLARE_FLAGS(LoadHints, LoadHint) + ... +//! [39b] + + +//! [40] +//: This name refers to a host name. +hostNameLabel->setText(tr("Name:")); + +/*: This text refers to a C++ code example. */ +QString example = tr("Example"); +//! [40] + +//! [41] +QPushButton *button = parentWidget->findChild("button1", Qt::FindDirectChildOnly); +//! [41] + + +//! [42] +QListWidget *list = parentWidget->findChild(QString(), Qt::FindDirectChildOnly); +//! [42] + + +//! [43] +QList childButtons = parentWidget.findChildren(QString(), Qt::FindDirectChildOnly); +//! [43] + +//! [44] +QLabel *label = new QLabel; +QLineEdit *lineEdit = new QLineEdit; +QObject::connect(lineEdit, &QLineEdit::textChanged, + label, &QLabel::setText); +//! [44] + +//! [45] +void someFunction(); +QPushButton *button = new QPushButton; +QObject::connect(button, &QPushButton::clicked, someFunction); +//! [45] + +//! [46] +QByteArray page = ...; +QTcpSocket *socket = new QTcpSocket; +socket->connectToHost("qt-project.org", 80); +QObject::connect(socket, &QTcpSocket::connected, [=] () { + socket->write("GET " + page + "\r\n"); + }); +//! [46] + +//! [47] +disconnect(myObject, &MyObject::mySignal(), 0, 0); +//! [47] + +//! [48] +QObject::disconnect(lineEdit, &QLineEdit::textChanged, + label, &QLabel::setText); +//! [48] + +//! [meta data] +//: This is a comment for the translator. +//= qtn_foo_bar +//~ loc-layout_id foo_dialog +//~ loc-blank False +//~ magic-stuff This might mean something magic. +QString text = MyMagicClass::tr("Sim sala bim."); +//! [meta data] + +//! [explicit tr context] +QString text = QScrollBar::tr("Page up"); +//! [explicit tr context] diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp new file mode 100644 index 0000000000..da6e9fca8e --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QSystemSemaphore sem("market", 3, QSystemSemaphore::Create); + // resources available == 3 +sem.acquire(); // resources available == 2 +sem.acquire(); // resources available == 1 +sem.acquire(); // resources available == 0 +sem.release(); // resources available == 1 +sem.release(2); // resources available == 3 +//! [0] + + +//! [1] +QSystemSemaphore sem("market", 5, QSystemSemaphore::Create); +sem.acquire(5); // acquire all 5 resources +sem.release(5); // release the 5 resources +//! [1] + + +//! [2] +sem.release(10); // "create" 10 new resources +//! [2] diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp new file mode 100644 index 0000000000..dfdef73e75 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QTimer::singleShot(600000, &app, SLOT(quit())); + ... + return app.exec(); +} +//! [0] diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp new file mode 100644 index 0000000000..ae38c8372f --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QDataStream out(...); +QVariant v(123); // The variant now contains an int +int x = v.toInt(); // x = 123 +out << v; // Writes a type tag and an int to out +v = QVariant("hello"); // The variant now contains a QByteArray +v = QVariant(tr("hello")); // The variant now contains a QString +int y = v.toInt(); // y = 0 since v cannot be converted to an int +QString s = v.toString(); // s = tr("hello") (see QObject::tr()) +out << v; // Writes a type tag and a QString to out +... +QDataStream in(...); // (opening the previously written stream) +in >> v; // Reads an Int variant +int z = v.toInt(); // z = 123 +qDebug("Type is %s", // prints "Type is int" + v.typeName()); +v = v.toInt() + 100; // The variant now hold the value 223 +v = QVariant(QStringList()); +//! [0] + + +//! [1] +QVariant x, y(QString()), z(QString("")); +x.convert(QVariant::Int); +// x.isNull() == true +// y.isNull() == true, z.isNull() == false +//! [1] + + +//! [2] +QVariant variant; +... +QColor color = variant.value(); +//! [2] + + +//! [3] +QColor color = palette().background().color(); +QVariant variant = color; +//! [3] + + +//! [4] +QVariant v; + +v.setValue(5); +int i = v.toInt(); // i is now 5 +QString s = v.toString() // s is now "5" + +MyCustomStruct c; +v.setValue(c); + +... + +MyCustomStruct c2 = v.value(); +//! [4] + + +//! [5] +QVariant v; + +MyCustomStruct c; +if (v.canConvert()) + c = v.value(); + +v = 7; +int i = v.value(); // same as v.toInt() +QString s = v.value(); // same as v.toString(), s is now "7" +MyCustomStruct c2 = v.value(); // conversion failed, c2 is empty +//! [5] + + +//! [6] +QVariant v = 42; + +v.canConvert(); // returns true +v.canConvert(); // returns true + +MyCustomStruct s; +v.setValue(s); + +v.canConvert(); // returns false +v.canConvert(); // returns true +//! [6] + + +//! [7] +MyCustomStruct s; +return QVariant::fromValue(s); +//! [7] + + +//! [8] +QObject *object = getObjectFromSomewhere(); +QVariant data = QVariant::fromValue(object); +//! [8] diff --git a/src/corelib/doc/snippets/code/src_corelib_mimetype_qmimedatabase.cpp b/src/corelib/doc/snippets/code/src_corelib_mimetype_qmimedatabase.cpp new file mode 100644 index 0000000000..e59a96b87a --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_mimetype_qmimedatabase.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QMimeDatabase db; +QMimeType mime = db.mimeTypeForFile(fileName); +if (mime.inherits("text/plain")) { + // The file is plain text, we can display it in a QTextEdit +} +//! [0] diff --git a/src/corelib/doc/snippets/code/src_corelib_plugin_qlibrary.cpp b/src/corelib/doc/snippets/code/src_corelib_plugin_qlibrary.cpp new file mode 100644 index 0000000000..9de685a7b5 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_plugin_qlibrary.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QLibrary myLib("mylib"); +typedef void (*MyPrototype)(); +MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol"); +if (myFunction) + myFunction(); +//! [0] + + +//! [1] +typedef void (*MyPrototype)(); +MyPrototype myFunction = + (MyPrototype) QLibrary::resolve("mylib", "mysymbol"); +if (myFunction) + myFunction(); +//! [1] + + +//! [2] +typedef int (*AvgFunction)(int, int); + +AvgFunction avg = (AvgFunction) library->resolve("avg"); +if (avg) + return avg(5, 8); +else + return -1; +//! [2] + + +//! [3] +extern "C" MY_EXPORT int avg(int a, int b) +{ + return (a + b) / 2; +} +//! [3] + + +//! [4] +#ifdef Q_OS_WIN +#define MY_EXPORT __declspec(dllexport) +#else +#define MY_EXPORT +#endif +//! [4] diff --git a/src/corelib/doc/snippets/code/src_corelib_plugin_quuid.cpp b/src/corelib/doc/snippets/code/src_corelib_plugin_quuid.cpp new file mode 100644 index 0000000000..5c8f6ae091 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_plugin_quuid.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +// {67C8770B-44F1-410A-AB9A-F9B5446F13EE} +QUuid IID_MyInterface(0x67c8770b, 0x44f1, 0x410a, 0xab, 0x9a, 0xf9, 0xb5, 0x44, 0x6f, 0x13, 0xee) +//! [0] diff --git a/src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp b/src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp new file mode 100644 index 0000000000..e212470b75 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [simple state machine] +QPushButton button; + +QStateMachine machine; +QState *s1 = new QState(); +s1->assignProperty(&button, "text", "Click me"); + +QFinalState *s2 = new QFinalState(); +s1->addTransition(&button, SIGNAL(clicked()), s2); + +machine.addState(s1); +machine.addState(s2); +machine.setInitialState(s1); +machine.start(); +//! [simple state machine] diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qatomic.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qatomic.cpp new file mode 100644 index 0000000000..7e3d7dc7e4 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qatomic.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +MySharedType &MySharedType::operator=(const MySharedType &other) +{ + (void) other.data->atomicInt.ref(); + if (!data->atomicInt.deref()) { + // The last reference has been released + delete d; + } + d = other.d; + return *this; +} +//! [0] + + +//! [1] +if (currentValue == expectedValue) { + currentValue = newValue; + return true; +} +return false; +//! [1] + + +//! [2] +int originalValue = currentValue; +currentValue = newValue; +return originalValue; +//! [2] + + +//! [3] +int originalValue = currentValue; +currentValue += valueToAdd; +return originalValue; +//! [3] + + +//! [4] +if (currentValue == expectedValue) { + currentValue = newValue; + return true; +} +return false; +//! [4] + + +//! [5] +T *originalValue = currentValue; +currentValue = newValue; +return originalValue; +//! [5] + + +//! [6] +T *originalValue = currentValue; +currentValue += valueToAdd; +return originalValue; +//! [6] diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qmutex.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qmutex.cpp new file mode 100644 index 0000000000..f5fbeb8419 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qmutex.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +int number = 6; + +void method1() +{ + number *= 5; + number /= 4; +} + +void method2() +{ + number *= 3; + number /= 2; +} +//! [0] + + +//! [1] +// method1() +number *= 5; // number is now 30 +number /= 4; // number is now 7 + +// method2() +number *= 3; // number is now 21 +number /= 2; // number is now 10 +//! [1] + + +//! [2] +// Thread 1 calls method1() +number *= 5; // number is now 30 + +// Thread 2 calls method2(). +// +// Most likely Thread 1 has been put to sleep by the operating +// system to allow Thread 2 to run. +number *= 3; // number is now 90 +number /= 2; // number is now 45 + +// Thread 1 finishes executing. +number /= 4; // number is now 11, instead of 10 +//! [2] + + +//! [3] +QMutex mutex; +int number = 6; + +void method1() +{ + mutex.lock(); + number *= 5; + number /= 4; + mutex.unlock(); +} + +void method2() +{ + mutex.lock(); + number *= 3; + number /= 2; + mutex.unlock(); +} +//! [3] + + +//! [4] +int complexFunction(int flag) +{ + mutex.lock(); + + int retVal = 0; + + switch (flag) { + case 0: + case 1: + retVal = moreComplexFunction(flag); + break; + case 2: + { + int status = anotherFunction(); + if (status < 0) { + mutex.unlock(); + return -2; + } + retVal = status + flag; + } + break; + default: + if (flag > 10) { + mutex.unlock(); + return -1; + } + break; + } + + mutex.unlock(); + return retVal; +} +//! [4] + + +//! [5] +int complexFunction(int flag) +{ + QMutexLocker locker(&mutex); + + int retVal = 0; + + switch (flag) { + case 0: + case 1: + return moreComplexFunction(flag); + case 2: + { + int status = anotherFunction(); + if (status < 0) + return -2; + retVal = status + flag; + } + break; + default: + if (flag > 10) + return -1; + break; + } + + return retVal; +} +//! [5] + + +//! [6] +class SignalWaiter +{ +private: + QMutexLocker locker; + +public: + SignalWaiter(QMutex *mutex) + : locker(mutex) + { + } + + void waitForSignal() + { + ... + while (!signalled) + waitCondition.wait(locker.mutex()); + ... + } +}; +//! [6] diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qmutexpool.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qmutexpool.cpp new file mode 100644 index 0000000000..29076db91c --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qmutexpool.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class Number { +public: + Number(double n) : num (n) { } + + void setNumber(double n) { num = n; } + double number() const { return num; } + +private: + double num; +}; +//! [0] + + +//! [1] +void calcSquare(Number *num) +{ + QMutexLocker locker(mutexpool.get(num)); + num.setNumber(num.number() * num.number()); +} +//! [1] diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qreadwritelock.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qreadwritelock.cpp new file mode 100644 index 0000000000..bd42c01905 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qreadwritelock.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QReadWriteLock lock; + +void ReaderThread::run() +{ + ... + lock.lockForRead(); + read_file(); + lock.unlock(); + ... +} + +void WriterThread::run() +{ + ... + lock.lockForWrite(); + write_file(); + lock.unlock(); + ... +} +//! [0] + + +//! [1] +QReadWriteLock lock; + +QByteArray readData() +{ + QReadLocker locker(&lock); + ... + return data; +} +//! [1] + + +//! [2] +QReadWriteLock lock; + +QByteArray readData() +{ + lock.lockForRead(); + ... + lock.unlock(); + return data; +} +//! [2] + + +//! [3] +QReadWriteLock lock; + +void writeData(const QByteArray &data) +{ + QWriteLocker locker(&lock); + ... +} +//! [3] + + +//! [4] +QReadWriteLock lock; + +void writeData(const QByteArray &data) +{ + lock.lockForWrite(); + ... + lock.unlock(); +} +//! [4] diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qsemaphore.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qsemaphore.cpp new file mode 100644 index 0000000000..fd4ff98314 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qsemaphore.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QSemaphore sem(5); // sem.available() == 5 + +sem.acquire(3); // sem.available() == 2 +sem.acquire(2); // sem.available() == 0 +sem.release(5); // sem.available() == 5 +sem.release(5); // sem.available() == 10 + +sem.tryAcquire(1); // sem.available() == 9, returns true +sem.tryAcquire(250); // sem.available() == 9, returns false +//! [0] + + +//! [1] +QSemaphore sem(5); // a semaphore that guards 5 resources +sem.acquire(5); // acquire all 5 resources +sem.release(5); // release the 5 resources +sem.release(10); // "create" 10 new resources +//! [1] + + +//! [2] +QSemaphore sem(5); // sem.available() == 5 +sem.tryAcquire(250); // sem.available() == 5, returns false +sem.tryAcquire(3); // sem.available() == 2, returns true +//! [2] + + +//! [3] +QSemaphore sem(5); // sem.available() == 5 +sem.tryAcquire(250, 1000); // sem.available() == 5, waits 1000 milliseconds and returns false +sem.tryAcquire(3, 30000); // sem.available() == 2, returns true without waiting +//! [3] diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp new file mode 100644 index 0000000000..681023c91b --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class MyThread : public QThread +{ +public: + void run(); +}; + +void MyThread::run() +{ + QTcpSocket socket; + // connect QTcpSocket's signals somewhere meaningful + ... + socket.connectToHost(hostName, portNumber); + exec(); +} +//! [0] diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp new file mode 100644 index 0000000000..149cae5bf6 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +forever { + mutex.lock(); + keyPressed.wait(&mutex); + do_something(); + mutex.unlock(); +} +//! [0] + + +//! [1] +forever { + getchar(); + keyPressed.wakeAll(); +} +//! [1] + + +//! [2] +forever { + mutex.lock(); + keyPressed.wait(&mutex); + ++count; + mutex.unlock(); + + do_something(); + + mutex.lock(); + --count; + mutex.unlock(); +} +//! [2] + + +//! [3] +forever { + getchar(); + + mutex.lock(); + // Sleep until there are no busy worker threads + while (count > 0) { + mutex.unlock(); + sleep(1); + mutex.lock(); + } + keyPressed.wakeAll(); + mutex.unlock(); +} +//! [3] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qbitarray.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qbitarray.cpp new file mode 100644 index 0000000000..cfaa6ef485 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qbitarray.cpp @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QBitArray ba(200); +//! [0] + + +//! [1] +QBitArray ba; +ba.resize(3); +ba[0] = true; +ba[1] = false; +ba[2] = true; +//! [1] + + +//! [2] +QBitArray ba(3); +ba.setBit(0, true); +ba.setBit(1, false); +ba.setBit(2, true); +//! [2] + + +//! [3] +QBitArray x(5); +x.setBit(3, true); +// x: [ 0, 0, 0, 1, 0 ] + +QBitArray y(5); +y.setBit(4, true); +// y: [ 0, 0, 0, 0, 1 ] + +x |= y; +// x: [ 0, 0, 0, 1, 1 ] +//! [3] + + +//! [4] +QBitArray().isNull(); // returns true +QBitArray().isEmpty(); // returns true + +QBitArray(0).isNull(); // returns false +QBitArray(0).isEmpty(); // returns true + +QBitArray(3).isNull(); // returns false +QBitArray(3).isEmpty(); // returns false +//! [4] + + +//! [5] +QBitArray().isNull(); // returns true +QBitArray(0).isNull(); // returns false +QBitArray(3).isNull(); // returns false +//! [5] + + +//! [6] +QBitArray ba(8); +ba.fill(true); +// ba: [ 1, 1, 1, 1, 1, 1, 1, 1 ] + +ba.fill(false, 2); +// ba: [ 0, 0 ] +//! [6] + + +//! [7] +QBitArray a(3); +a[0] = false; +a[1] = true; +a[2] = a[0] ^ a[1]; +//! [7] + + +//! [8] +QBitArray a(3); +QBitArray b(2); +a[0] = 1; a[1] = 0; a[2] = 1; // a: [ 1, 0, 1 ] +b[0] = 1; b[1] = 0; // b: [ 1, 1 ] +a &= b; // a: [ 1, 0, 0 ] +//! [8] + + +//! [9] +QBitArray a(3); +QBitArray b(2); +a[0] = 1; a[1] = 0; a[2] = 1; // a: [ 1, 0, 1 ] +b[0] = 1; b[1] = 0; // b: [ 1, 1 ] +a |= b; // a: [ 1, 1, 1 ] +//! [9] + + +//! [10] +QBitArray a(3); +QBitArray b(2); +a[0] = 1; a[1] = 0; a[2] = 1; // a: [ 1, 0, 1 ] +b[0] = 1; b[1] = 0; // b: [ 1, 1 ] +a ^= b; // a: [ 0, 1, 1 ] +//! [10] + + +//! [11] +QBitArray a(3); +QBitArray b; +a[0] = 1; a[1] = 0; a[2] = 1; // a: [ 1, 0, 1 ] +b = ~a; // b: [ 0, 1, 0 ] +//! [11] + + +//! [12] +QBitArray a(3); +QBitArray b(2); +QBitArray c; +a[0] = 1; a[1] = 0; a[2] = 1; // a: [ 1, 0, 1 ] +b[0] = 1; b[1] = 0; // b: [ 1, 1 ] +c = a & b; // c: [ 1, 0, 0 ] +//! [12] + + +//! [13] +QBitArray a(3); +QBitArray b(2); +QBitArray c; +a[0] = 1; a[1] = 0; a[2] = 1; // a: [ 1, 0, 1 ] +b[0] = 1; b[1] = 0; // b: [ 1, 1 ] +c = a | b; // c: [ 1, 1, 1 ] +//! [13] + + +//! [14] +QBitArray a(3); +QBitArray b(2); +QBitArray c; +a[0] = 1; a[1] = 0; a[2] = 1; // a: [ 1, 0, 1 ] +b[0] = 1; b[1] = 0; // b: [ 1, 1 ] +c = a ^ b; // c: [ 0, 1, 1 ] +//! [14] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp new file mode 100644 index 0000000000..a232f490b2 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp @@ -0,0 +1,421 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +void wrapInFunction() +{ + +//! [0] +QByteArray ba("Hello"); +//! [0] + + +//! [1] +QByteArray ba; +ba.resize(5); +ba[0] = 0x3c; +ba[1] = 0xb8; +ba[2] = 0x64; +ba[3] = 0x18; +ba[4] = 0xca; +//! [1] + + +//! [2] +for (int i = 0; i < ba.size(); ++i) { + if (ba.at(i) >= 'a' && ba.at(i) <= 'f') + cout << "Found character in range [a-f]" << endl; +} +//! [2] + + +//! [3] +QByteArray x("and"); +x.prepend("rock "); // x == "rock and" +x.append(" roll"); // x == "rock and roll" +x.replace(5, 3, "&"); // x == "rock & roll" +//! [3] + + +//! [4] +QByteArray ba("We must be bold, very bold"); +int j = 0; +while ((j = ba.indexOf("", j)) != -1) { + cout << "Found tag at index position " << j << endl; + ++j; +} +//! [4] + + +//! [5] +QByteArray().isNull(); // returns true +QByteArray().isEmpty(); // returns true + +QByteArray("").isNull(); // returns false +QByteArray("").isEmpty(); // returns true + +QByteArray("abc").isNull(); // returns false +QByteArray("abc").isEmpty(); // returns false +//! [5] + + +//! [6] +QByteArray ba("Hello"); +int n = ba.size(); // n == 5 +ba.data()[0]; // returns 'H' +ba.data()[4]; // returns 'o' +ba.data()[5]; // returns '\0' +//! [6] + + +//! [7] +QByteArray().isEmpty(); // returns true +QByteArray("").isEmpty(); // returns true +QByteArray("abc").isEmpty(); // returns false +//! [7] + + +//! [8] +QByteArray ba("Hello world"); +char *data = ba.data(); +while (*data) { + cout << "[" << *data << "]" << endl; + ++data; +} +//! [8] + + +//! [9] +QByteArray ba; +for (int i = 0; i < 10; ++i) + ba[i] = 'A' + i; +// ba == "ABCDEFGHIJ" +//! [9] + + +//! [10] +QByteArray ba("Stockholm"); +ba.truncate(5); // ba == "Stock" +//! [10] + + +//! [11] +QByteArray ba("STARTTLS\r\n"); +ba.chop(2); // ba == "STARTTLS" +//! [11] + + +//! [12] +QByteArray x("free"); +QByteArray y("dom"); +x += y; +// x == "freedom" +//! [12] + + +//! [13] +QByteArray().isNull(); // returns true +QByteArray("").isNull(); // returns false +QByteArray("abc").isNull(); // returns false +//! [13] + + +//! [14] +QByteArray ba("Istambul"); +ba.fill('o'); +// ba == "oooooooo" + +ba.fill('X', 2); +// ba == "XX" +//! [14] + + +//! [15] +QByteArray x("ship"); +QByteArray y("air"); +x.prepend(y); +// x == "airship" +//! [15] + + +//! [16] +QByteArray x("free"); +QByteArray y("dom"); +x.append(y); +// x == "freedom" +//! [16] + + +//! [17] +QByteArray ba("Meal"); +ba.insert(1, QByteArray("ontr")); +// ba == "Montreal" +//! [17] + + +//! [18] +QByteArray ba("Montreal"); +ba.remove(1, 4); +// ba == "Meal" +//! [18] + + +//! [19] +QByteArray x("Say yes!"); +QByteArray y("no"); +x.replace(4, 3, y); +// x == "Say no!" +//! [19] + + +//! [20] +QByteArray ba("colour behaviour flavour neighbour"); +ba.replace(QByteArray("ou"), QByteArray("o")); +// ba == "color behavior flavor neighbor" +//! [20] + + +//! [21] +QByteArray x("sticky question"); +QByteArray y("sti"); +x.indexOf(y); // returns 0 +x.indexOf(y, 1); // returns 10 +x.indexOf(y, 10); // returns 10 +x.indexOf(y, 11); // returns -1 +//! [21] + + +//! [22] +QByteArray ba("ABCBA"); +ba.indexOf("B"); // returns 1 +ba.indexOf("B", 1); // returns 1 +ba.indexOf("B", 2); // returns 3 +ba.indexOf("X"); // returns -1 +//! [22] + + +//! [23] +QByteArray x("crazy azimuths"); +QByteArray y("az"); +x.lastIndexOf(y); // returns 6 +x.lastIndexOf(y, 6); // returns 6 +x.lastIndexOf(y, 5); // returns 2 +x.lastIndexOf(y, 1); // returns -1 +//! [23] + + +//! [24] +QByteArray ba("ABCBA"); +ba.lastIndexOf("B"); // returns 3 +ba.lastIndexOf("B", 3); // returns 3 +ba.lastIndexOf("B", 2); // returns 1 +ba.lastIndexOf("X"); // returns -1 +//! [24] + + +//! [25] +QByteArray url("ftp://ftp.qt.nokia.com/"); +if (url.startsWith("ftp:")) + ... +//! [25] + + +//! [26] +QByteArray url("http://qt.nokia.com/index.html"); +if (url.endsWith(".html")) + ... +//! [26] + + +//! [27] +QByteArray x("Pineapple"); +QByteArray y = x.left(4); +// y == "Pine" +//! [27] + + +//! [28] +QByteArray x("Pineapple"); +QByteArray y = x.right(5); +// y == "apple" +//! [28] + + +//! [29] +QByteArray x("Five pineapples"); +QByteArray y = x.mid(5, 4); // y == "pine" +QByteArray z = x.mid(5); // z == "pineapples" +//! [29] + + +//! [30] +QByteArray x("Qt by NOKIA"); +QByteArray y = x.toLower(); +// y == "qt by nokia" +//! [30] + + +//! [31] +QByteArray x("Qt by NOKIA"); +QByteArray y = x.toUpper(); +// y == "QT BY NOKIA" +//! [31] + + +//! [32] +QByteArray ba(" lots\t of\nwhitespace\r\n "); +ba = ba.simplified(); +// ba == "lots of whitespace"; +//! [32] + + +//! [33] +QByteArray ba(" lots\t of\nwhitespace\r\n "); +ba = ba.trimmed(); +// ba == "lots\t of\nwhitespace"; +//! [33] + + +//! [34] +QByteArray x("apple"); +QByteArray y = x.leftJustified(8, '.'); // y == "apple..." +//! [34] + + +//! [35] +QByteArray x("apple"); +QByteArray y = x.rightJustified(8, '.'); // y == "...apple" +//! [35] + + +//! [36] +QByteArray str("FF"); +bool ok; +int hex = str.toInt(&ok, 16); // hex == 255, ok == true +int dec = str.toInt(&ok, 10); // dec == 0, ok == false +//! [36] + + +//! [37] +QByteArray str("FF"); +bool ok; +long hex = str.toLong(&ok, 16); // hex == 255, ok == true +long dec = str.toLong(&ok, 10); // dec == 0, ok == false +//! [37] + + +//! [38] +QByteArray string("1234.56"); +double a = string.toDouble(); // a == 1234.56 +//! [38] + + +//! [39] +QByteArray text("Qt is great!"); +text.toBase64(); // returns "UXQgaXMgZ3JlYXQh" +//! [39] + + +//! [40] +QByteArray ba; +int n = 63; +ba.setNum(n); // ba == "63" +ba.setNum(n, 16); // ba == "3f" +//! [40] + + +//! [41] +int n = 63; +QByteArray::number(n); // returns "63" +QByteArray::number(n, 16); // returns "3f" +QByteArray::number(n, 16).toUpper(); // returns "3F" +//! [41] + + +//! [42] +QByteArray ba = QByteArray::number(12.3456, 'E', 3); +// ba == 1.235E+01 +//! [42] + + +//! [43] + static const char mydata[] = { + 0x00, 0x00, 0x03, 0x84, 0x78, 0x9c, 0x3b, 0x76, + 0xec, 0x18, 0xc3, 0x31, 0x0a, 0xf1, 0xcc, 0x99, + ... + 0x6d, 0x5b +}; + +QByteArray data = QByteArray::fromRawData(mydata, sizeof(mydata)); +QDataStream in(&data, QIODevice::ReadOnly); +... +//! [43] + + +//! [44] +QByteArray text = QByteArray::fromBase64("UXQgaXMgZ3JlYXQh"); +text.data(); // returns "Qt is great!" +//! [44] + + +//! [45] +QByteArray text = QByteArray::fromHex("517420697320677265617421"); +text.data(); // returns "Qt is great!" +//! [45] + +//! [46] +QString tmp = "test"; +QByteArray text = tmp.toLocal8Bit(); +char *data = new char[text.size()] +strcpy(data, text.data()); +delete [] data; +//! [46] + +//! [47] +QString tmp = "test"; +QByteArray text = tmp.toLocal8Bit(); +char *data = new char[text.size() + 1] +strcpy(data, text.data()); +delete [] data; +//! [47] + +} + + diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp new file mode 100644 index 0000000000..59cd67fe6d --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QDate d1(1995, 5, 17); // May 17, 1995 +QDate d2(1995, 5, 20); // May 20, 1995 +d1.daysTo(d2); // returns 3 +d2.daysTo(d1); // returns -3 +//! [0] + + +//! [1] +QDate date = QDate::fromString("1MM12car2003", "d'MM'MMcaryyyy"); +// date is 1 December 2003 +//! [1] + + +//! [2] +QDate date = QDate::fromString("130", "Md"); // invalid +//! [2] + + +//! [3] +QDate::fromString("1.30", "M.d"); // January 30 1900 +QDate::fromString("20000110", "yyyyMMdd"); // January 10, 2000 +QDate::fromString("20000110", "yyyyMd"); // January 10, 2000 +//! [3] + + +//! [4] +QDate::isValid(2002, 5, 17); // true +QDate::isValid(2002, 2, 30); // false (Feb 30 does not exist) +QDate::isValid(2004, 2, 29); // true (2004 is a leap year) +QDate::isValid(2000, 2, 29); // true (2000 is a leap year) +QDate::isValid(2006, 2, 29); // false (2006 is not a leap year) +QDate::isValid(2100, 2, 29); // false (2100 is not a leap year) +QDate::isValid(1202, 6, 6); // true (even though 1202 is pre-Gregorian) +//! [4] + + +//! [5] +QTime n(14, 0, 0); // n == 14:00:00 +QTime t; +t = n.addSecs(70); // t == 14:01:10 +t = n.addSecs(-70); // t == 13:58:50 +t = n.addSecs(10 * 60 * 60 + 5); // t == 00:00:05 +t = n.addSecs(-15 * 60 * 60); // t == 23:00:00 +//! [5] + + +//! [6] +QTime time = QTime::fromString("1mm12car00", "m'mm'hcarss"); +// time is 12:01.00 +//! [6] + + +//! [7] +QTime time = QTime::fromString("00:710", "hh:ms"); // invalid +//! [7] + + +//! [8] +QTime time = QTime::fromString("1.30", "m.s"); +// time is 00:01:30.000 +//! [8] + + +//! [9] +QTime::isValid(21, 10, 30); // returns true +QTime::isValid(22, 5, 62); // returns false +//! [9] + + +//! [10] +QTime t; +t.start(); +some_lengthy_task(); +qDebug("Time elapsed: %d ms", t.elapsed()); +//! [10] + + +//! [11] +QDateTime now = QDateTime::currentDateTime(); +QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0)); +qDebug("There are %d seconds to Christmas", now.secsTo(xmas)); +//! [11] + + +//! [12] +QTime time1 = QTime::fromString("131", "HHh"); +// time1 is 13:00:00 +QTime time1 = QTime::fromString("1apA", "1amAM"); +// time1 is 01:00:00 + +QDateTime dateTime2 = QDateTime::fromString("M1d1y9800:01:02", + "'M'M'd'd'y'yyhh:mm:ss"); +// dateTime is 1 January 1998 00:01:02 +//! [12] + + +//! [13] +QDateTime dateTime = QDateTime::fromString("130", "Mm"); // invalid +//! [13] + + +//! [14] +QDateTime dateTime = QDateTime::fromString("1.30.1", "M.d.s"); +// dateTime is January 30 in 1900 at 00:00:01. +//! [14] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qeasingcurve.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qeasingcurve.cpp new file mode 100644 index 0000000000..3aa0d986af --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qeasingcurve.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +qreal myEasingFunction(qreal progress); +//! [0] + diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp new file mode 100644 index 0000000000..2fa73bac46 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp @@ -0,0 +1,299 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QHash hash; +//! [0] + + +//! [1] +hash["one"] = 1; +hash["three"] = 3; +hash["seven"] = 7; +//! [1] + + +//! [2] +hash.insert("twelve", 12); +//! [2] + + +//! [3] +int num1 = hash["thirteen"]; +int num2 = hash.value("thirteen"); +//! [3] + + +//! [4] +int timeout = 30; +if (hash.contains("TIMEOUT")) + timeout = hash.value("TIMEOUT"); +//! [4] + + +//! [5] +int timeout = hash.value("TIMEOUT", 30); +//! [5] + + +//! [6] +// WRONG +QHash hash; +... +for (int i = 0; i < 1000; ++i) { + if (hash[i] == okButton) + cout << "Found button at index " << i << endl; +} +//! [6] + + +//! [7] +QHashIterator i(hash); +while (i.hasNext()) { + i.next(); + cout << i.key() << ": " << i.value() << endl; +} +//! [7] + + +//! [8] +QHash::const_iterator i = hash.constBegin(); +while (i != hash.constEnd()) { + cout << i.key() << ": " << i.value() << endl; + ++i; +} +//! [8] + + +//! [9] +hash.insert("plenty", 100); +hash.insert("plenty", 2000); +// hash.value("plenty") == 2000 +//! [9] + + +//! [10] +QList values = hash.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [10] + + +//! [11] +QHash::iterator i = hash.find("plenty"); +while (i != hash.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [11] + + +//! [12] +QHash hash; +... +foreach (int value, hash) + cout << value << endl; +//! [12] + + +//! [13] +#ifndef EMPLOYEE_H +#define EMPLOYEE_H + +class Employee +{ +public: + Employee() {} + Employee(const QString &name, const QDate &dateOfBirth); + ... + +private: + QString myName; + QDate myDateOfBirth; +}; + +inline bool operator==(const Employee &e1, const Employee &e2) +{ + return e1.name() == e2.name() + && e1.dateOfBirth() == e2.dateOfBirth(); +} + +inline uint qHash(const Employee &key, uint seed) +{ + return qHash(key.name(), seed) ^ key.dateOfBirth().day(); +} + +#endif // EMPLOYEE_H +//! [13] + + +//! [14] +QHash hash; +hash.reserve(20000); +for (int i = 0; i < 20000; ++i) + hash.insert(keys[i], values[i]); +//! [14] + + +//! [15] +QHash objectHash; +... +QHash::iterator i = objectHash.find(obj); +while (i != objectHash.end() && i.key() == obj) { + if (i.value() == 0) { + i = objectHash.erase(i); + } else { + ++i; + } +} +//! [15] + + +//! [16] +QHash hash; +... +QHash::const_iterator i = hash.find("HDR"); +while (i != hash.end() && i.key() == "HDR") { + cout << i.value() << endl; + ++i; +} +//! [16] + + +//! [17] +QHash hash; +hash.insert("January", 1); +hash.insert("February", 2); +... +hash.insert("December", 12); + +QHash::iterator i; +for (i = hash.begin(); i != hash.end(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [17] + + +//! [18] +QHash::iterator i; +for (i = hash.begin(); i != hash.end(); ++i) + i.value() += 2; +//! [18] + + +//! [19] +QHash::iterator i = hash.begin(); +while (i != hash.end()) { + if (i.key().startsWith("_")) + i = hash.erase(i); + else + ++i; +} +//! [19] + + +//! [20] +QHash::iterator i = hash.begin(); +while (i != hash.end()) { + QHash::iterator prev = i; + ++i; + if (prev.key().startsWith("_")) + hash.erase(prev); +} +//! [20] + + +//! [21] +// WRONG +while (i != hash.end()) { + if (i.key().startsWith("_")) + hash.erase(i); + ++i; +} +//! [21] + + +//! [22] +if (i.key() == "Hello") + i.value() = "Bonjour"; +//! [22] + + +//! [23] +QHash hash; +hash.insert("January", 1); +hash.insert("February", 2); +... +hash.insert("December", 12); + +QHash::const_iterator i; +for (i = hash.constBegin(); i != hash.constEnd(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [23] + + +//! [24] +QMultiHash hash1, hash2, hash3; + +hash1.insert("plenty", 100); +hash1.insert("plenty", 2000); +// hash1.size() == 2 + +hash2.insert("plenty", 5000); +// hash2.size() == 1 + +hash3 = hash1 + hash2; +// hash3.size() == 3 +//! [24] + + +//! [25] +QList values = hash.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [25] + + +//! [26] +QMultiHash::iterator i = hash.find("plenty"); +while (i != hash.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [26] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qlinkedlist.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qlinkedlist.cpp new file mode 100644 index 0000000000..b9861f16c0 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qlinkedlist.cpp @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QLinkedList integerList; +QLinkedList timeList; +//! [0] + + +//! [1] +QLinkedList list; +list << "one" << "two" << "three"; +// list: ["one", "two", "three"] +//! [1] + + +//! [2] +QLinkedList list; +... +while (!list.isEmpty()) + delete list.takeFirst(); +//! [2] + + +//! [3] +QLinkedList list; +list.append("one"); +list.append("two"); +list.append("three"); +// list: ["one", "two", "three"] +//! [3] + + +//! [4] +QLinkedList list; +list.prepend("one"); +list.prepend("two"); +list.prepend("three"); +// list: ["three", "two", "one"] +//! [4] + + +//! [5] +QList list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeAll("sun"); +// list: ["cloud", "rain"] +//! [5] + + +//! [6] +QList list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeOne("sun"); +// list: ["cloud", "sun", "rain"] +//! [6] + + +//! [7] +QLinkedList list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QLinkedList::iterator i; +for (i = list.begin(); i != list.end(); ++i) + cout << *i << endl; +//! [7] + + +//! [8] +QLinkedList list; +... +QLinkedList::iterator it = qFind(list.begin(), + list.end(), "Joel"); +if (it != list.end()) + cout << "Found Joel" << endl; +//! [8] + + +//! [9] +QLinkedList::iterator i; +for (i = list.begin(); i != list.end(); ++i) + *i += 2; +//! [9] + + +//! [10] +QLinkedList list; +... +QLinkedList::iterator i = list.begin(); +while (i != list.end()) { + if ((*i).startsWith("_")) + i = list.erase(i); + else + ++i; +} +//! [10] + + +//! [11] +QLinkedList::iterator i = list.begin(); +while (i != list.end()) { + QLinkedList::iterator previous = i; + ++i; + if ((*previous).startsWith("_")) + list.erase(previous); +} +//! [11] + + +//! [12] +// WRONG +while (i != list.end()) { + if ((*i).startsWith("_")) + list.erase(i); + ++i; +} +//! [12] + + +//! [13] +if (*it == "Hello") + *it = "Bonjour"; +//! [13] + + +//! [14] +QLinkedList list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QLinkedList::const_iterator i; +for (i = list.constBegin(); i != list.constEnd(); ++i) + cout << *i << endl; +//! [14] + + +//! [15] +QLinkedList list; +... +QLinkedList::iterator it = qFind(list.constBegin(), + list.constEnd(), "Joel"); +if (it != list.constEnd()) + cout << "Found Joel" << endl; +//! [15] + + +//! [16] +std::list stdlist; +list.push_back(1.2); +list.push_back(0.5); +list.push_back(3.14); + +QLinkedList list = QLinkedList::fromStdList(stdlist); +//! [16] + + +//! [17] +QLinkedList list; +list << 1.2 << 0.5 << 3.14; + +std::list stdlist = list.toStdList(); +//! [17] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qlistdata.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qlistdata.cpp new file mode 100644 index 0000000000..dca5473cd6 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qlistdata.cpp @@ -0,0 +1,267 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QList integerList; +QList dateList; +//! [0] + + +//! [1] +QList list; +list << "one" << "two" << "three"; +// list: ["one", "two", "three"] +//! [1] + + +//! [2] +if (list[0] == "Bob") + list[0] = "Robert"; +//! [2] + + +//! [3] +for (int i = 0; i < list.size(); ++i) { + if (list.at(i) == "Jane") + cout << "Found Jane at position " << i << endl; +} +//! [3] + + +//! [4] +QList list; +... +while (!list.isEmpty()) + delete list.takeFirst(); +//! [4] + + +//! [5] +int i = list.indexOf("Jane"); +if (i != -1) + cout << "First occurrence of Jane is at position " << i << endl; +//! [5] + + +//! [6] +QList list; +list.append("one"); +list.append("two"); +list.append("three"); +// list: ["one", "two", "three"] +//! [6] + + +//! [7] +QList list; +list.prepend("one"); +list.prepend("two"); +list.prepend("three"); +// list: ["three", "two", "one"] +//! [7] + + +//! [8] +QList list; +list << "alpha" << "beta" << "delta"; +list.insert(2, "gamma"); +// list: ["alpha", "beta", "gamma", "delta"] +//! [8] + + +//! [9] +QList list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeAll("sun"); +// list: ["cloud", "rain"] +//! [9] + + +//! [10] +QList list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeOne("sun"); +// list: ["cloud", ,"sun", "rain"] +//! [10] + + +//! [11] +QList list; +list << "A" << "B" << "C" << "D" << "E" << "F"; +list.move(1, 4); +// list: ["A", "C", "D", "E", "B", "F"] +//! [11] + + +//! [12] +QList list; +list << "A" << "B" << "C" << "D" << "E" << "F"; +list.swap(1, 4); +// list: ["A", "E", "C", "D", "B", "F"] +//! [12] + + +//! [13] +QList list; +list << "A" << "B" << "C" << "B" << "A"; +list.indexOf("B"); // returns 1 +list.indexOf("B", 1); // returns 1 +list.indexOf("B", 2); // returns 3 +list.indexOf("X"); // returns -1 +//! [13] + + +//! [14] +QList list; +list << "A" << "B" << "C" << "B" << "A"; +list.lastIndexOf("B"); // returns 3 +list.lastIndexOf("B", 3); // returns 3 +list.lastIndexOf("B", 2); // returns 1 +list.lastIndexOf("X"); // returns -1 +//! [14] + + +//! [15] +QList list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QList::iterator i; +for (i = list.begin(); i != list.end(); ++i) + cout << *i << endl; +//! [15] + + +//! [16] +QList::iterator i; +for (i = list.begin(); i != list.end(); ++i) + *i += 2; +//! [16] + + +//! [17] +QList list; +... +qDeleteAll(list.begin(), list.end()); +//! [17] + + +//! [18] +if (*it == "Hello") + *it = "Bonjour"; +//! [18] + + +//! [19] +QList list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QList::const_iterator i; +for (i = list.constBegin(); i != list.constEnd(); ++i) + cout << *i << endl; +//! [19] + + +//! [20] +QList list; +... +qDeleteAll(list.constBegin(), list.constEnd()); +//! [20] + + +//! [21] +QVector vect; +vect << 20.0 << 30.0 << 40.0 << 50.0; + +QList list = QVector::fromVector(vect); +// list: [20.0, 30.0, 40.0, 50.0] +//! [21] + + +//! [22] +QStringList list; +list << "Sven" << "Kim" << "Ola"; + +QVector vect = list.toVector(); +// vect: ["Sven", "Kim", "Ola"] +//! [22] + + +//! [23] +QSet set; +set << 20 << 30 << 40 << ... << 70; + +QList list = QList::fromSet(set); +qSort(list); +//! [23] + + +//! [24] +QStringList list; +list << "Julia" << "Mike" << "Mike" << "Julia" << "Julia"; + +QSet set = list.toSet(); +set.contains("Julia"); // returns true +set.contains("Mike"); // returns true +set.size(); // returns 2 +//! [24] + + +//! [25] +std::list stdlist; +list.push_back(1.2); +list.push_back(0.5); +list.push_back(3.14); + +QList list = QList::fromStdList(stdlist); +//! [25] + + +//! [26] +QList list; +list << 1.2 << 0.5 << 3.14; + +std::list stdlist = list.toStdList(); +//! [26] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp new file mode 100644 index 0000000000..2e3b599910 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QLocale egyptian(QLocale::Arabic, QLocale::Egypt); +QString s1 = egyptian.toString(1.571429E+07, 'e'); +QString s2 = egyptian.toString(10); + +double d = egyptian.toDouble(s1); +int i = egyptian.toInt(s2); +//! [0] + + +//! [1] +QLocale::setDefault(QLocale(QLocale::Hebrew, QLocale::Israel)); +QLocale hebrew; // Constructs a default QLocale +QString s1 = hebrew.toString(15714.3, 'e'); + +bool ok; +double d; + +QLocale::setDefault(QLocale::C); +d = QString("1234,56").toDouble(&ok); // ok == false +d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 + +QLocale::setDefault(QLocale::German); +d = QString("1234,56").toDouble(&ok); // ok == true, d == 1234.56 +d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 + +QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); +str = QString("%1 %L2 %L3") + .arg(12345).arg(12345).arg(12345, 0, 16); +// str == "12345 12,345 3039" +//! [1] + + +//! [2] +QLocale korean("ko"); +QLocale swiss("de_CH"); +//! [2] + + +//! [3] +bool ok; +double d; + +QLocale c(QLocale::C); +d = c.toDouble( "1234.56", &ok ); // ok == true, d == 1234.56 +d = c.toDouble( "1,234.56", &ok ); // ok == true, d == 1234.56 +d = c.toDouble( "1234,56", &ok ); // ok == false + +QLocale german(QLocale::German); +d = german.toDouble( "1234,56", &ok ); // ok == true, d == 1234.56 +d = german.toDouble( "1.234,56", &ok ); // ok == true, d == 1234.56 +d = german.toDouble( "1234.56", &ok ); // ok == false + +d = german.toDouble( "1.234", &ok ); // ok == true, d == 1234.0 +//! [3] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp new file mode 100644 index 0000000000..2b9c1fb73e --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp @@ -0,0 +1,313 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QMap map; +//! [0] + + +//! [1] +map["one"] = 1; +map["three"] = 3; +map["seven"] = 7; +//! [1] + + +//! [2] +map.insert("twelve", 12); +//! [2] + + +//! [3] +int num1 = map["thirteen"]; +int num2 = map.value("thirteen"); +//! [3] + + +//! [4] +int timeout = 30; +if (map.contains("TIMEOUT")) + timeout = map.value("TIMEOUT"); +//! [4] + + +//! [5] +int timeout = map.value("TIMEOUT", 30); +//! [5] + + +//! [6] +// WRONG +QMap map; +... +for (int i = 0; i < 1000; ++i) { + if (map[i] == okButton) + cout << "Found button at index " << i << endl; +} +//! [6] + + +//! [7] +QMapIterator i(map); +while (i.hasNext()) { + i.next(); + cout << i.key() << ": " << i.value() << endl; +} +//! [7] + + +//! [8] +QMap::const_iterator i = map.constBegin(); +while (i != map.constEnd()) { + cout << i.key() << ": " << i.value() << endl; + ++i; +} +//! [8] + + +//! [9] +map.insert("plenty", 100); +map.insert("plenty", 2000); +// map.value("plenty") == 2000 +//! [9] + + +//! [10] +QList values = map.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [10] + + +//! [11] +QMap::iterator i = map.find("plenty"); +while (i != map.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [11] + + +//! [12] +QMap map; +... +foreach (int value, map) + cout << value << endl; +//! [12] + + +//! [13] +#ifndef EMPLOYEE_H +#define EMPLOYEE_H + +class Employee +{ +public: + Employee() {} + Employee(const QString &name, const QDate &dateOfBirth); + ... + +private: + QString myName; + QDate myDateOfBirth; +}; + +inline bool operator<(const Employee &e1, const Employee &e2) +{ + if (e1.name() != e2.name()) + return e1.name() < e2.name(); + return e1.dateOfBirth() < e2.dateOfBirth(); +} + +#endif // EMPLOYEE_H +//! [13] + + +//! [14] +QMap map; +... +QMap::const_iterator i = map.find("HDR"); +while (i != map.end() && i.key() == "HDR") { + cout << i.value() << endl; + ++i; +} +//! [14] + + +//! [15] +QMap map; +map.insert(1, "one"); +map.insert(5, "five"); +map.insert(10, "ten"); + +map.lowerBound(0); // returns iterator to (1, "one") +map.lowerBound(1); // returns iterator to (1, "one") +map.lowerBound(2); // returns iterator to (5, "five") +map.lowerBound(10); // returns iterator to (10, "ten") +map.lowerBound(999); // returns end() +//! [15] + + +//! [16] +QMap map; +... +QMap::const_iterator i = map.lowerBound("HDR"); +QMap::const_iterator upperBound = map.upperBound("HDR"); +while (i != upperBound) { + cout << i.value() << endl; + ++i; +} +//! [16] + + +//! [17] +QMap map; +map.insert(1, "one"); +map.insert(5, "five"); +map.insert(10, "ten"); + +map.upperBound(0); // returns iterator to (1, "one") +map.upperBound(1); // returns iterator to (5, "five") +map.upperBound(2); // returns iterator to (5, "five") +map.upperBound(10); // returns end() +map.upperBound(999); // returns end() +//! [17] + + +//! [18] +QMap map; +map.insert("January", 1); +map.insert("February", 2); +... +map.insert("December", 12); + +QMap::iterator i; +for (i = map.begin(); i != map.end(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [18] + + +//! [19] +QMap::iterator i; +for (i = map.begin(); i != map.end(); ++i) + i.value() += 2; +//! [19] + + +//! [20] +QMap::iterator i = map.begin(); +while (i != map.end()) { + if (i.key().startsWith("_")) + i = map.erase(i); + else + ++i; +} +//! [20] + + +//! [21] +QMap::iterator i = map.begin(); +while (i != map.end()) { + QMap::iterator prev = i; + ++i; + if (prev.key().startsWith("_")) + map.erase(prev); +} +//! [21] + + +//! [22] +// WRONG +while (i != map.end()) { + if (i.key().startsWith("_")) + map.erase(i); + ++i; +} +//! [22] + + +//! [23] +if (i.key() == "Hello") + i.value() = "Bonjour"; +//! [23] + + +//! [24] +QMap map; +map.insert("January", 1); +map.insert("February", 2); +... +map.insert("December", 12); + +QMap::const_iterator i; +for (i = map.constBegin(); i != map.constEnd(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [24] + + +//! [25] +QMultiMap map1, map2, map3; + +map1.insert("plenty", 100); +map1.insert("plenty", 2000); +// map1.size() == 2 + +map2.insert("plenty", 5000); +// map2.size() == 1 + +map3 = map1 + map2; +// map3.size() == 3 +//! [25] + + +//! [26] +QList values = map.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [26] + + +//! [27] +QMultiMap::iterator i = map.find("plenty"); +while (i != map.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [27] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp new file mode 100644 index 0000000000..4f48fcbcb1 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QPoint p; + +p.setX(p.x() + 1); +p += QPoint(1, 0); +p.rx()++; +//! [0] + + +//! [1] +QPoint p(1, 2); +p.rx()--; // p becomes (0, 2) +//! [1] + + +//! [2] +QPoint p(1, 2); +p.ry()++; // p becomes (1, 3) +//! [2] + + +//! [3] +QPoint p( 3, 7); +QPoint q(-1, 4); +p += q; // p becomes (2, 11) +//! [3] + + +//! [4] +QPoint p( 3, 7); +QPoint q(-1, 4); +p -= q; // p becomes (4, 3) +//! [4] + + +//! [5] +QPoint p(-1, 4); +p *= 2.5; // p becomes (-3, 10) +//! [5] + + +//! [6] +QPoint p(-3, 10); +p /= 2.5; // p becomes (-1, 4) +//! [6] + + +//! [7] +QPoint oldPosition; + +MyWidget::mouseMoveEvent(QMouseEvent *event) +{ + QPoint point = event->pos() - oldPosition; + if (point.manhattanLength() > 3) + // the mouse has moved more than 3 pixels since the oldPosition +} +//! [7] + + +//! [8] +double trueLength = sqrt(pow(x(), 2) + pow(y(), 2)); +//! [8] + + +//! [9] +QPointF p; + +p.setX(p.x() + 1.0); +p += QPointF(1.0, 0.0); +p.rx()++; +//! [9] + + +//! [10] + QPointF p(1.1, 2.5); + p.rx()--; // p becomes (0.1, 2.5) +//! [10] + + +//! [11] +QPointF p(1.1, 2.5); +p.ry()++; // p becomes (1.1, 3.5) +//! [11] + + +//! [12] +QPointF p( 3.1, 7.1); +QPointF q(-1.0, 4.1); +p += q; // p becomes (2.1, 11.2) +//! [12] + + +//! [13] +QPointF p( 3.1, 7.1); +QPointF q(-1.0, 4.1); +p -= q; // p becomes (4.1, 3.0) +//! [13] + + +//! [14] +QPointF p(-1.1, 4.1); +p *= 2.5; // p becomes (-2.75, 10.25) +//! [14] + + +//! [15] +QPointF p(-2.75, 10.25); +p /= 2.5; // p becomes (-1.1, 4.1) +//! [15] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qqueue.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qqueue.cpp new file mode 100644 index 0000000000..3a1cf7c1a1 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qqueue.cpp @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QQueue queue; +queue.enqueue(1); +queue.enqueue(2); +queue.enqueue(3); +while (!queue.isEmpty()) + cout << queue.dequeue() << endl; +//! [0] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qrect.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qrect.cpp new file mode 100644 index 0000000000..ebf9118c20 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qrect.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QRect r1(100, 200, 11, 16); +QRect r2(QPoint(100, 200), QSize(11, 16)); +//! [0] + + +//! [1] +QRectF r1(100, 200, 11, 16); +QRectF r2(QPoint(100, 200), QSize(11, 16)); +//! [1] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qregexp.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qregexp.cpp new file mode 100644 index 0000000000..002ae96f23 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qregexp.cpp @@ -0,0 +1,224 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QRegExp rx("(\\d+)"); +QString str = "Offsets: 12 14 99 231 7"; +QStringList list; +int pos = 0; + +while ((pos = rx.indexIn(str, pos)) != -1) { + list << rx.cap(1); + pos += rx.matchedLength(); +} +// list: ["12", "14", "99", "231", "7"] +//! [0] + + +//! [1] +QRegExp rx("*.txt"); +rx.setPatternSyntax(QRegExp::Wildcard); +rx.exactMatch("README.txt"); // returns true +rx.exactMatch("welcome.txt.bak"); // returns false +//! [1] + + +//! [2] +QRegExp rx("ro+m"); +rx.setMinimal(true); +//! [2] + + +//! [3] +QRegExp mark("\\b" // word boundary + "[Mm]ark" // the word we want to match + ); +//! [3] + + +//! [4] +QRegExp rx("^\\d\\d?$"); // match integers 0 to 99 +rx.indexIn("123"); // returns -1 (no match) +rx.indexIn("-6"); // returns -1 (no match) +rx.indexIn("6"); // returns 0 (matched as position 0) +//! [4] + + +//! [5] +QRegExp rx("^\\S+$"); // match strings without whitespace +rx.indexIn("Hello world"); // returns -1 (no match) +rx.indexIn("This_is-OK"); // returns 0 (matched at position 0) +//! [5] + + +//! [6] +QRegExp rx("\\b(mail|letter|correspondence)\\b"); +rx.indexIn("I sent you an email"); // returns -1 (no match) +rx.indexIn("Please write the letter"); // returns 17 +//! [6] + + +//! [7] +QString captured = rx.cap(1); // captured == "letter" +//! [7] + + +//! [8] +QRegExp rx("&(?!amp;)"); // match ampersands but not & +QString line1 = "This & that"; +line1.replace(rx, "&"); +// line1 == "This & that" +QString line2 = "His & hers & theirs"; +line2.replace(rx, "&"); +// line2 == "His & hers & theirs" +//! [8] + + +//! [9] +QString str = "One Eric another Eirik, and an Ericsson. " + "How many Eiriks, Eric?"; +QRegExp rx("\\b(Eric|Eirik)\\b"); // match Eric or Eirik +int pos = 0; // where we are in the string +int count = 0; // how many Eric and Eirik's we've counted +while (pos >= 0) { + pos = rx.indexIn(str, pos); + if (pos >= 0) { + ++pos; // move along in str + ++count; // count our Eric or Eirik + } +} +//! [9] + + +//! [10] +str = "Nokia Corporation\tqt.nokia.com\tNorway"; +QString company, web, country; +rx.setPattern("^([^\t]+)\t([^\t]+)\t([^\t]+)$"); +if (rx.indexIn(str) != -1) { + company = rx.cap(1); + web = rx.cap(2); + country = rx.cap(3); +} +//! [10] + + +//! [11] +QStringList field = str.split("\t"); +//! [11] + + +//! [12] +QRegExp rx("*.html"); +rx.setPatternSyntax(QRegExp::Wildcard); +rx.exactMatch("index.html"); // returns true +rx.exactMatch("default.htm"); // returns false +rx.exactMatch("readme.txt"); // returns false +//! [12] + + +//! [13] +QString str = "offsets: 1.23 .50 71.00 6.00"; +QRegExp rx("\\d*\\.\\d+"); // primitive floating point matching +int count = 0; +int pos = 0; +while ((pos = rx.indexIn(str, pos)) != -1) { + ++count; + pos += rx.matchedLength(); +} +// pos will be 9, 14, 18 and finally 24; count will end up as 4 +//! [13] + + +//! [14] +QRegExp rx("(\\d+)(\\s*)(cm|inch(es)?)"); +int pos = rx.indexIn("Length: 36 inches"); +QStringList list = rx.capturedTexts(); +// list is now ("36 inches", "36", " ", "inches", "es") +//! [14] + + +//! [15] +QRegExp rx("(\\d+)(?:\\s*)(cm|inch(?:es)?)"); +int pos = rx.indexIn("Length: 36 inches"); +QStringList list = rx.capturedTexts(); +// list is now ("36 inches", "36", "inches") +//! [15] + + +//! [16] +QStringList list = rx.capturedTexts(); +QStringList::iterator it = list.begin(); +while (it != list.end()) { + myProcessing(*it); + ++it; +} +//! [16] + + +//! [17] +QRegExp rxlen("(\\d+)(?:\\s*)(cm|inch)"); +int pos = rxlen.indexIn("Length: 189cm"); +if (pos > -1) { + QString value = rxlen.cap(1); // "189" + QString unit = rxlen.cap(2); // "cm" + // ... +} +//! [17] + + +//! [18] +QRegExp rx("/([a-z]+)/([a-z]+)"); +rx.indexIn("Output /dev/null"); // returns 7 (position of /dev/null) +rx.pos(0); // returns 7 (position of /dev/null) +rx.pos(1); // returns 8 (position of dev) +rx.pos(2); // returns 12 (position of null) +//! [18] + + +//! [19] +s1 = QRegExp::escape("bingo"); // s1 == "bingo" +s2 = QRegExp::escape("f(x)"); // s2 == "f\\(x\\)" +//! [19] + + +//! [20] +QRegExp rx("(" + QRegExp::escape(name) + + "|" + QRegExp::escape(alias) + ")"); +//! [20] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qregularexpression.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qregularexpression.cpp new file mode 100644 index 0000000000..cab89d9c9e --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qregularexpression.cpp @@ -0,0 +1,289 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Giuseppe D'Angelo . +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QRegularExpression re("a pattern"); +//! [0] + + +//! [1] +QRegularExpression re; +re.setPattern("another pattern"); +//! [1] + + +//! [2] +// matches two digits followed by a space and a word +QRegularExpression re("\\d\\d \\w+"); + +// matches a backslash +QRegularExpression re2("\\\\"); +//! [2] + + +//! [3] +QRegularExpression re("a third pattern"); +QString pattern = re.pattern(); // pattern == "a third pattern" +//! [3] + + +//! [4] +// matches "Qt rocks", but also "QT rocks", "QT ROCKS", "qT rOcKs", etc. +QRegularExpression re("Qt rocks", QRegularExpression::CaseInsensitiveOption); +//! [4] + + +//! [5] +QRegularExpression re("^\\d+$"); +re.setPatternOptions(QRegularExpression::MultilineOption); +// re matches any line in the subject string that contains only digits (but at least one) +//! [5] + + +//! [6] +QRegularExpression re = QRegularExpression("^two.*words$", QRegularExpression::MultilineOption + | QRegularExpression::DotMatchesEverythingOption); + +QRegularExpression::PatternOptions options = re.patternOptions(); +// options == QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption +//! [6] + + +//! [7] +// match two digits followed by a space and a word +QRegularExpression re("\\d\\d \\w+"); +QRegularExpressionMatch match = re.match("abc123 def"); +bool hasMatch = match.hasMatch(); // true +//! [7] + + +//! [8] +QRegularExpression re("\\d\\d \\w+"); +QRegularExpressionMatch match = re.match("abc123 def"); +if (match.hasMatch()) { + QString matched = match.captured(0); // matched == "23 def" + // ... +} +//! [8] + + +//! [9] +QRegularExpression re("\\d\\d \\w+"); +QRegularExpressionMatch match = re.match("12 abc 45 def", 1); +if (match.hasMatch()) { + QString matched = match.captured(0); // matched == "45 def" + // ... +} +//! [9] + + +//! [10] +QRegularExpression re("^(\\d\\d)/(\\d\\d)/(\\d\\d\\d\\d)$"); +QRegularExpressionMatch match = re.match("08/12/1985"); +if (match.hasMatch()) { + QString day = re.captured(1); // day == "08" + QString month = re.captured(2); // month == "12" + QString year = re.captured(3); // year == "1985" + // ... +} +//! [10] + + +//! [11] +QRegularExpression re("abc(\\d+)def"); +QRegularExpressionMatch match = re.match("XYZabc123defXYZ"); +if (match.hasMatch()) { + int startOffset = re.capturedStart(1); // startOffset == 6 + int endOffset = re.capturedEnd(1); // endOffset == 9 + // ... +} +//! [11] + + +//! [12] +QRegularExpression re("^(?\\d\\d)/(?\\d\\d)/(?\\d\\d\\d\\d)$"); +QRegularExpressionMatch match = re.match("08/12/1985"); +if (match.hasMatch()) { + QString date = match.captured("date"); // date == "08" + QString month = match.captured("month"); // month == "12" + QString year = match.captured("year"); // year == 1985 +} +//! [12] + + +//! [13] +QRegularExpression re("(\\w+)"); +QRegularExpressionMatchIterator i = re.globalMatch("the quick fox"); +//! [13] + + +//! [14] +QStringList words; +while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + QString word = match.captured(1); + words << word; +} +// words contains "the", "quick", "fox" +//! [14] + + +//! [15] +QString pattern("^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d\\d?, \\d\\d\\d\\d$"); +QRegularExpression re(pattern); + +QString input("Jan 21,"); +QRegularExpressionMatch match = re.match(input, 0, QRegularExpressionMatch::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [15] + + +//! [16] +QString input("Dec 8, 1985"); +QRegularExpressionMatch match = re.match(input, 0, QRegularExpressionMatch::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // true +bool hasPartialMatch = match.hasPartialMatch(); // false +//! [16] + + +//! [17] +QRegularExpression re("abc\\w+X|def"); +QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpressionMatch::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // true +bool hasPartialMatch = match.hasPartialMatch(); // false +QString captured = match.captured(0); // captured == "def" +//! [17] + + +//! [18] +QRegularExpression re("abc\\w+X|defY"); +QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpressionMatch::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +QString captured = match.captured(0); // captured == "abcdef" +//! [18] + + +//! [19] +QRegularExpression re("abc|ab"); +QRegularExpressionMatch match = re.match("ab", 0, QRegularExpressionMatch::PartialPreferFirstMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [19] + + +//! [20] +QRegularExpression re("abc(def)?"); +QRegularExpressionMatch match = re.match("abc", 0, QRegularExpressionMatch::PartialPreferFirstMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [20] + +//! [21] +QRegularExpression re("(abc)*"); +QRegularExpressionMatch match = re.match("abc", 0, QRegularExpressionMatch::PartialPreferFirstMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [21] + +//! [22] +QRegularExpression invalidRe("(unmatched|parenthesis"); +bool isValid = invalidRe.isValid(); // false +//! [22] + +//! [23] +QRegularExpression invalidRe("(unmatched|parenthesis"); +if (!invalidRe.isValid()) { + QString errorString = invalidRe.errorString(); // errorString == "missing )" + int errorOffset = invalidRe.patternErrorOffset(); // errorOffset == 22 + // ... +} +//! [23] + +//! [24] +QRegularExpression re("^this pattern must match exactly$"); +//! [24] + +//! [25] +QString p("a .*|pattern"); +QRegularExpression re("\\A(?:" + p + ")\\z"); // re matches exactly the pattern string p +//! [25] + +//! [26] +QString escaped = QRegularExpression::escape("a(x) = f(x) + g(x)"); +// escaped == "a\\(x\\)\\ \\=\\ f\\(x\\)\\ \\+\\ g\\(x\\)" +//! [26] + +//! [27] +QString pattern = "(" + QRegularExpression::escape(name) + + "|" + QRegularExpression::escape(nickname) + ")"; +QRegularExpression re(pattern); +//! [27] + +//! [28] +QRegularExpressionMatch match = re.match(...); +for (int i = 0; i <= match.lastCapturedIndex(); ++i) { + QString captured = match.captured(i); + // ... +} +//! [28] + +//! [29] +QRegularExpression("(\d\d) (?\w+)"); +QRegularExpressionMatch match = re.match("23 Jordan"); +if (match.hasMatch()) { + QString number = match.captured(1); // first == "23" + QString name = match.captured("name"); // name == "Jordan" +} +//! [29] + +//! [30] +// extracts the words +QRegularExpression re("(\w+)"); +QString subject("the quick fox"); +QRegularExpressionMatchIterator i = re.globalMatch(subject); +while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + // ... +} +//! [30] + + diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qscopedpointer.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qscopedpointer.cpp new file mode 100644 index 0000000000..fd9cd3e4b0 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qscopedpointer.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +void myFunction(bool useSubClass) +{ + MyClass *p = useSubClass ? new MyClass() : new MySubClass; + QIODevice *device = handsOverOwnership(); + + if (m_value > 3) { + delete p; + delete device; + return; + } + + try { + process(device); + } + catch (...) { + delete p; + delete device; + throw; + } + + delete p; + delete device; +} +//! [0] + +//! [1] +void myFunction(bool useSubClass) +{ + // assuming that MyClass has a virtual destructor + QScopedPointer p(useSubClass ? new MyClass() : new MySubClass); + QScopedPointer device(handsOverOwnership()); + + if (m_value > 3) + return; + + process(device); +} +//! [1] + +//! [2] + const QWidget *const p = new QWidget(); + // is equivalent to: + const QScopedPointer p(new QWidget()); + + QWidget *const p = new QWidget(); + // is equivalent to: + const QScopedPointer p(new QWidget()); + + const QWidget *p = new QWidget(); + // is equivalent to: + QScopedPointer p(new QWidget()); +//! [2] + +//! [3] +if (scopedPointer) { + ... +} +//! [3] + +//! [4] +class MyPrivateClass; // forward declare MyPrivateClass + +class MyClass +{ +private: + QScopedPointer privatePtr; // QScopedPointer to forward declared class + +public: + MyClass(); // OK + inline ~MyClass() {} // VIOLATION - Destructor must not be inline + +private: + Q_DISABLE_COPY(MyClass) // OK - copy constructor and assignment operators + // are now disabled, so the compiler won't implicitely + // generate them. +}; +//! [4] + +//! [5] +// this QScopedPointer deletes its data using the delete[] operator: +QScopedPointer > arrayPointer(new int[42]); + +// this QScopedPointer frees its data using free(): +QScopedPointer podPointer(reinterpret_cast(malloc(42))); + +// this struct calls "myCustomDeallocator" to delete the pointer +struct ScopedPointerCustomDeleter +{ + static inline void cleanup(MyCustomClass *pointer) + { + myCustomDeallocator(pointer); + } +}; + +// QScopedPointer using a custom deleter: +QScopedPointer customPointer(new MyCustomClass); +//! [5] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qsize.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qsize.cpp new file mode 100644 index 0000000000..8772152ad6 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qsize.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QSize t1(10, 12); +t1.scale(60, 60, Qt::IgnoreAspectRatio); +// t1 is (60, 60) + +QSize t2(10, 12); +t2.scale(60, 60, Qt::KeepAspectRatio); +// t2 is (50, 60) + +QSize t3(10, 12); +t3.scale(60, 60, Qt::KeepAspectRatioByExpanding); +// t3 is (60, 72) +//! [0] + + +//! [1] +QSize size(100, 10); +size.rwidth() += 20; + +// size becomes (120,10) +//! [1] + + +//! [2] +QSize size(100, 10); +size.rheight() += 5; + +// size becomes (100,15) +//! [2] + + +//! [3] +QSize s( 3, 7); +QSize r(-1, 4); +s += r; + +// s becomes (2,11) +//! [3] + + +//! [4] +QSize s( 3, 7); +QSize r(-1, 4); +s -= r; + +// s becomes (4,3) +//! [4] + + +//! [5] +QSizeF t1(10, 12); +t1.scale(60, 60, Qt::IgnoreAspectRatio); +// t1 is (60, 60) + +QSizeF t2(10, 12); +t2.scale(60, 60, Qt::KeepAspectRatio); +// t2 is (50, 60) + +QSizeF t3(10, 12); +t3.scale(60, 60, Qt::KeepAspectRatioByExpanding); +// t3 is (60, 72) +//! [5] + + +//! [6] +QSizeF size(100.3, 10); +size.rwidth() += 20.5; + + // size becomes (120.8,10) +//! [6] + + +//! [7] +QSizeF size(100, 10.2); +size.rheight() += 5.5; + +// size becomes (100,15.7) +//! [7] + + +//! [8] +QSizeF s( 3, 7); +QSizeF r(-1, 4); +s += r; + +// s becomes (2,11) +//! [8] + + +//! [9] +QSizeF s( 3, 7); +QSizeF r(-1, 4); +s -= r; + +// s becomes (4,3) +//! [9] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp new file mode 100644 index 0000000000..507e929f47 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +DEFINES += QT_NO_CAST_FROM_ASCII \ + QT_NO_CAST_TO_ASCII +//! [0] + + +//! [1] +QString url = QLatin1String("http://www.unicode.org/"); +//! [1] + + +//! [2] +double d = 12.34; +QString str = QString("delta: %1").arg(d, 0, 'E', 3); +// str == "delta: 1.234E+01" +//! [2] + + +//! [3] +if (str == "auto" || str == "extern" + || str == "static" || str == "register") { + ... +} +//! [3] + + +//! [4] +if (str == QString("auto") || str == QString("extern") + || str == QString("static") || str == QString("register")) { + ... +} +//! [4] + + +//! [5] +if (str == QLatin1String("auto") + || str == QLatin1String("extern") + || str == QLatin1String("static") + || str == QLatin1String("register") { + ... +} +//! [5] + + +//! [6] +QLabel *label = new QLabel(QLatin1String("MOD"), this); +//! [6] + + +//! [7] +QString plain = "#include " +QString html = plain.toHtmlEscaped(); +// html == "#include <QtCore>" +//! [7] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp new file mode 100644 index 0000000000..e33c94efda --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +... +progressBar = new QProgressBar(this); +progressBar->setRange(0, 100); + +// Construct a 1-second timeline with a frame range of 0 - 100 +QTimeLine *timeLine = new QTimeLine(1000, this); +timeLine->setFrameRange(0, 100); +connect(timeLine, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int))); + +// Clicking the push button will start the progress bar animation +pushButton = new QPushButton(tr("Start animation"), this); +connect(pushButton, SIGNAL(clicked()), timeLine, SLOT(start())); +... +//! [0] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp new file mode 100644 index 0000000000..b3f9a7e675 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp @@ -0,0 +1,183 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QVector integerVector; +QVector stringVector; +//! [0] + + +//! [1] +QVector vector(200); +//! [1] + + +//! [2] +QVector vector(200, "Pass"); +//! [2] + + +//! [3] +if (vector[0] == "Liz") + vector[0] = "Elizabeth"; +//! [3] + + +//! [4] +for (int i = 0; i < vector.size(); ++i) { + if (vector.at(i) == "Alfonso") + cout << "Found Alfonso at position " << i << endl; +} +//! [4] + + +//! [5] +int i = vector.indexOf("Harumi"); +if (i != -1) + cout << "First occurrence of Harumi is at position " << i << endl; +//! [5] + + +//! [6] +QVector vector(10); +int *data = vector.data(); +for (int i = 0; i < 10; ++i) + data[i] = 2 * i; +//! [6] + + +//! [7] +QVector vector(0); +vector.append("one"); +vector.append("two"); +vector.append("three"); +// vector: ["one", "two", "three"] +//! [7] + + +//! [8] +QVector vector; +vector.prepend("one"); +vector.prepend("two"); +vector.prepend("three"); +// vector: ["three", "two", "one"] +//! [8] + + +//! [9] +QVector vector; +vector << "alpha" << "beta" << "delta"; +vector.insert(2, "gamma"); +// vector: ["alpha", "beta", "gamma", "delta"] +//! [9] + + +//! [10] +QVector vector; +vector << 2.718 << 1.442 << 0.4342; +vector.insert(1, 3, 9.9); +// vector: [2.718, 9.9, 9.9, 9.9, 1.442, 0.4342] +//! [10] + + +//! [11] +QVector vector(3); +vector.fill("Yes"); +// vector: ["Yes", "Yes", "Yes"] + +vector.fill("oh", 5); +// vector: ["oh", "oh", "oh", "oh", "oh"] +//! [11] + + +//! [12] +QVector vector; +vector << "A" << "B" << "C" << "B" << "A"; +vector.indexOf("B"); // returns 1 +vector.indexOf("B", 1); // returns 1 +vector.indexOf("B", 2); // returns 3 +vector.indexOf("X"); // returns -1 +//! [12] + + +//! [13] +QList vector; +vector << "A" << "B" << "C" << "B" << "A"; +vector.lastIndexOf("B"); // returns 3 +vector.lastIndexOf("B", 3); // returns 3 +vector.lastIndexOf("B", 2); // returns 1 +vector.lastIndexOf("X"); // returns -1 +//! [13] + + +//! [14] +QVector vect; +vect << "red" << "green" << "blue" << "black"; + +QList list = vect.toList(); +// list: ["red", "green", "blue", "black"] +//! [14] + + +//! [15] +QStringList list; +list << "Sven" << "Kim" << "Ola"; + +QVector vect = QVector::fromList(list); +// vect: ["Sven", "Kim", "Ola"] +//! [15] + + +//! [16] +std::vector stdvector; +vector.push_back(1.2); +vector.push_back(0.5); +vector.push_back(3.14); + +QVector vector = QVector::fromStdVector(stdvector); +//! [16] + + +//! [17] +QVector vector; +vector << 1.2 << 0.5 << 3.14; + +std::vector stdvector = vector.toStdVector(); +//! [17] diff --git a/src/corelib/doc/snippets/code/src_corelib_xml_qxmlstream.cpp b/src/corelib/doc/snippets/code/src_corelib_xml_qxmlstream.cpp new file mode 100644 index 0000000000..9f40777df1 --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_xml_qxmlstream.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QXmlStreamReader xml; + ... + while (!xml.atEnd()) { + xml.readNext(); + ... // do processing + } + if (xml.hasError()) { + ... // do error handling + } +//! [0] + + +//! [1] + writeStartElement(qualifiedName); + writeCharacters(text); + writeEndElement(); +//! [1] + + +//! [2] + writeStartElement(namespaceUri, name); + writeCharacters(text); + writeEndElement(); +//! [2] + + diff --git a/src/corelib/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp b/src/corelib/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp new file mode 100644 index 0000000000..90bc2e9b0a --- /dev/null +++ b/src/corelib/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +int ret = QMessageBox::warning(this, tr("My Application"), + tr("The document has been modified.\n" + "Do you want to save your changes?"), + QMessageBox::Save | QMessageBox::Discard + | QMessageBox::Cancel, + QMessageBox::Save); +//! [0] + + +//! [1] +QMessageBox msgBox; +msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); +switch (msgBox.exec()) { +case QMessageBox::Yes: + // yes was clicked + break; +case QMessageBox::No: + // no was clicked + break; +default: + // should never be reached + break; +} +//! [1] + + +//! [2] +QMessageBox msgBox; +QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole); +QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort); + +msgBox.exec(); + +if (msgBox.clickedButton() == connectButton) { + // connect +} else if (msgBox.clickedButton() == abortButton) { + // abort +} +//! [2] + + +//! [3] +QMessageBox messageBox(this); +QAbstractButton *disconnectButton = + messageBox.addButton(tr("Disconnect"), QMessageBox::ActionRole); +... +messageBox.exec(); +if (messageBox.clickedButton() == disconnectButton) { + ... +} +//! [3] + + +//! [4] +#include +#include + +int main(int argc, char *argv[]) +{ + QT_REQUIRE_VERSION(argc, argv, "4.0.2") + + QApplication app(argc, argv); + ... + return app.exec(); +} +//! [4] + +//! [5] +QMessageBox msgBox; +msgBox.setText("The document has been modified."); +msgBox.exec(); +//! [5] + +//! [6] +QMessageBox msgBox; +msgBox.setText("The document has been modified."); +msgBox.setInformativeText("Do you want to save your changes?"); +msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); +msgBox.setDefaultButton(QMessageBox::Save); +int ret = msgBox.exec(); +//! [6] + +//! [7] +switch (ret) { + case QMessageBox::Save: + // Save was clicked + break; + case QMessageBox::Discard: + // Don't Save was clicked + break; + case QMessageBox::Cancel: + // Cancel was clicked + break; + default: + // should never be reached + break; +} +//! [7] + +//! [9] +QMessageBox msgBox(this); +msgBox.setText(tr("The document has been modified.\n" + "Do you want to save your changes?")); +msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard + | QMessageBox::Cancel); +msgBox.setDefaultButton(QMessageBox::Save); +//! [9] diff --git a/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp b/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp new file mode 100644 index 0000000000..cf4707cbeb --- /dev/null +++ b/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class DateFormatProxyModel : public QIdentityProxyModel +{ + // ... + + void setDateFormatString(const QString &formatString) + { + m_formatString = formatString; + } + + QVariant data(const QModelIndex &index, int role) + { + if (role != Qt::DisplayRole) + return QIdentityProxyModel::data(index, role); + + const QDateTime dateTime = sourceModel()->data(SourceClass::DateRole).toDateTime(); + + return dateTime.toString(m_formatString); + } + +private: + QString m_formatString; +}; +//! [0] diff --git a/src/corelib/doc/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp b/src/corelib/doc/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp new file mode 100644 index 0000000000..ba81221e9c --- /dev/null +++ b/src/corelib/doc/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QItemSelection *selection = new QItemSelection(topLeft, bottomRight); +//! [0] + + +//! [1] +QItemSelection *selection = new QItemSelection(); +... +selection->select(topLeft, bottomRight); +//! [1] diff --git a/src/corelib/doc/snippets/file/file.cpp b/src/corelib/doc/snippets/file/file.cpp new file mode 100644 index 0000000000..f03c6e6847 --- /dev/null +++ b/src/corelib/doc/snippets/file/file.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +static void process_line(const QByteArray &) +{ +} + +static void process_line(const QString &) +{ +} + +static void noStream_snippet() +{ +//! [0] + QFile file("in.txt"); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + + while (!file.atEnd()) { + QByteArray line = file.readLine(); + process_line(line); + } +//! [0] +} + +static void readTextStream_snippet() +{ +//! [1] + QFile file("in.txt"); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + + QTextStream in(&file); + while (!in.atEnd()) { + QString line = in.readLine(); + process_line(line); + } +//! [1] +} + +static void writeTextStream_snippet() +{ +//! [2] + QFile file("out.txt"); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + return; + + QTextStream out(&file); + out << "The magic number is: " << 49 << "\n"; +//! [2] +} + +static void writeTextStream_snippet() +{ + QFile file("out.dat"); + if (!file.open(QIODevice::WriteOnly)) + return; + + QDataStream out(&file); + out << "The magic number is: " << 49 << "\n"; +} + +static void readRegularEmptyFile_snippet() +{ +//! [3] + QFile file("/proc/modules"); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + + QTextStream in(&file); + QString line = in.readLine(); + while (!line.isNull()) { + process_line(line); + line = in.readLine(); + } +//! [3] +} + +int main() +{ + lineByLine_snippet(); + writeStream_snippet(); +} diff --git a/src/corelib/doc/snippets/fileinfo/main.cpp b/src/corelib/doc/snippets/fileinfo/main.cpp new file mode 100644 index 0000000000..48d8223d79 --- /dev/null +++ b/src/corelib/doc/snippets/fileinfo/main.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + +//! [0] + QFileInfo fileInfo1("~/examples/191697/."); + QFileInfo fileInfo2("~/examples/191697/.."); + QFileInfo fileInfo3("~/examples/191697/main.cpp"); +//! [0] +//! [1] + QFileInfo fileInfo4("."); + QFileInfo fileInfo5(".."); + QFileInfo fileInfo6("main.cpp"); +//! [1] + + qDebug() << fileInfo1.fileName(); + qDebug() << fileInfo2.fileName(); + qDebug() << fileInfo3.fileName(); + qDebug() << fileInfo4.fileName(); + qDebug() << fileInfo5.fileName(); + qDebug() << fileInfo6.fileName(); + + QPushButton* button1 = new QPushButton(fileInfo1.dir().path()); + QPushButton* button2 = new QPushButton(fileInfo2.dir().path()); + QPushButton* button3 = new QPushButton(fileInfo3.dir().path()); + QPushButton* button4 = new QPushButton(fileInfo4.dir().path()); + QPushButton* button5 = new QPushButton(fileInfo5.dir().path()); + QPushButton* button6 = new QPushButton(fileInfo6.dir().path()); + + QVBoxLayout* vbox = new QVBoxLayout; + vbox->addWidget(button1); + vbox->addWidget(button2); + vbox->addWidget(button3); + vbox->addWidget(button4); + vbox->addWidget(button5); + vbox->addWidget(button6); + vbox->addStretch(1); + + QGroupBox *groupBox = new QGroupBox("QFileInfo::dir() test"); + groupBox->setLayout(vbox); + groupBox->show(); + + return app.exec(); +} diff --git a/src/corelib/doc/snippets/ntfsp.cpp b/src/corelib/doc/snippets/ntfsp.cpp new file mode 100644 index 0000000000..8f2ff1fc98 --- /dev/null +++ b/src/corelib/doc/snippets/ntfsp.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +//! [0] +extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; +//! [0] + +//! [1] +qt_ntfs_permission_lookup++; // turn checking on +qt_ntfs_permission_lookup--; // turn it off again +//! [1] + diff --git a/src/corelib/doc/snippets/pointer/pointer.cpp b/src/corelib/doc/snippets/pointer/pointer.cpp new file mode 100644 index 0000000000..dd2bc82102 --- /dev/null +++ b/src/corelib/doc/snippets/pointer/pointer.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + +//! [0] + QPointer label = new QLabel; + label->setText("&Status:"); +//! [0] + +//! [1] + if (label) +//! [1] //! [2] + label->show(); +//! [2] + return 0; +} diff --git a/src/corelib/doc/snippets/process/process.cpp b/src/corelib/doc/snippets/process/process.cpp new file mode 100644 index 0000000000..19f241a695 --- /dev/null +++ b/src/corelib/doc/snippets/process/process.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +bool zip() +{ +//! [0] + QProcess gzip; + gzip.start("gzip", QStringList() << "-c"); + if (!gzip.waitForStarted()) + return false; + + gzip.write("Qt rocks!"); + gzip.closeWriteChannel(); + + if (!gzip.waitForFinished()) + return false; + + QByteArray result = gzip.readAll(); +//! [0] + + gzip.start("gzip", QStringList() << "-d" << "-c"); + gzip.write(result); + gzip.closeWriteChannel(); + + if (!gzip.waitForFinished()) + return false; + + qDebug("Result: %s", gzip.readAll().data()); + return true; +} + + +int main() +{ + zip(); + return 0; +} diff --git a/src/corelib/doc/snippets/qdebug/qdebugsnippet.cpp b/src/corelib/doc/snippets/qdebug/qdebugsnippet.cpp new file mode 100644 index 0000000000..2dbfe49c7d --- /dev/null +++ b/src/corelib/doc/snippets/qdebug/qdebugsnippet.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +class Coordinate : public QObject +{ +public: + int myX, myY; + + int x() const { return myX; }; + int y() const { return myY; }; +}; + +//! [0] +QDebug operator<<(QDebug dbg, const Coordinate &c) +{ + dbg.nospace() << "(" << c.x() << ", " << c.y() << ")"; + + return dbg.space(); +} +//! [0] + +int main(int argv, char **args) +{ + Coordinate coordinate; + coordinate.myX = 10; + coordinate.myY = 44; + +//! [1] + qDebug() << "Date:" << QDate::currentDate(); + qDebug() << "Types:" << QString("String") << QChar('x') << QRect(0, 10, 50, 40); + qDebug() << "Custom coordinate type:" << coordinate; +//! [1] +} diff --git a/src/corelib/doc/snippets/qdir-listfiles/main.cpp b/src/corelib/doc/snippets/qdir-listfiles/main.cpp new file mode 100644 index 0000000000..599046aabd --- /dev/null +++ b/src/corelib/doc/snippets/qdir-listfiles/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#include +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + QDir dir; + dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); + dir.setSorting(QDir::Size | QDir::Reversed); + + QFileInfoList list = dir.entryInfoList(); + std::cout << " Bytes Filename" << std::endl; + for (int i = 0; i < list.size(); ++i) { + QFileInfo fileInfo = list.at(i); + std::cout << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10) + .arg(fileInfo.fileName())); + std::cout << std::endl; + } + return 0; +} +//! [0] diff --git a/src/corelib/doc/snippets/qdir-namefilters/main.cpp b/src/corelib/doc/snippets/qdir-namefilters/main.cpp new file mode 100644 index 0000000000..7b48f7eaf7 --- /dev/null +++ b/src/corelib/doc/snippets/qdir-namefilters/main.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main(int argc, char *argv[]) +{ + QDir dir; + dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); + dir.setSorting(QDir::Size | QDir::Reversed); + +//! [0] + QStringList filters; + filters << "*.cpp" << "*.cxx" << "*.cc"; + dir.setNameFilters(filters); +//! [0] + + QFileInfoList list = dir.entryInfoList(); + std::cout << " Bytes Filename" << std::endl; + for (int i = 0; i < list.size(); ++i) { + QFileInfo fileInfo = list.at(i); + std::cout << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10) + .arg(fileInfo.fileName())); + std::cout << std::endl; + } + return 0; +} diff --git a/src/corelib/doc/snippets/qelapsedtimer/main.cpp b/src/corelib/doc/snippets/qelapsedtimer/main.cpp new file mode 100644 index 0000000000..7b4b6529e7 --- /dev/null +++ b/src/corelib/doc/snippets/qelapsedtimer/main.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include + +void slowOperation1() +{ + static char buf[256]; + for (int i = 0; i < (1<<20); ++i) + buf[i % sizeof buf] = i; +} + +void slowOperation2(int) { slowOperation1(); } + +void startExample() +{ +//![0] + QElapsedTimer timer; + timer.start(); + + slowOperation1(); + + qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds"; +//![0] +} + +//![1] +void executeSlowOperations(int timeout) +{ + QElapsedTimer timer; + timer.start(); + slowOperation1(); + + int remainingTime = timeout - timer.elapsed(); + if (remainingTime > 0) + slowOperation2(remainingTime); +} +//![1] + +//![2] +void executeOperationsForTime(int ms) +{ + QElapsedTimer timer; + timer.start(); + + while (!timer.hasExpired(ms)) + slowOperation1(); +} +//![2] + +int restartExample() +{ +//![3] + QElapsedTimer timer; + + int count = 1; + timer.start(); + do { + count *= 2; + slowOperation2(count); + } while (timer.restart() < 250); + + return count; +//![3] +} + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + startExample(); + restartExample(); + executeSlowOperations(5); + executeOperationsForTime(5); +} diff --git a/src/corelib/doc/snippets/qmetaobject-invokable/main.cpp b/src/corelib/doc/snippets/qmetaobject-invokable/main.cpp new file mode 100644 index 0000000000..b22df1ea15 --- /dev/null +++ b/src/corelib/doc/snippets/qmetaobject-invokable/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window window; + qDebug() << window.metaObject()->methodCount(); + window.show(); + return app.exec(); +} diff --git a/src/corelib/doc/snippets/qmetaobject-invokable/qmetaobject-invokable.pro b/src/corelib/doc/snippets/qmetaobject-invokable/qmetaobject-invokable.pro new file mode 100644 index 0000000000..4df19215f0 --- /dev/null +++ b/src/corelib/doc/snippets/qmetaobject-invokable/qmetaobject-invokable.pro @@ -0,0 +1,3 @@ +HEADERS = window.h +SOURCES = main.cpp \ + window.cpp diff --git a/src/corelib/doc/snippets/qmetaobject-invokable/window.cpp b/src/corelib/doc/snippets/qmetaobject-invokable/window.cpp new file mode 100644 index 0000000000..5ab8d83f63 --- /dev/null +++ b/src/corelib/doc/snippets/qmetaobject-invokable/window.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "window.h" + +Window::Window() +{ +} + +void Window::normalMethod() +{ + // Cannot be called by the meta-object system. + show(); +} + +void Window::invokableMethod() +{ + // Can be called by the meta-object system. + show(); +} diff --git a/src/corelib/doc/snippets/qmetaobject-invokable/window.h b/src/corelib/doc/snippets/qmetaobject-invokable/window.h new file mode 100644 index 0000000000..f2f34792e5 --- /dev/null +++ b/src/corelib/doc/snippets/qmetaobject-invokable/window.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +//! [Window class with invokable method] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(); + void normalMethod(); + Q_INVOKABLE void invokableMethod(); +}; +//! [Window class with invokable method] + +#endif diff --git a/src/corelib/doc/snippets/qprocess-environment/main.cpp b/src/corelib/doc/snippets/qprocess-environment/main.cpp new file mode 100644 index 0000000000..124668a544 --- /dev/null +++ b/src/corelib/doc/snippets/qprocess-environment/main.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +void startProcess() +{ + { +//! [0] +QProcess process; +QStringList env = QProcess::systemEnvironment(); +env << "TMPDIR=C:\\MyApp\\temp"; // Add an environment variable +env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;C:\\Bin"); +process.setEnvironment(env); +process.start("myapp"); +//! [0] + } + + { +//! [1] +QProcess process; +QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); +env.insert("TMPDIR", "C:\\MyApp\\temp"); // Add an environment variable +env.insert("PATH", env.value("Path") + ";C:\\Bin"); +process.setProcessEnvironment(env); +process.start("myapp"); +//! [1] + } +} + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + startProcess(); + return app.exec(); +} diff --git a/src/corelib/doc/snippets/qprocess/qprocess-simpleexecution.cpp b/src/corelib/doc/snippets/qprocess/qprocess-simpleexecution.cpp new file mode 100644 index 0000000000..ea1892078e --- /dev/null +++ b/src/corelib/doc/snippets/qprocess/qprocess-simpleexecution.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); +//! [0] + QObject *parent; +//! [0] + parent = &app; + +//! [1] + QString program = "./path/to/Qt/examples/widgets/analogclock"; +//! [1] + program = "./../../../../examples/widgets/analogclock/analogclock"; + +//! [2] + QStringList arguments; + arguments << "-style" << "motif"; + + QProcess *myProcess = new QProcess(parent); + myProcess->start(program, arguments); +//! [2] + + return app.exec(); +} diff --git a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp new file mode 100644 index 0000000000..cda905e3a2 --- /dev/null +++ b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "buttonwidget.h" + +//! [0] +ButtonWidget::ButtonWidget(QStringList texts, QWidget *parent) + : QWidget(parent) +{ + signalMapper = new QSignalMapper(this); + + QGridLayout *gridLayout = new QGridLayout; + for (int i = 0; i < texts.size(); ++i) { + QPushButton *button = new QPushButton(texts[i]); + connect(button, SIGNAL(clicked()), signalMapper, SLOT(map())); +//! [0] //! [1] + signalMapper->setMapping(button, texts[i]); + gridLayout->addWidget(button, i / 3, i % 3); + } + + connect(signalMapper, SIGNAL(mapped(const QString &)), +//! [1] //! [2] + this, SIGNAL(clicked(const QString &))); + + setLayout(gridLayout); +} +//! [2] diff --git a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h new file mode 100644 index 0000000000..9204de935a --- /dev/null +++ b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BUTTONWIDGET_H +#define BUTTONWIDGET_H + +#include + +class QSignalMapper; +class QString; +class QStringList; + +//! [0] +class ButtonWidget : public QWidget +{ + Q_OBJECT + +public: + ButtonWidget(QStringList texts, QWidget *parent = 0); + +signals: + void clicked(const QString &text); + +private: + QSignalMapper *signalMapper; +//! [0] //! [1] +}; +//! [1] + +#endif diff --git a/src/corelib/doc/snippets/qsortfilterproxymodel-details/main.cpp b/src/corelib/doc/snippets/qsortfilterproxymodel-details/main.cpp new file mode 100644 index 0000000000..549d24b249 --- /dev/null +++ b/src/corelib/doc/snippets/qsortfilterproxymodel-details/main.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +class MyItemModel : public QStandardItemModel +{ +public: + MyItemModel(QWidget *parent = 0); +}; + +MyItemModel::MyItemModel(QWidget *parent) + : QStandardItemModel(parent) +{}; + +class Widget : public QWidget +{ +public: + Widget(QWidget *parent = 0); +}; + +Widget::Widget(QWidget *parent) + : QWidget(parent) +{ +//! [0] //! [1] + QTreeView *treeView = new QTreeView; +//! [0] + MyItemModel *model = new MyItemModel(this); + + treeView->setModel(model); +//! [1] + +//! [2] + MyItemModel *sourceModel = new MyItemModel(this); + QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); + + proxyModel->setSourceModel(sourceModel); + treeView->setModel(proxyModel); +//! [2] + +//! [3] + treeView->setSortingEnabled(true); +//! [3] + +//! [4] + proxyModel->sort(2, Qt::AscendingOrder); +//! [4] //! [5] + proxyModel->setFilterRegExp(QRegExp(".png", Qt::CaseInsensitive, + QRegExp::FixedString)); + proxyModel->setFilterKeyColumn(1); +//! [5] +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Widget widget; + widget.show(); + return app.exec(); +} diff --git a/src/corelib/doc/snippets/qstack/main.cpp b/src/corelib/doc/snippets/qstack/main.cpp new file mode 100644 index 0000000000..cc96f8c55d --- /dev/null +++ b/src/corelib/doc/snippets/qstack/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +using namespace std; + +int main(int argc, char *argv[]) +{ +//! [0] + QStack stack; + stack.push(1); + stack.push(2); + stack.push(3); + while (!stack.isEmpty()) + cout << stack.pop() << endl; +//! [0] +} diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp new file mode 100644 index 0000000000..d7299e80d5 --- /dev/null +++ b/src/corelib/doc/snippets/qstring/main.cpp @@ -0,0 +1,997 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +class Widget : public QWidget +{ +public: + Widget(QWidget *parent = 0); + + void constCharPointer(); + void constCharArray(); + void characterReference(); + void atFunction(); + void stringLiteral(); + void modify(); + void index(); + QString boolToString(bool b); + void nullVsEmpty(); + + void appendFunction(); + void argFunction(); + void chopFunction(); + void compareFunction(); + void compareSensitiveFunction(); + void containsFunction(); + void countFunction(); + void dataFunction(); + void endsWithFunction(); + void fillFunction(); + void fromRawDataFunction(); + + void indexOfFunction(); + void firstIndexOfFunction(); + void insertFunction(); + void isNullFunction(); + void isEmptyFunction(); + void lastIndexOfFunction(); + void leftFunction(); + void leftJustifiedFunction(); + void leftRefFunction(); + void midFunction(); + void midRefFunction(); + void numberFunction(); + + void prependFunction(); + void removeFunction(); + void replaceFunction(); + void reserveFunction(); + void resizeFunction(); + void rightFunction(); + void rightJustifiedFunction(); + void rightRefFunction(); + void sectionFunction(); + void setNumFunction(); + void simplifiedFunction(); + + void sizeFunction(); + void splitFunction(); + void splitCaseSensitiveFunction(); + void sprintfFunction(); + void startsWithFunction(); + void toDoubleFunction(); + void toFloatFunction(); + void toIntFunction(); + void toLongFunction(); + void toLongLongFunction(); + + void toLowerFunction(); + void toShortFunction(); + void toUIntFunction(); + void toULongFunction(); + void toULongLongFunction(); + void toUShortFunction(); + void toUpperFunction(); + void trimmedFunction(); + void truncateFunction(); + + void plusEqualOperator(); + void arrayOperator(); +}; + +Widget::Widget(QWidget *parent) + : QWidget(parent) +{ +} + +void Widget::constCharPointer() +{ + //! [0] + QString str = "Hello"; + //! [0] +} + +void Widget::constCharArray() +{ + //! [1] + static const QChar data[4] = { 0x0055, 0x006e, 0x10e3, 0x03a3 }; + QString str(data, 4); + //! [1] +} + +void Widget::characterReference() +{ + //! [2] + QString str; + str.resize(4); + + str[0] = QChar('U'); + str[1] = QChar('n'); + str[2] = QChar(0x10e3); + str[3] = QChar(0x03a3); + //! [2] +} + +void Widget::atFunction() +{ + //! [3] + QString str; + + for (int i = 0; i < str.size(); ++i) { + if (str.at(i) >= QChar('a') && str.at(i) <= QChar('f')) + qDebug() << "Found character in range [a-f]"; + } + //! [3] +} + +void Widget::stringLiteral() +{ + //! [4] + QString str; + + if (str == "auto" || str == "extern" + || str == "static" || str == "register") { + // ... + } + //! [4] +} + +void Widget::modify() +{ + //! [5] + QString str = "and"; + str.prepend("rock "); // str == "rock and" + str.append(" roll"); // str == "rock and roll" + str.replace(5, 3, "&"); // str == "rock & roll" + //! [5] +} + +void Widget::index() +{ + //! [6] + QString str = "We must be bold, very bold"; + int j = 0; + + while ((j = str.indexOf("", j)) != -1) { + qDebug() << "Found tag at index position" << j; + ++j; + } + //! [6] +} + +//! [7] +QString Widget::boolToString(bool b) +{ + QString result; + if (b) + result = "True"; + else + result = "False"; + return result; +} +//! [7] + + +void Widget::nullVsEmpty() +{ + //! [8] + QString().isNull(); // returns true + QString().isEmpty(); // returns true + + QString("").isNull(); // returns false + QString("").isEmpty(); // returns true + + QString("abc").isNull(); // returns false + QString("abc").isEmpty(); // returns false + //! [8] +} + +void Widget::appendFunction() +{ + //! [9] + QString x = "free"; + QString y = "dom"; + + x.append(y); + // x == "freedom" + //! [9] + + //! [10] + x.insert(x.size(), y); + //! [10] +} + +void Widget::argFunction() +{ + //! [11] + QString i; // current file's number + QString total; // number of files to process + QString fileName; // current file's name + + QString status = QString("Processing file %1 of %2: %3") + .arg(i).arg(total).arg(fileName); + //! [11] + + //! [12] //! [13] + QString str; + //! [12] + str = "%1 %2"; + + str.arg("%1f", "Hello"); // returns "%1f Hello" + str.arg("%1f").arg("Hello"); // returns "Hellof %2" + //! [13] + + //! [14] + str = QString("Decimal 63 is %1 in hexadecimal") + .arg(63, 0, 16); + // str == "Decimal 63 is 3f in hexadecimal" + + QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); + str = QString("%1 %L2 %L3") + .arg(12345) + .arg(12345) + .arg(12345, 0, 16); + // str == "12345 12,345 3039" + //! [14] +} + +void Widget::chopFunction() +{ + //! [15] + QString str("LOGOUT\r\n"); + str.chop(2); + // str == "LOGOUT" + //! [15] +} + +void Widget::compareFunction() +{ + int x = QString::compare("auto", "auto"); // x == 0 + int y = QString::compare("auto", "car"); // y < 0 + int z = QString::compare("car", "auto"); // z > 0 +} + +void Widget::compareSensitiveFunction() +{ + //! [16] + int x = QString::compare("aUtO", "AuTo", Qt::CaseInsensitive); // x == 0 + int y = QString::compare("auto", "Car", Qt::CaseSensitive); // y > 0 + int z = QString::compare("auto", "Car", Qt::CaseInsensitive); // z < 0 + //! [16] +} + +void Widget::containsFunction() +{ + //! [17] + QString str = "Peter Pan"; + str.contains("peter", Qt::CaseInsensitive); // returns true + //! [17] +} + +void Widget::countFunction() +{ + //! [18] + QString str = "banana and panama"; + str.count(QRegExp("a[nm]a")); // returns 4 + //! [18] + + //! [95] + QString str = "banana and panama"; + str.count(QRegularExpression("a[nm]a")); // returns 4 + //! [95] +} + +void Widget::dataFunction() +{ + //! [19] + QString str = "Hello world"; + QChar *data = str.data(); + while (!data->isNull()) { + qDebug() << data->unicode(); + ++data; + } + //! [19] +} + +void Widget::endsWithFunction() +{ + //! [20] + QString str = "Bananas"; + str.endsWith("anas"); // returns true + str.endsWith("pple"); // returns false + //! [20] +} + +void Widget::fillFunction() +{ + //! [21] + QString str = "Berlin"; + str.fill('z'); + // str == "zzzzzz" + + str.fill('A', 2); + // str == "AA" + //! [21] +} + +void Widget::fromRawDataFunction() +{ + //! [22] + QRegExp pattern; + static const QChar unicode[] = { + 0x005A, 0x007F, 0x00A4, 0x0060, + 0x1009, 0x0020, 0x0020}; + int size = sizeof(unicode) / sizeof(QChar); + + QString str = QString::fromRawData(unicode, size); + if (str.contains(QRegExp(pattern))) { + // ... + //! [22] //! [23] + } + //! [23] +} + +void Widget::indexOfFunction() +{ + //! [24] + QString x = "sticky question"; + QString y = "sti"; + x.indexOf(y); // returns 0 + x.indexOf(y, 1); // returns 10 + x.indexOf(y, 10); // returns 10 + x.indexOf(y, 11); // returns -1 + //! [24] +} + +void Widget::firstIndexOfFunction() +{ + //! [25] + QString str = "the minimum"; + str.indexOf(QRegExp("m[aeiou]"), 0); // returns 4 + //! [25] + + //! [93] + QString str = "the minimum"; + str.indexOf(QRegularExpression("m[aeiou]"), 0); // returns 4 + //! [93] +} + +void Widget::insertFunction() +{ + //! [26] + QString str = "Meal"; + str.insert(1, QString("ontr")); + // str == "Montreal" + //! [26] +} + +void Widget::isEmptyFunction() +{ + //! [27] + QString().isEmpty(); // returns true + QString("").isEmpty(); // returns true + QString("x").isEmpty(); // returns false + QString("abc").isEmpty(); // returns false + //! [27] +} + +void Widget::isNullFunction() +{ + //! [28] + QString().isNull(); // returns true + QString("").isNull(); // returns false + QString("abc").isNull(); // returns false + //! [28] +} + +void Widget::lastIndexOfFunction() +{ + //! [29] + QString x = "crazy azimuths"; + QString y = "az"; + x.lastIndexOf(y); // returns 6 + x.lastIndexOf(y, 6); // returns 6 + x.lastIndexOf(y, 5); // returns 2 + x.lastIndexOf(y, 1); // returns -1 + //! [29] + + //! [30] + QString str = "the minimum"; + str.lastIndexOf(QRegExp("m[aeiou]")); // returns 8 + //! [30] + + //! [94] + QString str = "the minimum"; + str.lastIndexOf(QRegularExpression("m[aeiou]")); // returns 8 + //! [94] +} + +void Widget::leftFunction() +{ + //! [31] + QString x = "Pineapple"; + QString y = x.left(4); // y == "Pine" + //! [31] +} + +void Widget::leftJustifiedFunction() +{ + //! [32] + QString s = "apple"; + QString t = s.leftJustified(8, '.'); // t == "apple..." + //! [32] + + //! [33] + QString str = "Pineapple"; + str = str.leftJustified(5, '.', true); // str == "Pinea" + //! [33] +} + +void Widget::midFunction() +{ + //! [34] + QString x = "Nine pineapples"; + QString y = x.mid(5, 4); // y == "pine" + QString z = x.mid(5); // z == "pineapples" + //! [34] +} + +void Widget::numberFunction() +{ + //! [35] + long a = 63; + QString s = QString::number(a, 16); // s == "3f" + QString t = QString::number(a, 16).toUpper(); // t == "3F" + //! [35] +} + +void Widget::prependFunction() +{ + //! [36] + QString x = "ship"; + QString y = "air"; + x.prepend(y); + // x == "airship" + //! [36] +} + +void Widget::removeFunction() +{ + //! [37] + QString s = "Montreal"; + s.remove(1, 4); + // s == "Meal" + //! [37] + + //! [38] + QString t = "Ali Baba"; + t.remove(QChar('a'), Qt::CaseInsensitive); + // t == "li Bb" + //! [38] + + //! [39] + QString r = "Telephone"; + r.remove(QRegExp("[aeiou].")); + // r == "The" + //! [39] + + //! [96] + QString r = "Telephone"; + r.remove(QRegularExpression("[aeiou].")); + // r == "The" + //! [96] +} + +void Widget::replaceFunction() +{ + //! [40] + QString x = "Say yes!"; + QString y = "no"; + x.replace(4, 3, y); + // x == "Say no!" + //! [40] + + //! [41] + QString str = "colour behaviour flavour neighbour"; + str.replace(QString("ou"), QString("o")); + // str == "color behavior flavor neighbor" + //! [41] + + //! [42] + QString s = "Banana"; + s.replace(QRegExp("a[mn]"), "ox"); + // s == "Boxoxa" + //! [42] + + //! [43] + QString t = "A bon mot."; + t.replace(QRegExp("([^<]*)"), "\\emph{\\1}"); + // t == "A \\emph{bon mot}." + //! [43] + + //! [86] + QString equis = "xxxxxx"; + equis.replace("xx", "x"); + // equis == "xxx" + //! [86] + + //! [87] + QString s = "Banana"; + s.replace(QRegularExpression("a[mn]"), "ox"); + // s == "Boxoxa" + //! [87] + + //! [88] + QString t = "A bon mot."; + t.replace(QRegularExpression("([^<]*)"), "\\emph{\\1}"); + // t == "A \\emph{bon mot}." + //! [88] +} + +void Widget::reserveFunction() +{ + //! [44] + QString result; + int maxSize; + bool condition; + QChar nextChar; + + result.reserve(maxSize); + + while (condition) + result.append(nextChar); + + result.squeeze(); + //! [44] +} + +void Widget::resizeFunction() +{ + //! [45] + QString s = "Hello world"; + s.resize(5); + // s == "Hello" + + s.resize(8); + // s == "Hello???" (where ? stands for any character) + //! [45] + + //! [46] + QString t = "Hello"; + t += QString(10, 'X'); + // t == "HelloXXXXXXXXXX" + //! [46] + + //! [47] + QString r = "Hello"; + r = r.leftJustified(10, ' '); + // r == "Hello " + //! [47] +} + +void Widget::rightFunction() +{ + //! [48] + QString x = "Pineapple"; + QString y = x.right(5); // y == "apple" + //! [48] +} + +void Widget::rightJustifiedFunction() +{ + //! [49] + QString s = "apple"; + QString t = s.rightJustified(8, '.'); // t == "...apple" + //! [49] + + //! [50] + QString str = "Pineapple"; + str = str.rightJustified(5, '.', true); // str == "Pinea" + //! [50] +} + +void Widget::sectionFunction() +{ + //! [51] //! [52] + QString str; + //! [51] + QString csv = "forename,middlename,surname,phone"; + QString path = "/usr/local/bin/myapp"; // First field is empty + QString::SectionFlag flag = QString::SectionSkipEmpty; + + + str = csv.section(',', 2, 2); // str == "surname" + str = path.section('/', 3, 4); // str == "bin/myapp" + str = path.section('/', 3, 3, flag); // str == "myapp" + //! [52] + + //! [53] + str = csv.section(',', -3, -2); // str == "middlename,surname" + str = path.section('/', -1); // str == "myapp" + //! [53] + + //! [54] + QString data = "forename**middlename**surname**phone"; + + str = data.section("**", 2, 2); // str == "surname" + str = data.section("**", -3, -2); // str == "middlename**surname" + //! [54] + + //! [55] + QString line = "forename\tmiddlename surname \t \t phone"; + QRegExp sep("\\s+"); + str = line.section(sep, 2, 2); // str == "surname" + str = line.section(sep, -3, -2); // str == "middlename surname" + //! [55] + + //! [89] + QString line = "forename\tmiddlename surname \t \t phone"; + QRegularExpression sep("\\s+"); + str = line.section(sep, 2, 2); // str == "surname" + str = line.section(sep, -3, -2); // str == "middlename surname" + //! [89] +} + +void Widget::setNumFunction() +{ + //! [56] + QString str; + str.setNum(1234); // str == "1234" + //! [56] +} + +void Widget::simplifiedFunction() +{ + //! [57] + QString str = " lots\t of\nwhitespace\r\n "; + str = str.simplified(); + // str == "lots of whitespace"; + //! [57] +} + +void Widget::sizeFunction() +{ + //! [58] + QString str = "World"; + int n = str.size(); // n == 5 + str.data()[0]; // returns 'W' + str.data()[4]; // returns 'd' + str.data()[5]; // returns '\0' + //! [58] +} + +void Widget::splitFunction() +{ + //! [59] + QString str; + QStringList list; + + str = "Some text\n\twith strange whitespace."; + list = str.split(QRegExp("\\s+")); + // list: [ "Some", "text", "with", "strange", "whitespace." ] + //! [59] + + //! [60] + str = "This time, a normal English sentence."; + list = str.split(QRegExp("\\W+"), QString::SkipEmptyParts); + // list: [ "This", "time", "a", "normal", "English", "sentence" ] + //! [60] + + //! [61] + str = "Now: this sentence fragment."; + list = str.split(QRegExp("\\b")); + // list: [ "", "Now", ": ", "this", " ", "sentence", " ", "fragment", "." ] + //! [61] + + //! [90] + QString str; + QStringList list; + + str = "Some text\n\twith strange whitespace."; + list = str.split(QRegularExpression("\\s+")); + // list: [ "Some", "text", "with", "strange", "whitespace." ] + //! [90] + + //! [91] + str = "This time, a normal English sentence."; + list = str.split(QRegularExpression("\\W+"), QString::SkipEmptyParts); + // list: [ "This", "time", "a", "normal", "English", "sentence" ] + //! [91] + + //! [92] + str = "Now: this sentence fragment."; + list = str.split(QRegularExpression("\\b")); + // list: [ "", "Now", ": ", "this", " ", "sentence", " ", "fragment", "." ] + //! [92] +} + +void Widget::splitCaseSensitiveFunction() +{ + //! [62] + QString str = "a,,b,c"; + + QStringList list1 = str.split(","); + // list1: [ "a", "", "b", "c" ] + + QStringList list2 = str.split(",", QString::SkipEmptyParts); + // list2: [ "a", "b", "c" ] + //! [62] +} + +void Widget::sprintfFunction() +{ + //! [63] + size_t BufSize; + char buf[BufSize]; + + ::snprintf(buf, BufSize, "%lld", 123456789LL); + QString str = QString::fromAscii(buf); + //! [63] + + //! [64] + QString result; + QTextStream(&result) << "pi = " << 3.14; + // result == "pi = 3.14" + //! [64] +} + +void Widget::startsWithFunction() +{ + //! [65] + QString str = "Bananas"; + str.startsWith("Ban"); // returns true + str.startsWith("Car"); // returns false + //! [65] +} + +void Widget::toDoubleFunction() +{ + //! [66] + QString str = "1234.56"; + double val = str.toDouble(); // val == 1234.56 + //! [66] + + //! [67] + bool ok; + double d; + + d = QString( "1234.56e-02" ).toDouble(&ok); // ok == true, d == 12.3456 + //! [67] + + //! [68] + d = QString( "1234,56" ).toDouble(&ok); // ok == false + d = QString( "1234.56" ).toDouble(&ok); // ok == true, d == 1234.56 + //! [68] + + //! [69] + d = QString( "1,234,567.89" ).toDouble(&ok); // ok == false + d = QString( "1234567.89" ).toDouble(&ok); // ok == true + //! [69] +} + +void Widget::toFloatFunction() +{ + //! [71] + QString str1 = "1234.56"; + str1.toFloat(); // returns 1234.56 + + bool ok; + QString str2 = "R2D2"; + str2.toFloat(&ok); // returns 0.0, sets ok to false + //! [71] +} + +void Widget::toIntFunction() +{ + //! [72] + QString str = "FF"; + bool ok; + int hex = str.toInt(&ok, 16); // hex == 255, ok == true + int dec = str.toInt(&ok, 10); // dec == 0, ok == false + //! [72] +} + +void Widget::toLongFunction() +{ + //! [73] + QString str = "FF"; + bool ok; + + long hex = str.toLong(&ok, 16); // hex == 255, ok == true + long dec = str.toLong(&ok, 10); // dec == 0, ok == false + //! [73] +} + +void Widget::toLongLongFunction() +{ + //! [74] + QString str = "FF"; + bool ok; + + qint64 hex = str.toLongLong(&ok, 16); // hex == 255, ok == true + qint64 dec = str.toLongLong(&ok, 10); // dec == 0, ok == false + //! [74] +} + +void Widget::toLowerFunction() +{ + //! [75] + QString str = "Qt by NOKIA"; + str = str.toLower(); // str == "qt by nokia" + //! [75] +} + +void Widget::toShortFunction() +{ + //! [76] + QString str = "FF"; + bool ok; + + short hex = str.toShort(&ok, 16); // hex == 255, ok == true + short dec = str.toShort(&ok, 10); // dec == 0, ok == false + //! [76] +} + +void Widget::toUIntFunction() +{ + //! [77] + QString str = "FF"; + bool ok; + + uint hex = str.toUInt(&ok, 16); // hex == 255, ok == true + uint dec = str.toUInt(&ok, 10); // dec == 0, ok == false + //! [77] +} + +void Widget::toULongFunction() +{ + //! [78] + QString str = "FF"; + bool ok; + + ulong hex = str.toULong(&ok, 16); // hex == 255, ok == true + ulong dec = str.toULong(&ok, 10); // dec == 0, ok == false + //! [78] +} + +void Widget::toULongLongFunction() +{ + //! [79] + QString str = "FF"; + bool ok; + + quint64 hex = str.toULongLong(&ok, 16); // hex == 255, ok == true + quint64 dec = str.toULongLong(&ok, 10); // dec == 0, ok == false + //! [79] +} + +void Widget::toUShortFunction() +{ + //! [80] + QString str = "FF"; + bool ok; + + ushort hex = str.toUShort(&ok, 16); // hex == 255, ok == true + ushort dec = str.toUShort(&ok, 10); // dec == 0, ok == false + //! [80] +} + +void Widget::toUpperFunction() +{ + //! [81] + QString str = "TeXt"; + str = str.toUpper(); // str == "TEXT" + //! [81] +} + +void Widget::trimmedFunction() +{ + //! [82] + QString str = " lots\t of\nwhitespace\r\n "; + str = str.trimmed(); + // str == "lots\t of\nwhitespace" + //! [82] +} + +void Widget::truncateFunction() +{ + //! [83] + QString str = "Vladivostok"; + str.truncate(4); + // str == "Vlad" + //! [83] +} + +void Widget::plusEqualOperator() +{ + //! [84] + QString x = "free"; + QString y = "dom"; + x += y; + // x == "freedom" + //! [84] +} + +void Widget::arrayOperator() +{ + //! [85] + QString str; + + if (str[0] == QChar('?')) + str[0] = QChar('_'); + //! [85] +} + +void Widget::midRefFunction() +{ + //! [midRef] + QString x = "Nine pineapples"; + QStringRef y = x.midRef(5, 4); // y == "pine" + QStringRef z = x.midRef(5); // z == "pineapples" + //! [midRef] +} + +void Widget::leftRefFunction() +{ + //! [leftRef] + QString x = "Pineapple"; + QStringRef y = x.leftRef(4); // y == "Pine" + //! [leftRef] +} + +void Widget::rightRefFunction() +{ + //! [rightRef] + QString x = "Pineapple"; + QStringRef y = x.rightRef(5); // y == "apple" + //! [rightRef] +} + + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Widget widget; + widget.show(); + return app.exec(); +} diff --git a/src/corelib/doc/snippets/qstring/stringbuilder.cpp b/src/corelib/doc/snippets/qstring/stringbuilder.cpp new file mode 100644 index 0000000000..53cf0b7be0 --- /dev/null +++ b/src/corelib/doc/snippets/qstring/stringbuilder.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QString foo; + QString type = "long"; + + foo->setText(QLatin1String("vector<") + type + QLatin1String(">::iterator")); + + if (foo.startsWith("(" + type + ") 0x")) + ... +//! [0] + +//! [3] + DEFINES *= QT_USE_QSTRINGBUILDER +//! [3] + +//! [5] + #include + + QString hello("hello"); + QStringRef el(&hello, 2, 3); + QLatin1String world("world"); + QString message = hello % el % world % QChar('!'); +//! [5] diff --git a/src/corelib/doc/snippets/qstringlist/main.cpp b/src/corelib/doc/snippets/qstringlist/main.cpp new file mode 100644 index 0000000000..8ca463371e --- /dev/null +++ b/src/corelib/doc/snippets/qstringlist/main.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +using namespace std; + +class Widget : public QWidget +{ +public: + Widget(QWidget *parent = 0); +}; + +Widget::Widget(QWidget *parent) + : QWidget(parent) +{ +//! [0] + QStringList fonts; + fonts << "Arial" << "Helvetica" << "Times" << "Courier"; +//! [0] + +//! [1] + for (int i = 0; i < fonts.size(); ++i) + cout << fonts.at(i).toLocal8Bit().constData() << endl; +//! [1] + +//! [2] + QStringListIterator javaStyleIterator(fonts); + while (javaStyleIterator.hasNext()) + cout << javaStyleIterator.next().toLocal8Bit().constData() << endl; +//! [2] + +//! [3] + QStringList::const_iterator constIterator; + for (constIterator = fonts.constBegin(); constIterator != fonts.constEnd(); + ++constIterator) + cout << (*constIterator).toLocal8Bit().constData() << endl; +//! [3] + +//! [4] + QString str = fonts.join(","); + // str == "Arial,Helvetica,Times,Courier" +//! [4] + +//! [5] //! [6] + QStringList list; +//! [5] + list = str.split(","); + // list: ["Arial", "Helvetica", "Times", "Courier"] +//! [6] + +//! [7] + QStringList monospacedFonts = fonts.filter(QRegExp("Courier|Fixed")); +//! [7] + +//! [8] + QStringList files; + files << "$QTDIR/src/moc/moc.y" + << "$QTDIR/src/moc/moc.l" + << "$QTDIR/include/qconfig.h"; + + files.replaceInStrings("$QTDIR", "/usr/lib/qt"); + // files: [ "/usr/lib/qt/src/moc/moc.y", ...] +//! [8] + + QString str1, str2, str3; +//! [9] + QStringList longerList = (QStringList() << str1 << str2 << str3); +//! [9] + + list.clear(); +//! [10] + list << "Bill Murray" << "John Doe" << "Bill Clinton"; + +//! [11] + QStringList result; +//! [11] + result = list.filter("Bill"); + // result: ["Bill Murray", "Bill Clinton"] +//! [10] + + result.clear(); +//! [12] + foreach (const QString &str, list) { + if (str.contains("Bill")) + result += str; + } +//! [12] + + list.clear(); +//! [13] + list << "alpha" << "beta" << "gamma" << "epsilon"; + list.replaceInStrings("a", "o"); + // list == ["olpho", "beto", "gommo", "epsilon"] +//! [13] + + list.clear(); +//! [14] + list << "alpha" << "beta" << "gamma" << "epsilon"; + list.replaceInStrings(QRegExp("^a"), "o"); + // list == ["olpha", "beta", "gamma", "epsilon"] +//! [14] + + list.clear(); +//! [15] + list << "Bill Clinton" << "Murray, Bill"; + list.replaceInStrings(QRegExp("^(.*), (.*)$"), "\\2 \\1"); + // list == ["Bill Clinton", "Bill Murray"] +//! [15] + + list.clear(); +//! [16] + list << "alpha" << "beta" << "gamma" << "epsilon"; + list.replaceInStrings(QRegularExpression("^a"), "o"); + // list == ["olpha", "beta", "gamma", "epsilon"] +//! [16] + + list.clear(); +//! [17] + list << "Bill Clinton" << "Murray, Bill"; + list.replaceInStrings(QRegularExpression("^(.*), (.*)$"), "\\2 \\1"); + // list == ["Bill Clinton", "Bill Murray"] +//! [17] + +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Widget widget; + widget.show(); + return app.exec(); +} diff --git a/src/corelib/doc/snippets/qstringlistmodel/main.cpp b/src/corelib/doc/snippets/qstringlistmodel/main.cpp new file mode 100644 index 0000000000..24de0fd0ae --- /dev/null +++ b/src/corelib/doc/snippets/qstringlistmodel/main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +class Widget : public QWidget +{ +public: + Widget(QWidget *parent = 0); +}; + +Widget::Widget(QWidget *parent) + : QWidget(parent) +{ +//! [0] + QStringListModel *model = new QStringListModel(); + QStringList list; + list << "a" << "b" << "c"; + model->setStringList(list); +//! [0] +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Widget widget; + widget.show(); + return app.exec(); +} diff --git a/src/corelib/doc/snippets/qtcast/qtcast.cpp b/src/corelib/doc/snippets/qtcast/qtcast.cpp new file mode 100644 index 0000000000..f0c3834bf0 --- /dev/null +++ b/src/corelib/doc/snippets/qtcast/qtcast.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "qtcast.h" + +MyWidget::MyWidget() +{ +//! [0] + QObject *obj = new MyWidget; +//! [0] + +//! [1] + QWidget *widget = qobject_cast(obj); +//! [1] + +//! [2] + MyWidget *myWidget = qobject_cast(obj); +//! [2] + +//! [3] + QLabel *label = qobject_cast(obj); +//! [3] //! [4] + // label is 0 +//! [4] + +//! [5] + if (QLabel *label = qobject_cast(obj)) { +//! [5] //! [6] + label->setText(tr("Ping")); + } else if (QPushButton *button = qobject_cast(obj)) { + button->setText(tr("Pong!")); + } +//! [6] +} + +int main() +{ + return 0; +} diff --git a/src/corelib/doc/snippets/qxmlstreamwriter/main.cpp b/src/corelib/doc/snippets/qxmlstreamwriter/main.cpp new file mode 100644 index 0000000000..907d779357 --- /dev/null +++ b/src/corelib/doc/snippets/qxmlstreamwriter/main.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + QFile output; + output.open(stdout, QIODevice::WriteOnly); +//! [write output] +//! [start stream] + QXmlStreamWriter stream(&output); + stream.setAutoFormatting(true); + stream.writeStartDocument(); +//! [start stream] + stream.writeDTD(""); + stream.writeStartElement("xbel"); + stream.writeAttribute("version", "1.0"); + stream.writeStartElement("folder"); + stream.writeAttribute("folded", "no"); +//! [write element] + stream.writeStartElement("bookmark"); + stream.writeAttribute("href", "http://qt.nokia.com/"); + stream.writeTextElement("title", "Qt Home"); + stream.writeEndElement(); // bookmark +//! [write element] + stream.writeEndElement(); // folder + stream.writeEndElement(); // xbel +//! [finish stream] + stream.writeEndDocument(); +//! [finish stream] +//! [write output] + output.close(); + return 0; +} diff --git a/src/corelib/doc/snippets/settings/settings.cpp b/src/corelib/doc/snippets/settings/settings.cpp new file mode 100644 index 0000000000..8648843d43 --- /dev/null +++ b/src/corelib/doc/snippets/settings/settings.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QWidget *win; +QWidget *panel; + +void snippet_ctor1() +{ +//! [0] + QSettings settings("MySoft", "Star Runner"); +//! [0] +} + +void snippet_ctor2() +{ +//! [1] + QCoreApplication::setOrganizationName("MySoft"); +//! [1] //! [2] + QCoreApplication::setOrganizationDomain("mysoft.com"); +//! [2] //! [3] + QCoreApplication::setApplicationName("Star Runner"); +//! [3] + +//! [4] + QSettings settings; +//! [4] + +//! [5] + settings.setValue("editor/wrapMargin", 68); +//! [5] //! [6] + int margin = settings.value("editor/wrapMargin").toInt(); +//! [6] + { +//! [7] + int margin = settings.value("editor/wrapMargin", 80).toInt(); +//! [7] + } + +//! [8] + settings.setValue("mainwindow/size", win->size()); +//! [8] //! [9] + settings.setValue("mainwindow/fullScreen", win->isFullScreen()); +//! [9] //! [10] + settings.setValue("outputpanel/visible", panel->isVisible()); +//! [10] + +//! [11] + settings.beginGroup("mainwindow"); + settings.setValue("size", win->size()); + settings.setValue("fullScreen", win->isFullScreen()); + settings.endGroup(); +//! [11] + +//! [12] + settings.beginGroup("outputpanel"); + settings.setValue("visible", panel->isVisible()); + settings.endGroup(); +//! [12] +} + +void snippet_locations() +{ +//! [13] + QSettings obj1("MySoft", "Star Runner"); +//! [13] //! [14] + QSettings obj2("MySoft"); + QSettings obj3(QSettings::SystemScope, "MySoft", "Star Runner"); + QSettings obj4(QSettings::SystemScope, "MySoft"); +//! [14] + + { +//! [15] + QSettings settings(QSettings::IniFormat, QSettings::UserScope, + "MySoft", "Star Runner"); +//! [15] + } + + { + QSettings settings("starrunner.ini", QSettings::IniFormat); + } + + { + QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft", + QSettings::NativeFormat); + } +} + +class MainWindow : public QMainWindow +{ +public: + MainWindow(); + + void writeSettings(); + void readSettings(); + +protected: + void closeEvent(QCloseEvent *event); +}; + +//! [16] +void MainWindow::writeSettings() +{ + QSettings settings("Moose Soft", "Clipper"); + + settings.beginGroup("MainWindow"); + settings.setValue("size", size()); + settings.setValue("pos", pos()); + settings.endGroup(); +} +//! [16] + +//! [17] +void MainWindow::readSettings() +{ + QSettings settings("Moose Soft", "Clipper"); + + settings.beginGroup("MainWindow"); + resize(settings.value("size", QSize(400, 400)).toSize()); + move(settings.value("pos", QPoint(200, 200)).toPoint()); + settings.endGroup(); +} +//! [17] + +//! [18] +MainWindow::MainWindow() +{ +//! [18] //! [19] + readSettings(); +//! [19] //! [20] +} +//! [20] + +bool userReallyWantsToQuit() { return true; } + +//! [21] +void MainWindow::closeEvent(QCloseEvent *event) +{ + if (userReallyWantsToQuit()) { + writeSettings(); + event->accept(); + } else { + event->ignore(); + } +} +//! [21] diff --git a/src/corelib/doc/snippets/sharedemployee/employee.h b/src/corelib/doc/snippets/sharedemployee/employee.h new file mode 100644 index 0000000000..efb1d32000 --- /dev/null +++ b/src/corelib/doc/snippets/sharedemployee/employee.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef EMPLOYEE_H +#define EMPLOYEE_H + +//! [0] +#include +#include + +class EmployeeData : public QSharedData +{ + public: + EmployeeData() : id(-1) { } + EmployeeData(const EmployeeData &other) + : QSharedData(other), id(other.id), name(other.name) { } + ~EmployeeData() { } + + int id; + QString name; +}; + +class Employee +{ + public: +//! [1] + Employee() { d = new EmployeeData; } +//! [1] //! [2] + Employee(int id, QString name) { + d = new EmployeeData; + setId(id); + setName(name); + } +//! [2] //! [7] + Employee(const Employee &other) + : d (other.d) + { + } +//! [7] +//! [3] + void setId(int id) { d->id = id; } +//! [3] //! [4] + void setName(QString name) { d->name = name; } +//! [4] + +//! [5] + int id() const { return d->id; } +//! [5] //! [6] + QString name() const { return d->name; } +//! [6] + + private: + QSharedDataPointer d; +}; +//! [0] + +#endif diff --git a/src/corelib/doc/snippets/sharedemployee/main.cpp b/src/corelib/doc/snippets/sharedemployee/main.cpp new file mode 100644 index 0000000000..6e840ab5e6 --- /dev/null +++ b/src/corelib/doc/snippets/sharedemployee/main.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#include "employee.h" + +int main() +{ + Employee e1(1001, "Albrecht Durer"); + Employee e2 = e1; + e1.setName("Hans Holbein"); +} +//! [0] diff --git a/src/corelib/doc/snippets/signalmapper/filereader.cpp b/src/corelib/doc/snippets/signalmapper/filereader.cpp new file mode 100644 index 0000000000..067ba8280e --- /dev/null +++ b/src/corelib/doc/snippets/signalmapper/filereader.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the config.tests of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "filereader.h" + + +FileReader::FileReader(QWidget *parent) + : QWidget(parent) +{ + textEdit = new QTextEdit; + + taxFileButton = new QPushButton("Tax File"); + accountFileButton = new QPushButton("Accounts File"); + reportFileButton = new QPushButton("Report File"); + +//! [0] + signalMapper = new QSignalMapper(this); + signalMapper->setMapping(taxFileButton, QString("taxfile.txt")); + signalMapper->setMapping(accountFileButton, QString("accountsfile.txt")); + signalMapper->setMapping(reportFileButton, QString("reportfile.txt")); + + connect(taxFileButton, &QPushButton::clicked, + signalMapper, &QSignalMapper::map); + connect(accountFileButton, &QPushButton::clicked, + signalMapper, &QSignalMapper::map); + connect(reportFileButton, &QPushButton::clicked, + signalMapper, &QSignalMapper::map); +//! [0] + +//! [1] + connect(signalMapper, SIGNAL(mapped(QString)), + this, SLOT(readFile(QString))); +//! [1] + +/* +//! [2] + //slower due to signature normalization at runtime + + connect(signalMapper, SIGNAL(mapped(const QString &)), + this, SLOT(readFile(const QString &))); +//! [2] +*/ + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addWidget(taxFileButton); + buttonLayout->addWidget(accountFileButton); + buttonLayout->addWidget(reportFileButton); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(textEdit); + mainLayout->addLayout(buttonLayout); + + setLayout(mainLayout); +} + +void FileReader::readFile(const QString &filename) +{ + QFile file(filename); + + if (!file.open(QIODevice::ReadOnly)) { + QMessageBox::information(this, tr("Unable to open file"), + file.errorString()); + return; + } + + + QTextStream in(&file); + textEdit->setPlainText(in.readAll()); +} + diff --git a/src/corelib/doc/snippets/signalsandslots/lcdnumber.h b/src/corelib/doc/snippets/signalsandslots/lcdnumber.h new file mode 100644 index 0000000000..7056254f9f --- /dev/null +++ b/src/corelib/doc/snippets/signalsandslots/lcdnumber.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#ifndef LCDNUMBER_H +//! [0] //! [1] +#define LCDNUMBER_H +//! [1] + +//! [2] +#include +//! [2] + +//! [3] +class LcdNumber : public QFrame +//! [3] //! [4] +{ +//! [4] //! [5] + Q_OBJECT +//! [5] + +//! [6] +public: +//! [6] //! [7] + LcdNumber(QWidget *parent = 0); +//! [7] + +//! [8] +signals: +//! [8] //! [9] + void overflow(); +//! [9] + +//! [10] +public slots: +//! [10] //! [11] + void display(int num); + void display(double num); + void display(const QString &str); + void setHexMode(); + void setDecMode(); + void setOctMode(); + void setBinMode(); + void setSmallDecimalPoint(bool point); +//! [11] //! [12] +}; +//! [12] + +//! [13] +#endif +//! [13] diff --git a/src/corelib/doc/snippets/signalsandslots/signalsandslots.cpp b/src/corelib/doc/snippets/signalsandslots/signalsandslots.cpp new file mode 100644 index 0000000000..3072650585 --- /dev/null +++ b/src/corelib/doc/snippets/signalsandslots/signalsandslots.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "signalsandslots.h" + +//! [0] +void Counter::setValue(int value) +{ + if (value != m_value) { + m_value = value; + emit valueChanged(value); + } +} +//! [0] + +int main() +{ +//! [1] + Counter a, b; +//! [1] //! [2] + QObject::connect(&a, &Counter::valueChanged, + &b, &Counter::setValue); +//! [2] + +//! [3] + a.setValue(12); // a.value() == 12, b.value() == 12 +//! [3] //! [4] + b.setValue(48); // a.value() == 12, b.value() == 48 +//! [4] + + + QWidget *widget = reinterpret_cast(new QObject(0)); +//! [5] + if (widget->inherits("QAbstractButton")) { + QAbstractButton *button = static_cast(widget); + button->toggle(); +//! [5] //! [6] + } +//! [6] + +//! [7] + if (QAbstractButton *button = qobject_cast(widget)) + button->toggle(); +//! [7] +} diff --git a/src/corelib/doc/snippets/signalsandslots/signalsandslots.h b/src/corelib/doc/snippets/signalsandslots/signalsandslots.h new file mode 100644 index 0000000000..e18f955a41 --- /dev/null +++ b/src/corelib/doc/snippets/signalsandslots/signalsandslots.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SIGNALSANDSLOTS_H +#define SIGNALSANDSLOTS_H + +#define Counter PlainCounter + +//! [0] +class Counter +{ +public: + Counter() { m_value = 0; } + + int value() const { return m_value; } + void setValue(int value); + +private: + int m_value; +}; +//! [0] + +#undef Counter +#define Counter ObjectCounter + +//! [1] +#include +//! [1] + +//! [2] +class Counter : public QObject +//! [2] //! [3] +{ + Q_OBJECT + +public: + Counter() { m_value = 0; } + + int value() const { return m_value; } + +public slots: + void setValue(int value); + +signals: + void valueChanged(int newValue); + +private: + int m_value; +}; +//! [3] + +#endif diff --git a/src/corelib/doc/snippets/streaming/main.cpp b/src/corelib/doc/snippets/streaming/main.cpp new file mode 100644 index 0000000000..7c992345c2 --- /dev/null +++ b/src/corelib/doc/snippets/streaming/main.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +//! [0] +struct Movie +{ + int id; + QString title; + QDate releaseDate; +}; +//! [0] + +//! [1] +QDataStream &operator<<(QDataStream &out, const Movie &movie) +{ + out << (quint32)movie.id << movie.title + << movie.releaseDate; + return out; +} +//! [1] + +//! [2] +QDataStream &operator>>(QDataStream &in, Movie &movie) +{ + quint32 id; + QDate date; + + in >> id >> movie.title >> date; + movie.id = (int)id; + movie.releaseDate = date; + return in; +} +//! [2] + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + Movie m; + m.id = 0001; + m.title = "Happy Meal"; + m.releaseDate = QDate(1995, 5, 17); + + QByteArray byteArray; + QDataStream stream(&byteArray, QIODevice::WriteOnly); + stream << m; + + // display + qDebug() << m.id << m.releaseDate << m.title; + + Movie m2; + + int id2; + QString title2; + QDate date2; + + QDataStream stream2(byteArray); + stream2 >> id2 >> title2 >> date2; + + m2.id = id2; + m2.title = title2; + m2.releaseDate = date2; + + qDebug() << id2 << " " << date2 << " " << title2; + + return 0; +} diff --git a/src/corelib/doc/snippets/streaming/streaming.pro b/src/corelib/doc/snippets/streaming/streaming.pro new file mode 100644 index 0000000000..8c5eb91f05 --- /dev/null +++ b/src/corelib/doc/snippets/streaming/streaming.pro @@ -0,0 +1,2 @@ +SOURCES = main.cpp +CONFIG += CONSOLE \ No newline at end of file diff --git a/src/corelib/doc/snippets/threads/threads.cpp b/src/corelib/doc/snippets/threads/threads.cpp new file mode 100644 index 0000000000..9ef716705a --- /dev/null +++ b/src/corelib/doc/snippets/threads/threads.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#include "threads.h" + +//! [0] +void MyThread::run() +//! [0] //! [1] +{ +//! [1] //! [2] +} +//! [2] + +#define Counter ReentrantCounter + +//! [3] +class Counter +//! [3] //! [4] +{ +public: + Counter() { n = 0; } + + void increment() { ++n; } + void decrement() { --n; } + int value() const { return n; } + +private: + int n; +}; +//! [4] + +#undef Counter +#define Counter ThreadSafeCounter + +//! [5] +class Counter +//! [5] //! [6] +{ +public: + Counter() { n = 0; } + + void increment() { QMutexLocker locker(&mutex); ++n; } + void decrement() { QMutexLocker locker(&mutex); --n; } + int value() const { QMutexLocker locker(&mutex); return n; } + +private: + mutable QMutex mutex; + int n; +}; +//! [6] + +typedef int SomeClass; + +//! [7] +QThreadStorage > caches; + +void cacheObject(const QString &key, SomeClass *object) +//! [7] //! [8] +{ + caches.localData().insert(key, object); +} + +void removeFromCache(const QString &key) +//! [8] //! [9] +{ + if (!caches.hasLocalData()) + return; + + caches.localData().remove(key); +} +//! [9] + +int main() +{ + return 0; +} diff --git a/src/corelib/doc/snippets/threads/threads.h b/src/corelib/doc/snippets/threads/threads.h new file mode 100644 index 0000000000..a45a2c92da --- /dev/null +++ b/src/corelib/doc/snippets/threads/threads.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +//! [0] +class MyThread : public QThread +{ + Q_OBJECT + +protected: + void run(); +}; +//! [0] diff --git a/src/corelib/doc/snippets/timers/timers.cpp b/src/corelib/doc/snippets/timers/timers.cpp new file mode 100644 index 0000000000..65b1c0d146 --- /dev/null +++ b/src/corelib/doc/snippets/timers/timers.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +class Foo : public QObject +{ +public: + Foo(); +}; + +Foo::Foo() +{ +//! [0] + QTimer *timer = new QTimer(this); +//! [0] //! [1] + connect(timer, SIGNAL(timeout()), this, SLOT(updateCaption())); +//! [1] //! [2] + timer->start(1000); +//! [2] + +//! [3] + QTimer::singleShot(200, this, SLOT(updateCaption())); +//! [3] + + { + // ZERO-CASE +//! [4] + QTimer *timer = new QTimer(this); +//! [4] //! [5] + connect(timer, SIGNAL(timeout()), this, SLOT(processOneThing())); +//! [5] //! [6] + timer->start(); +//! [6] + } +} + +int main() +{ + +} diff --git a/src/corelib/doc/src/containers.qdoc b/src/corelib/doc/src/containers.qdoc new file mode 100644 index 0000000000..8419a92dcf --- /dev/null +++ b/src/corelib/doc/src/containers.qdoc @@ -0,0 +1,803 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \group tools + \title Non-GUI Classes + \ingroup groups + + \brief Collection classes such as list, queue, stack and string, along + with other classes that can be used without needing QApplication. + + The non-GUI classes are general-purpose collection and string classes + that may be used independently of the GUI classes. + + In particular, these classes do not depend on QApplication at all, + and so can be used in non-GUI programs. + +*/ + +/*! + \page containers.html + \title Container Classes + \ingroup technology-apis + \ingroup groups + \ingroup qt-basic-concepts + \keyword container class + \keyword container classes + + \brief Qt's template-based container classes. + + \tableofcontents + + \section1 Introduction + + The Qt library provides a set of general purpose template-based + container classes. These classes can be used to store items of a + specified type. For example, if you need a resizable array of + \l{QString}s, use QVector. + + These container classes are designed to be lighter, safer, and + easier to use than the STL containers. If you are unfamiliar with + the STL, or prefer to do things the "Qt way", you can use these + classes instead of the STL classes. + + The container classes are \l{implicitly shared}, they are + \l{reentrant}, and they are optimized for speed, low memory + consumption, and minimal inline code expansion, resulting in + smaller executables. In addition, they are \l{thread-safe} + in situations where they are used as read-only containers + by all threads used to access them. + + For traversing the items stored in a container, you can use one + of two types of iterators: \l{Java-style iterators} and + \l{STL-style iterators}. The Java-style iterators are easier to + use and provide high-level functionality, whereas the STL-style + iterators are slightly more efficient and can be used together + with Qt's and STL's \l{generic algorithms}. + + Qt also offers a \l{foreach} keyword that make it very + easy to iterate over all the items stored in a container. + + \section1 The Container Classes + + Qt provides the following sequential containers: QList, + QLinkedList, QVector, QStack, and QQueue. For most + applications, QList is the best type to use. Although it is + implemented as an array-list, it provides very fast prepends and + appends. If you really need a linked-list, use QLinkedList; if you + want your items to occupy consecutive memory locations, use QVector. + QStack and QQueue are convenience classes that provide LIFO and + FIFO semantics. + + Qt also provides these associative containers: QMap, + QMultiMap, QHash, QMultiHash, and QSet. The "Multi" containers + conveniently support multiple values associated with a single + key. The "Hash" containers provide faster lookup by using a hash + function instead of a binary search on a sorted set. + + As special cases, the QCache and QContiguousCache classes provide + efficient hash-lookup of objects in a limited cache storage. + + \table + \header \li Class \li Summary + + \row \li \l{QList} + \li This is by far the most commonly used container class. It + stores a list of values of a given type (T) that can be accessed + by index. Internally, the QList is implemented using an array, + ensuring that index-based access is very fast. + + Items can be added at either end of the list using + QList::append() and QList::prepend(), or they can be inserted in + the middle using QList::insert(). More than any other container + class, QList is highly optimized to expand to as little code as + possible in the executable. QStringList inherits from + QList. + + \row \li \l{QLinkedList} + \li This is similar to QList, except that it uses + iterators rather than integer indexes to access items. It also + provides better performance than QList when inserting in the + middle of a huge list, and it has nicer iterator semantics. + (Iterators pointing to an item in a QLinkedList remain valid as + long as the item exists, whereas iterators to a QList can become + invalid after any insertion or removal.) + + \row \li \l{QVector} + \li This stores an array of values of a given type at adjacent + positions in memory. Inserting at the front or in the middle of + a vector can be quite slow, because it can lead to large numbers + of items having to be moved by one position in memory. + + \row \li \l{QStack} + \li This is a convenience subclass of QVector that provides + "last in, first out" (LIFO) semantics. It adds the following + functions to those already present in QVector: + \l{QStack::push()}{push()}, \l{QStack::pop()}{pop()}, + and \l{QStack::top()}{top()}. + + \row \li \l{QQueue} + \li This is a convenience subclass of QList that provides + "first in, first out" (FIFO) semantics. It adds the following + functions to those already present in QList: + \l{QQueue::enqueue()}{enqueue()}, + \l{QQueue::dequeue()}{dequeue()}, and \l{QQueue::head()}{head()}. + + \row \li \l{QSet} + \li This provides a single-valued mathematical set with fast + lookups. + + \row \li \l{QMap} + \li This provides a dictionary (associative array) that maps keys + of type Key to values of type T. Normally each key is associated + with a single value. QMap stores its data in Key order; if order + doesn't matter QHash is a faster alternative. + + \row \li \l{QMultiMap} + \li This is a convenience subclass of QMap that provides a nice + interface for multi-valued maps, i.e. maps where one key can be + associated with multiple values. + + \row \li \l{QHash} + \li This has almost the same API as QMap, but provides + significantly faster lookups. QHash stores its data in an + arbitrary order. + + \row \li \l{QMultiHash} + \li This is a convenience subclass of QHash that + provides a nice interface for multi-valued hashes. + + \endtable + + Containers can be nested. For example, it is perfectly possible + to use a QMap >, where the key type is + QString and the value type QList. The only pitfall is that + you must insert a space between the closing angle brackets (>); + otherwise the C++ compiler will misinterpret the two >'s as a + right-shift operator (>>) and report a syntax error. + + The containers are defined in individual header files with the + same name as the container (e.g., \c ). For + convenience, the containers are forward declared in \c + . + + \keyword assignable data type + \keyword assignable data types + + The values stored in the various containers can be of any + \e{assignable data type}. To qualify, a type must provide a + default constructor, a copy constructor, and an assignment + operator. This covers most data types you are likely to want to + store in a container, including basic types such as \c int and \c + double, pointer types, and Qt data types such as QString, QDate, + and QTime, but it doesn't cover QObject or any QObject subclass + (QWidget, QDialog, QTimer, etc.). If you attempt to instantiate a + QList, the compiler will complain that QWidget's copy + constructor and assignment operators are disabled. If you want to + store these kinds of objects in a container, store them as + pointers, for example as QList. + + Here's an example custom data type that meets the requirement of + an assignable data type: + + \snippet code/doc_src_containers.cpp 0 + + If we don't provide a copy constructor or an assignment operator, + C++ provides a default implementation that performs a + member-by-member copy. In the example above, that would have been + sufficient. Also, if you don't provide any constructors, C++ + provides a default constructor that initializes its member using + default constructors. Although it doesn't provide any + explicit constructors or assignment operator, the following data + type can be stored in a container: + + \snippet streaming/main.cpp 0 + + Some containers have additional requirements for the data types + they can store. For example, the Key type of a QMap must + provide \c operator<(). Such special requirements are documented + in a class's detailed description. In some cases, specific + functions have special requirements; these are described on a + per-function basis. The compiler will always emit an error if a + requirement isn't met. + + Qt's containers provide operator<<() and operator>>() so that they + can easily be read and written using a QDataStream. This means + that the data types stored in the container must also support + operator<<() and operator>>(). Providing such support is + straightforward; here's how we could do it for the Movie struct + above: + + \snippet streaming/main.cpp 1 + \codeline + \snippet streaming/main.cpp 2 + + \keyword default-constructed values + + The documentation of certain container class functions refer to + \e{default-constructed values}; for example, QVector + automatically initializes its items with default-constructed + values, and QMap::value() returns a default-constructed value if + the specified key isn't in the map. For most value types, this + simply means that a value is created using the default + constructor (e.g. an empty string for QString). But for primitive + types like \c{int} and \c{double}, as well as for pointer types, + the C++ language doesn't specify any initialization; in those + cases, Qt's containers automatically initialize the value to 0. + + \section1 The Iterator Classes + + Iterators provide a uniform means to access items in a container. + Qt's container classes provide two types of iterators: Java-style + iterators and STL-style iterators. Iterators of both types are + invalidated when the data in the container is modified or detached + from \l{Implicit Sharing}{implicitly shared copies} due to a call + to a non-const member function. + + \section2 Java-Style Iterators + + The Java-style iterators are new in Qt 4 and are the standard + ones used in Qt applications. They are more convenient to use than + the STL-style iterators, at the price of being slightly less + efficient. Their API is modelled on Java's iterator classes. + + For each container class, there are two Java-style iterator data + types: one that provides read-only access and one that provides + read-write access. + + \table + \header \li Containers \li Read-only iterator + \li Read-write iterator + \row \li QList, QQueue \li QListIterator + \li QMutableListIterator + \row \li QLinkedList \li QLinkedListIterator + \li QMutableLinkedListIterator + \row \li QVector, QStack \li QVectorIterator + \li QMutableVectorIterator + \row \li QSet \li QSetIterator + \li QMutableSetIterator + \row \li QMap, QMultiMap \li QMapIterator + \li QMutableMapIterator + \row \li QHash, QMultiHash \li QHashIterator + \li QMutableHashIterator + \endtable + + In this discussion, we will concentrate on QList and QMap. The + iterator types for QLinkedList, QVector, and QSet have exactly + the same interface as QList's iterators; similarly, the iterator + types for QHash have the same interface as QMap's iterators. + + Unlike STL-style iterators (covered \l{STL-style + iterators}{below}), Java-style iterators point \e between items + rather than directly \e at items. For this reason, they are + either pointing to the very beginning of the container (before + the first item), at the very end of the container (after the last + item), or between two items. The diagram below shows the valid + iterator positions as red arrows for a list containing four + items: + + \image javaiterators1.png + + Here's a typical loop for iterating through all the elements of a + QList in order and printing them to the console: + + \snippet code/doc_src_containers.cpp 1 + + It works as follows: The QList to iterate over is passed to the + QListIterator constructor. At that point, the iterator is located + just in front of the first item in the list (before item "A"). + Then we call \l{QListIterator::hasNext()}{hasNext()} to + check whether there is an item after the iterator. If there is, we + call \l{QListIterator::next()}{next()} to jump over that + item. The next() function returns the item that it jumps over. For + a QList, that item is of type QString. + + Here's how to iterate backward in a QList: + + \snippet code/doc_src_containers.cpp 2 + + The code is symmetric with iterating forward, except that we + start by calling \l{QListIterator::toBack()}{toBack()} + to move the iterator after the last item in the list. + + The diagram below illustrates the effect of calling + \l{QListIterator::next()}{next()} and + \l{QListIterator::previous()}{previous()} on an iterator: + + \image javaiterators2.png + + The following table summarizes the QListIterator API: + + \table + \header \li Function \li Behavior + \row \li \l{QListIterator::toFront()}{toFront()} + \li Moves the iterator to the front of the list (before the first item) + \row \li \l{QListIterator::toBack()}{toBack()} + \li Moves the iterator to the back of the list (after the last item) + \row \li \l{QListIterator::hasNext()}{hasNext()} + \li Returns true if the iterator isn't at the back of the list + \row \li \l{QListIterator::next()}{next()} + \li Returns the next item and advances the iterator by one position + \row \li \l{QListIterator::peekNext()}{peekNext()} + \li Returns the next item without moving the iterator + \row \li \l{QListIterator::hasPrevious()}{hasPrevious()} + \li Returns true if the iterator isn't at the front of the list + \row \li \l{QListIterator::previous()}{previous()} + \li Returns the previous item and moves the iterator back by one position + \row \li \l{QListIterator::peekPrevious()}{peekPrevious()} + \li Returns the previous item without moving the iterator + \endtable + + QListIterator provides no functions to insert or remove items + from the list as we iterate. To accomplish this, you must use + QMutableListIterator. Here's an example where we remove all + odd numbers from a QList using QMutableListIterator: + + \snippet code/doc_src_containers.cpp 3 + + The next() call in the loop is made every time. It jumps over the + next item in the list. The + \l{QMutableListIterator::remove()}{remove()} function removes the + last item that we jumped over from the list. The call to + \l{QMutableListIterator::remove()}{remove()} does not invalidate + the iterator, so it is safe to continue using it. This works just + as well when iterating backward: + + \snippet code/doc_src_containers.cpp 4 + + If we just want to modify the value of an existing item, we can + use \l{QMutableListIterator::setValue()}{setValue()}. In the code + below, we replace any value larger than 128 with 128: + + \snippet code/doc_src_containers.cpp 5 + + Just like \l{QMutableListIterator::remove()}{remove()}, + \l{QMutableListIterator::setValue()}{setValue()} operates on the + last item that we jumped over. If we iterate forward, this is the + item just before the iterator; if we iterate backward, this is + the item just after the iterator. + + The \l{QMutableListIterator::next()}{next()} function returns a + non-const reference to the item in the list. For simple + operations, we don't even need + \l{QMutableListIterator::setValue()}{setValue()}: + + \snippet code/doc_src_containers.cpp 6 + + As mentioned above, QLinkedList's, QVector's, and QSet's iterator + classes have exactly the same API as QList's. We will now turn to + QMapIterator, which is somewhat different because it iterates on + (key, value) pairs. + + Like QListIterator, QMapIterator provides + \l{QMapIterator::toFront()}{toFront()}, + \l{QMapIterator::toBack()}{toBack()}, + \l{QMapIterator::hasNext()}{hasNext()}, + \l{QMapIterator::next()}{next()}, + \l{QMapIterator::peekNext()}{peekNext()}, + \l{QMapIterator::hasPrevious()}{hasPrevious()}, + \l{QMapIterator::previous()}{previous()}, and + \l{QMapIterator::peekPrevious()}{peekPrevious()}. The key and + value components are extracted by calling key() and value() on + the object returned by next(), peekNext(), previous(), or + peekPrevious(). + + The following example removes all (capital, country) pairs where + the capital's name ends with "City": + + \snippet code/doc_src_containers.cpp 7 + + QMapIterator also provides a key() and a value() function that + operate directly on the iterator and that return the key and + value of the last item that the iterator jumped above. For + example, the following code copies the contents of a QMap into a + QHash: + + \snippet code/doc_src_containers.cpp 8 + + If we want to iterate through all the items with the same + value, we can use \l{QMapIterator::findNext()}{findNext()} + or \l{QMapIterator::findPrevious()}{findPrevious()}. + Here's an example where we remove all the items with a particular + value: + + \snippet code/doc_src_containers.cpp 9 + + \section2 STL-Style Iterators + + STL-style iterators have been available since the release of Qt + 2.0. They are compatible with Qt's and STL's \l{generic + algorithms} and are optimized for speed. + + For each container class, there are two STL-style iterator types: + one that provides read-only access and one that provides + read-write access. Read-only iterators should be used wherever + possible because they are faster than read-write iterators. + + \table + \header \li Containers \li Read-only iterator + \li Read-write iterator + \row \li QList, QQueue \li QList::const_iterator + \li QList::iterator + \row \li QLinkedList \li QLinkedList::const_iterator + \li QLinkedList::iterator + \row \li QVector, QStack \li QVector::const_iterator + \li QVector::iterator + \row \li QSet \li QSet::const_iterator + \li QSet::iterator + \row \li QMap, QMultiMap \li QMap::const_iterator + \li QMap::iterator + \row \li QHash, QMultiHash \li QHash::const_iterator + \li QHash::iterator + \endtable + + The API of the STL iterators is modelled on pointers in an array. + For example, the \c ++ operator advances the iterator to the next + item, and the \c * operator returns the item that the iterator + points to. In fact, for QVector and QStack, which store their + items at adjacent memory positions, the + \l{QVector::iterator}{iterator} type is just a typedef for \c{T *}, + and the \l{QVector::iterator}{const_iterator} type is + just a typedef for \c{const T *}. + + In this discussion, we will concentrate on QList and QMap. The + iterator types for QLinkedList, QVector, and QSet have exactly + the same interface as QList's iterators; similarly, the iterator + types for QHash have the same interface as QMap's iterators. + + Here's a typical loop for iterating through all the elements of a + QList in order and converting them to lowercase: + + \snippet code/doc_src_containers.cpp 10 + + Unlike \l{Java-style iterators}, STL-style iterators point + directly at items. The begin() function of a container returns an + iterator that points to the first item in the container. The + end() function of a container returns an iterator to the + imaginary item one position past the last item in the container. + end() marks an invalid position; it must never be dereferenced. + It is typically used in a loop's break condition. If the list is + empty, begin() equals end(), so we never execute the loop. + + The diagram below shows the valid iterator positions as red + arrows for a vector containing four items: + + \image stliterators1.png + + Iterating backward with an STL-style iterator requires us to + decrement the iterator \e before we access the item. This + requires a \c while loop: + + \snippet code/doc_src_containers.cpp 11 + + In the code snippets so far, we used the unary \c * operator to + retrieve the item (of type QString) stored at a certain iterator + position, and we then called QString::toLower() on it. Most C++ + compilers also allow us to write \c{i->toLower()}, but some + don't. + + For read-only access, you can use const_iterator, constBegin(), + and constEnd(). For example: + + \snippet code/doc_src_containers.cpp 12 + + The following table summarizes the STL-style iterators' API: + + \table + \header \li Expression \li Behavior + \row \li \c{*i} \li Returns the current item + \row \li \c{++i} \li Advances the iterator to the next item + \row \li \c{i += n} \li Advances the iterator by \c n items + \row \li \c{--i} \li Moves the iterator back by one item + \row \li \c{i -= n} \li Moves the iterator back by \c n items + \row \li \c{i - j} \li Returns the number of items between iterators \c i and \c j + \endtable + + The \c{++} and \c{--} operators are available both as prefix + (\c{++i}, \c{--i}) and postfix (\c{i++}, \c{i--}) operators. The + prefix versions modify the iterators and return a reference to + the modified iterator; the postfix versions take a copy of the + iterator before they modify it, and return that copy. In + expressions where the return value is ignored, we recommend that + you use the prefix operators (\c{++i}, \c{--i}), as these are + slightly faster. + + For non-const iterator types, the return value of the unary \c{*} + operator can be used on the left side of the assignment operator. + + For QMap and QHash, the \c{*} operator returns the value + component of an item. If you want to retrieve the key, call key() + on the iterator. For symmetry, the iterator types also provide a + value() function to retrieve the value. For example, here's how + we would print all items in a QMap to the console: + + \snippet code/doc_src_containers.cpp 13 + + Thanks to \l{implicit sharing}, it is very inexpensive for a + function to return a container per value. The Qt API contains + dozens of functions that return a QList or QStringList per value + (e.g., QSplitter::sizes()). If you want to iterate over these + using an STL iterator, you should always take a copy of the + container and iterate over the copy. For example: + + \snippet code/doc_src_containers.cpp 14 + + This problem doesn't occur with functions that return a const or + non-const reference to a container. + + \l{Implicit sharing} has another consequence on STL-style + iterators: You must not take a copy of a container while + non-const iterators are active on that container. Java-style + iterators don't suffer from that limitation. + + \keyword foreach + \section1 The foreach Keyword + + If you just want to iterate over all the items in a container + in order, you can use Qt's \c foreach keyword. The keyword is a + Qt-specific addition to the C++ language, and is implemented + using the preprocessor. + + Its syntax is: \c foreach (\e variable, \e container) \e + statement. For example, here's how to use \c foreach to iterate + over a QLinkedList: + + \snippet code/doc_src_containers.cpp 15 + + The \c foreach code is significantly shorter than the equivalent + code that uses iterators: + + \snippet code/doc_src_containers.cpp 16 + + Unless the data type contains a comma (e.g., \c{QPair}), the variable used for iteration can be defined within the + \c foreach statement: + + \snippet code/doc_src_containers.cpp 17 + + And like any other C++ loop construct, you can use braces around + the body of a \c foreach loop, and you can use \c break to leave + the loop: + + \snippet code/doc_src_containers.cpp 18 + + With QMap and QHash, \c foreach accesses the value component of + the (key, value) pairs. If you want to iterate over both the keys + and the values, you can use iterators (which are fastest), or you + can write code like this: + + \snippet code/doc_src_containers.cpp 19 + + For a multi-valued map: + + \snippet code/doc_src_containers.cpp 20 + + Qt automatically takes a copy of the container when it enters a + \c foreach loop. If you modify the container as you are + iterating, that won't affect the loop. (If you do not modify the + container, the copy still takes place, but thanks to \l{implicit + sharing} copying a container is very fast.) + + Since foreach creates a copy of the container, using a non-const + reference for the variable does not allow you to modify the original + container. It only affects the copy, which is probably not what you + want. + + In addition to \c foreach, Qt also provides a \c forever + pseudo-keyword for infinite loops: + + \snippet code/doc_src_containers.cpp 21 + + If you're worried about namespace pollution, you can disable + these macros by adding the following line to your \c .pro file: + + \snippet code/doc_src_containers.cpp 22 + + \section1 Other Container-Like Classes + + Qt includes three template classes that resemble containers in + some respects. These classes don't provide iterators and cannot + be used with the \c foreach keyword. + + \list + \li QVarLengthArray provides a low-level + variable-length array. It can be used instead of QVector in + places where speed is particularly important. + + \li QCache provides a cache to store objects of a certain + type T associated with keys of type Key. + + \li QContiguousCache provides an efficient way of caching data + that is typically accessed in a contiguous way. + + \li QPair stores a pair of elements. + \endlist + + Additional non-template types that compete with Qt's template + containers are QBitArray, QByteArray, QString, and QStringList. + + \section1 Algorithmic Complexity + + Algorithmic complexity is concerned about how fast (or slow) each + function is as the number of items in the container grow. For + example, inserting an item in the middle of a QLinkedList is an + extremely fast operation, irrespective of the number of items + stored in the QLinkedList. On the other hand, inserting an item + in the middle of a QVector is potentially very expensive if the + QVector contains many items, since half of the items must be + moved one position in memory. + + To describe algorithmic complexity, we use the following + terminology, based on the "big Oh" notation: + + \keyword constant time + \keyword logarithmic time + \keyword linear time + \keyword linear-logarithmic time + \keyword quadratic time + + \list + \li \b{Constant time:} O(1). A function is said to run in constant + time if it requires the same amount of time no matter how many + items are present in the container. One example is + QLinkedList::insert(). + + \li \b{Logarithmic time:} O(log \e n). A function that runs in + logarithmic time is a function whose running time is + proportional to the logarithm of the number of items in the + container. One example is qBinaryFind(). + + \li \b{Linear time:} O(\e n). A function that runs in linear time + will execute in a time directly proportional to the number of + items stored in the container. One example is + QVector::insert(). + + \li \b{Linear-logarithmic time:} O(\e{n} log \e n). A function + that runs in linear-logarithmic time is asymptotically slower + than a linear-time function, but faster than a quadratic-time + function. + + \li \b{Quadratic time:} O(\e{n}\unicode{178}). A quadratic-time function + executes in a time that is proportional to the square of the + number of items stored in the container. + \endlist + + The following table summarizes the algorithmic complexity of Qt's + sequential container classes: + + \table + \header \li \li Index lookup \li Insertion \li Prepending \li Appending + \row \li QLinkedList \li O(\e n) \li O(1) \li O(1) \li O(1) + \row \li QList \li O(1) \li O(n) \li Amort. O(1) \li Amort. O(1) + \row \li QVector \li O(1) \li O(n) \li O(n) \li Amort. O(1) + \endtable + + In the table, "Amort." stands for "amortized behavior". For + example, "Amort. O(1)" means that if you call the function + only once, you might get O(\e n) behavior, but if you call it + multiple times (e.g., \e n times), the average behavior will be + O(1). + + The following table summarizes the algorithmic complexity of Qt's + associative containers and sets: + + \table + \header \li{1,2} \li{2,1} Key lookup \li{2,1} Insertion + \header \li Average \li Worst case \li Average \li Worst case + \row \li QMap \li O(log \e n) \li O(log \e n) \li O(log \e n) \li O(log \e n) + \row \li QMultiMap \li O(log \e n) \li O(log \e n) \li O(log \e n) \li O(log \e n) + \row \li QHash \li Amort. O(1) \li O(\e n) \li Amort. O(1) \li O(\e n) + \row \li QSet \li Amort. O(1) \li O(\e n) \li Amort. O(1) \li O(\e n) + \endtable + + With QVector, QHash, and QSet, the performance of appending items + is amortized O(log \e n). It can be brought down to O(1) by + calling QVector::reserve(), QHash::reserve(), or QSet::reserve() + with the expected number of items before you insert the items. + The next section discusses this topic in more depth. + + \section1 Growth Strategies + + QVector, QString, and QByteArray store their items + contiguously in memory; QList maintains an array of pointers + to the items it stores to provide fast index-based access (unless + T is a pointer type or a basic type of the size of a pointer, in + which case the value itself is stored in the array); QHash keeps a hash table whose size is proportional to the number + of items in the hash. To avoid reallocating the data every single + time an item is added at the end of the container, these classes + typically allocate more memory than necessary. + + Consider the following code, which builds a QString from another + QString: + + \snippet code/doc_src_containers.cpp 23 + + We build the string \c out dynamically by appending one character + to it at a time. Let's assume that we append 15000 characters to + the QString string. Then the following 18 reallocations (out of a + possible 15000) occur when QString runs out of space: 4, 8, 12, + 16, 20, 52, 116, 244, 500, 1012, 2036, 4084, 6132, 8180, 10228, + 12276, 14324, 16372. At the end, the QString has 16372 Unicode + characters allocated, 15000 of which are occupied. + + The values above may seem a bit strange, but here are the guiding + principles: + \list + \li QString allocates 4 characters at a time until it reaches size 20. + \li From 20 to 4084, it advances by doubling the size each time. + More precisely, it advances to the next power of two, minus + 12. (Some memory allocators perform worst when requested exact + powers of two, because they use a few bytes per block for + book-keeping.) + \li From 4084 on, it advances by blocks of 2048 characters (4096 + bytes). This makes sense because modern operating systems + don't copy the entire data when reallocating a buffer; the + physical memory pages are simply reordered, and only the data + on the first and last pages actually needs to be copied. + \endlist + + QByteArray and QList use more or less the same algorithm as + QString. + + QVector also uses that algorithm for data types that can be + moved around in memory using memcpy() (including the basic C++ + types, the pointer types, and Qt's \l{shared classes}) but uses a + different algorithm for data types that can only be moved by + calling the copy constructor and a destructor. Since the cost of + reallocating is higher in that case, QVector reduces the + number of reallocations by always doubling the memory when + running out of space. + + QHash is a totally different case. QHash's internal hash + table grows by powers of two, and each time it grows, the items + are relocated in a new bucket, computed as qHash(\e key) % + QHash::capacity() (the number of buckets). This remark applies to + QSet and QCache as well. + + For most applications, the default growing algorithm provided by + Qt does the trick. If you need more control, QVector, + QHash, QSet, QString, and QByteArray provide a trio of + functions that allow you to check and specify how much memory to + use to store the items: + + \list + \li \l{QString::capacity()}{capacity()} returns the + number of items for which memory is allocated (for QHash and + QSet, the number of buckets in the hash table). + \li \l{QString::reserve()}{reserve}(\e size) explicitly + preallocates memory for \e size items. + \li \l{QString::squeeze()}{squeeze()} frees any memory + not required to store the items. + \endlist + + If you know approximately how many items you will store in a + container, you can start by calling reserve(), and when you are + done populating the container, you can call squeeze() to release + the extra preallocated memory. +*/ diff --git a/src/corelib/doc/src/datastreamformat.qdoc b/src/corelib/doc/src/datastreamformat.qdoc new file mode 100644 index 0000000000..8ff31371a2 --- /dev/null +++ b/src/corelib/doc/src/datastreamformat.qdoc @@ -0,0 +1,373 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page datastreamformat.html + \title Serializing Qt Data Types + \ingroup qt-network + \brief Representations of data types that can be serialized by QDataStream. + + The \l QDataStream allows you to serialize some of the Qt data types. + The table below lists the data types that QDataStream can serialize + and how they are represented. The format described below is + \l{QDataStream::setVersion()}{version 12}. + + It is always best to cast integers to a Qt integer type, such as + qint16 or quint32, when reading and writing. This ensures that + you always know exactly what size integers you are reading and + writing, no matter what the underlying platform and architecture + the application happens to be running on. + + \table + \row \li bool + \li \list + \li boolean + \endlist + \row \li qint8 + \li \list + \li signed byte + \endlist + \row \li qint16 + \li \list + \li signed 16-bit integer + \endlist + \row \li qint32 + \li \list + \li signed 32-bit integer + \endlist + \row \li qint64 + \li \list + \li signed 64-bit integer + \endlist + \row \li quint8 + \li \list + \li unsigned byte + \endlist + \row \li quint16 + \li \list + \li unsigned 16-bit integer + \endlist + \row \li quint32 + \li \list + \li unsigned 32-bit integer + \endlist + \row \li quint64 + \li \list + \li unsigned 64-bit integer + \endlist + \row \li \c float + \li \list + \li 32-bit floating point number using the standard IEEE 754 format + \endlist + \row \li \c double + \li \list + \li 64-bit floating point number using the standard IEEE 754 format + \endlist + \row \li \c {const char *} + \li \list + \li The string length (quint32) + \li The string bytes, excluding the terminating 0 + \endlist + \row \li QBitArray + \li \list + \li The array size (quint32) + \li The array bits, i.e. (size + 7)/8 bytes + \endlist + \row \li QBrush + \li \list + \li The brush style (quint8) + \li The brush color (QColor) + \li If style is CustomPattern, the brush pixmap (QPixmap) + \endlist + \row \li QByteArray + \li \list + \li If the byte array is null: 0xFFFFFFFF (quint32) + \li Otherwise: the array size (quint32) followed by the array bytes, i.e. size bytes + \endlist + \row \li \l QColor + \li \list + \li Color spec (qint8) + \li Alpha value (quint16) + \li Red value (quint16) + \li Green value (quint16) + \li Blue value (quint16) + \li Pad value (quint16) + \endlist + \row \li QCursor + \li \list + \li Shape ID (qint16) + \li If shape is BitmapCursor: The bitmap (QPixmap), mask (QPixmap), and hot spot (QPoint) + \endlist + \row \li QDate + \li \list + \li Julian day (quint32) + \endlist + \row \li QDateTime + \li \list + \li Date (QDate) + \li Time (QTime) + \li 0 for Qt::LocalTime, 1 for Qt::UTC (quint8) + \endlist + \row \li QEasingCurve + \li \list + \li type (quint8) + \li func (quint64) + \li hasConfig (bool) + \li If hasConfig is true then these fields follow: + \li list + \li period (double) + \li amplitude (double) + \li overshoot (double) + \endlist + \row \li QFont + \li \list + \li The family (QString) + \li The point size (qint16) + \li The style hint (quint8) + \li The char set (quint8) + \li The weight (quint8) + \li The font bits (quint8) + \endlist + \row \li QHash + \li \list + \li The number of items (quint32) + \li For all items, the key (Key) and value (T) + \endlist + \row \li QIcon + \li \list + \li The number of pixmap entries (quint32) + \li For all pixmap entries: + \list + \li The pixmap (QPixmap) + \li The file name (QString) + \li The pixmap size (QSize) + \li The \l{QIcon::Mode}{mode} (quint32) + \li The \l{QIcon::State}{state} (quint32) + \endlist + \endlist + \row \li QImage + \li \list + \li If the image is null a "null image" marker is saved; + otherwise the image is saved in PNG or BMP format (depending + on the stream version). If you want control of the format, + stream the image into a QBuffer (using QImageIO) and stream + that. + \endlist + \row \li QKeySequence + \li \list + \li A QList, where each integer is a key in the key sequence + \endlist + \row \li QLinkedList + \li \list + \li The number of items (quint32) + \li The items (T) + \endlist + \row \li QList + \li \list + \li The number of items (quint32) + \li The items (T) + \endlist + \row \li QMap + \li \list + \li The number of items (quint32) + \li For all items, the key (Key) and value (T) + \endlist + \row \li QMargins + \li \list + \li left (int) + \li top (int) + \li right (int) + \li bottom (int) + \endlist + \row \li QMatrix + \li \list + \li m11 (double) + \li m12 (double) + \li m21 (double) + \li m22 (double) + \li dx (double) + \li dy (double) + \endlist + \row \li QMatrix4x4 + \li \list + \li m11 (double) + \li m12 (double) + \li m13 (double) + \li m14 (double) + \li m21 (double) + \li m22 (double) + \li m23 (double) + \li m24 (double) + \li m31 (double) + \li m32 (double) + \li m33 (double) + \li m34 (double) + \li m41 (double) + \li m42 (double) + \li m43 (double) + \li m44 (double) + \endlist + \row \li QPair + \li \list + \li first (T1) + \li second (T2) + \endlist + \row \li QPalette + \li The disabled, active, and inactive color groups, each of which consists + of the following: + \list + \li foreground (QBrush) + \li button (QBrush) + \li light (QBrush) + \li midlight (QBrush) + \li dark (QBrush) + \li mid (QBrush) + \li text (QBrush) + \li brightText (QBrush) + \li buttonText (QBrush) + \li base (QBrush) + \li background (QBrush) + \li shadow (QBrush) + \li highlight (QBrush) + \li highlightedText (QBrush) + \li link (QBrush) + \li linkVisited (QBrush) + \endlist + \row \li QPen + \li \list + \li The pen styles (quint8) + \li The pen width (quint16) + \li The pen color (QColor) + \endlist + \row \li QPicture + \li \list + \li The size of the picture data (quint32) + \li The raw bytes of picture data (char) + \endlist + \row \li QPixmap + \li \list + \li Save it as a PNG image. + \endlist + \row \li QPoint + \li \list + \li The x coordinate (qint32) + \li The y coordinate (qint32) + \endlist + \row \li QQuaternion + \li \list + \li The scalar component (double) + \li The x coordinate (double) + \li The y coordinate (double) + \li The z coordinate (double) + \endlist + \row \li QRect + \li \list + \li left (qint32) + \li top (qint32) + \li right (qint32) + \li bottom (qint32) + \endlist + \row \li QRegExp + \li \list + \li The regexp pattern (QString) + \li Case sensitivity (quint8) + \li Regular expression syntax (quint8) + \li Minimal matching (quint8) + \endlist + \row \li QRegularExpression + \li \list + \li The regular expression pattern (QString) + \li The pattern options (quint32) + \endlist + \row \li QRegion + \li \list + \li The size of the data, i.e. 8 + 16 * (number of rectangles) (quint32) + \li 10 (qint32) + \li The number of rectangles (quint32) + \li The rectangles in sequential order (QRect) + \endlist + \row \li QSize + \li \list + \li width (qint32) + \li height (qint32) + \endlist + \row \li QString + \li \list + \li If the string is null: 0xFFFFFFFF (quint32) + \li Otherwise: The string length in bytes (quint32) followed by the data in UTF-16 + \endlist + \row \li QTime + \li \list + \li Milliseconds since midnight (quint32) + \endlist + \row \li QTransform + \li \list + \li m11 (double) + \li m12 (double) + \li m13 (double) + \li m21 (double) + \li m22 (double) + \li m23 (double) + \li m31 (double) + \li m32 (double) + \li m33 (double) + \endlist + \row \li QUrl + \li \list + \li Holds an URL (QString) + \endlist + \row \li QVariant + \li \list + \li The type of the data (quint32) + \li The null flag (qint8) + \li The data of the specified type + \endlist + \row \li QVector2D + \li \list + \li the x coordinate (double) + \li the y coordinate (double) + \endlist + \row \li QVector3D + \li \list + \li the x coordinate (double) + \li the y coordinate (double) + \li the z coordinate (double) + \endlist + \row \li QVector4D + \li \list + \li the x coordinate (double) + \li the y coordinate (double) + \li the z coordinate (double) + \li the w coordinate (double) + \endlist + \row \li QVector + \li \list + \li The number of items (quint32) + \li The items (T) + \endlist + \endtable +*/ diff --git a/src/corelib/doc/src/implicit-sharing.qdoc b/src/corelib/doc/src/implicit-sharing.qdoc new file mode 100644 index 0000000000..6fc60de35e --- /dev/null +++ b/src/corelib/doc/src/implicit-sharing.qdoc @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* TODO: Move some of the documentation from QSharedDataPointer into this + document. */ + +/*! + \group shared + \title Implicitly Shared Classes +*/ + +/*! + \page implicit-sharing.html + \title Implicit Sharing + \ingroup qt-basic-concepts + + \brief Reference counting for fast copying. + + \keyword implicit data sharing + \keyword implicit sharing + \keyword implicitly shared + \keyword reference counting + \keyword shared implicitly + \keyword shared classes + + Many C++ classes in Qt use implicit data sharing to maximize + resource usage and minimize copying. Implicitly shared classes are + both safe and efficient when passed as arguments, because only a + pointer to the data is passed around, and the data is copied only + if and when a function writes to it, i.e., \e {copy-on-write}. + + \tableofcontents + + \section1 Overview + + A shared class consists of a pointer to a shared data block that + contains a reference count and the data. + + When a shared object is created, it sets the reference count to 1. The + reference count is incremented whenever a new object references the + shared data, and decremented when the object dereferences the shared + data. The shared data is deleted when the reference count becomes + zero. + + \keyword deep copy + \keyword shallow copy + + When dealing with shared objects, there are two ways of copying an + object. We usually speak about \e deep and \e shallow copies. A deep + copy implies duplicating an object. A shallow copy is a reference + copy, i.e. just a pointer to a shared data block. Making a deep copy + can be expensive in terms of memory and CPU. Making a shallow copy is + very fast, because it only involves setting a pointer and incrementing + the reference count. + + Object assignment (with operator=()) for implicitly shared objects is + implemented using shallow copies. + + The benefit of sharing is that a program does not need to duplicate + data unnecessarily, which results in lower memory use and less copying + of data. Objects can easily be assigned, sent as function arguments, + and returned from functions. + + Implicit sharing takes place behind the scenes; the programmer + does not need to worry about it. Even in multithreaded + applications, implicit sharing takes place, as explained in + \l{Thread-Support in Qt Modules#Threads and Implicitly Shared Classes} + {Threads and Implicitly Shared Classes}. + + When implementing your own implicitly shared classes, use the + QSharedData and QSharedDataPointer classes. + + \section1 Implicit Sharing in Detail + + Implicit sharing automatically detaches the object from a shared + block if the object is about to change and the reference count is + greater than one. (This is often called \e {copy-on-write} or + \e {value semantics}.) + + An implicitly shared class has total control of its internal data. In + any member functions that modify its data, it automatically detaches + before modifying the data. + + The QPen class, which uses implicit sharing, detaches from the shared + data in all member functions that change the internal data. + + Code fragment: + \snippet code/doc_src_groups.cpp 0 + + + \section1 List of Classes + + The classes listed below automatically detach from common data if + an object is about to be changed. The programmer will not even + notice that the objects are shared. Thus you should treat + separate instances of them as separate objects. They will always + behave as separate objects but with the added benefit of sharing + data whenever possible. For this reason, you can pass instances + of these classes as arguments to functions by value without + concern for the copying overhead. + + Example: + \snippet code/doc_src_groups.cpp 1 + + In this example, \c p1 and \c p2 share data until QPainter::begin() + is called for \c p2, because painting a pixmap will modify it. + + \warning Do not copy an implicitly shared container (QMap, + QVector, etc.) while you are iterating over it using an non-const + \l{STL-style iterator}. + + \keyword implicitly shared classes + \annotatedlist shared +*/ diff --git a/src/corelib/doc/src/json.qdoc b/src/corelib/doc/src/json.qdoc new file mode 100644 index 0000000000..406135cc45 --- /dev/null +++ b/src/corelib/doc/src/json.qdoc @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \group json + \title JSON Classes +*/ + +/*! + \page json.html + \title JSON Support in Qt + \ingroup qt-basic-concepts + \brief An overview over the JSON support in Qt. + + \ingroup frameworks-technologies + + \keyword JSON + + Qt provides support for dealing with JSON data. JSON is a + format to encode object data derived from Javascript, but + now widely used as a data exchange format on the internet. + + The JSON support in Qt provides an easy to use C++ API to parse, + modify and save JSON data. It also contains support for saving this + data in a binary format that is directly mmap'able and very fast to + access. + + More details about the JSON data format can be found at \l{http://json.org}{json.org} + and in \l{http://tools.ietf.org/html/rfc4627}{RFC-4627}. + + \tableofcontents + + \section1 Overview + + JSON is a format to store structured data. It has 6 basic data types: + + \list + \li bool + \li double + \li string + \li array + \li object + \li null + \endlist + + Any value can be any of the above type. A boolean value is represented by the + strings true or false in JSON. JSON doesn't explicitly specify the valid range + for numbers, but the support in Qt is limited to the valid range and precision of + doubles. A string can be any valid unicode string. An array is a list of values, and an + object is a dictionary of key/value pairs. All keys in an object are strings, and + an object cannot contain any duplicated keys. + + The text representation, of JSON encloses arrays in square brackets ([ ... ]) and + objects in curly brackets ({ ... }). The different entries in arrays and objects + are separated by commas. The separator between keys and values in an object is a + colon (:). + + A simple JSON document encoding a person, its age, address and phone numbers could + look like: + + \code + { + "FirstName": "John", + "LastName": "Doe", + "Age": 43, + "Address": { + "Street": "Downing Street 10", + "City": "London", + "Country": "Great Britain" + }, + "Phone numbers": [ + "+44 1234567", + "+44 2345678" + ] + } + \endcode + + The above example consists of an object with 5 key/value pairs. Two of the values are strings, + one is a number, one is another object and the last one an array. + + A valid JSON document is either an array or an object, so a document always starts + with a square or curly bracket. + + The JSON support in Qt consists of a set of 4 classes. + + + \section1 The JSON Classes + + The JSON support in Qt consists of these classes: + + \annotatedlist json + + All JSON classes are value based, implicitly shared classes. +*/ diff --git a/src/corelib/doc/src/objectmodel/metaobjects.qdoc b/src/corelib/doc/src/objectmodel/metaobjects.qdoc new file mode 100644 index 0000000000..8e071be91e --- /dev/null +++ b/src/corelib/doc/src/objectmodel/metaobjects.qdoc @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page metaobjects.html + \title The Meta-Object System + \brief An overview of Qt's meta-object system and introspection capabilities. + + \ingroup qt-basic-concepts + \keyword meta-object + \target Meta-Object System + + Qt's meta-object system provides the signals and slots mechanism for + inter-object communication, run-time type information, and the dynamic + property system. + + The meta-object system is based on three things: + + \list 1 + \li The \l QObject class provides a base class for objects that can + take advantage of the meta-object system. + \li The Q_OBJECT macro inside the private section of the class + declaration is used to enable meta-object features, such as + dynamic properties, signals, and slots. + \li The \l{moc}{Meta-Object Compiler} (\c moc) supplies each + QObject subclass with the necessary code to implement + meta-object features. + \endlist + + The \c moc tool reads a C++ source file. If it finds one or more + class declarations that contain the Q_OBJECT macro, it + produces another C++ source file which contains the meta-object + code for each of those classes. This generated source file is + either \c{#include}'d into the class's source file or, more + usually, compiled and linked with the class's implementation. + + In addition to providing the \l{signals and slots} mechanism for + communication between objects (the main reason for introducing + the system), the meta-object code provides the following + additional features: + + \list + \li QObject::metaObject() returns the associated + \l{QMetaObject}{meta-object} for the class. + \li QMetaObject::className() returns the class name as a + string at run-time, without requiring native run-time type information + (RTTI) support through the C++ compiler. + \li QObject::inherits() function returns whether an object is an + instance of a class that inherits a specified class within the + QObject inheritance tree. + \li QObject::tr() and QObject::trUtf8() translate strings for + \l{Internationalization with Qt}{internationalization}. + \li QObject::setProperty() and QObject::property() + dynamically set and get properties by name. + \li QMetaObject::newInstance() constructs a new instance of the class. + \endlist + + \target qobjectcast + It is also possible to perform dynamic casts using qobject_cast() + on QObject classes. The qobject_cast() function behaves similarly + to the standard C++ \c dynamic_cast(), with the advantages + that it doesn't require RTTI support and it works across dynamic + library boundaries. It attempts to cast its argument to the pointer + type specified in angle-brackets, returning a non-zero pointer if the + object is of the correct type (determined at run-time), or 0 + if the object's type is incompatible. + + For example, let's assume \c MyWidget inherits from QWidget and + is declared with the Q_OBJECT macro: + + \snippet qtcast/qtcast.cpp 0 + + The \c obj variable, of type \c{QObject *}, actually refers to a + \c MyWidget object, so we can cast it appropriately: + + \snippet qtcast/qtcast.cpp 1 + + The cast from QObject to QWidget is successful, because the + object is actually a \c MyWidget, which is a subclass of QWidget. + Since we know that \c obj is a \c MyWidget, we can also cast it to + \c{MyWidget *}: + + \snippet qtcast/qtcast.cpp 2 + + The cast to \c MyWidget is successful because qobject_cast() + makes no distinction between built-in Qt types and custom types. + + \snippet qtcast/qtcast.cpp 3 + \snippet qtcast/qtcast.cpp 4 + + The cast to QLabel, on the other hand, fails. The pointer is then + set to 0. This makes it possible to handle objects of different + types differently at run-time, based on the type: + + \snippet qtcast/qtcast.cpp 5 + \snippet qtcast/qtcast.cpp 6 + + While it is possible to use QObject as a base class without the + Q_OBJECT macro and without meta-object code, neither signals + and slots nor the other features described here will be available + if the Q_OBJECT macro is not used. From the meta-object + system's point of view, a QObject subclass without meta code is + equivalent to its closest ancestor with meta-object code. This + means for example, that QMetaObject::className() will not return + the actual name of your class, but the class name of this + ancestor. + + Therefore, we strongly recommend that all subclasses of QObject + use the Q_OBJECT macro regardless of whether or not they + actually use signals, slots, and properties. + + \sa QMetaObject, {Qt's Property System}, {Signals and Slots} +*/ diff --git a/src/corelib/doc/src/objectmodel/object.qdoc b/src/corelib/doc/src/objectmodel/object.qdoc new file mode 100644 index 0000000000..4e212b37dd --- /dev/null +++ b/src/corelib/doc/src/objectmodel/object.qdoc @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page object.html + \title Object Model + \ingroup qt-basic-concepts + \brief A description of the powerful features made possible by Qt's dynamic object model. + + The standard C++ object model provides very efficient runtime + support for the object paradigm. But its static nature is + inflexibile in certain problem domains. Graphical user interface + programming is a domain that requires both runtime efficiency and + a high level of flexibility. Qt provides this, by combining the + speed of C++ with the flexibility of the Qt Object Model. + + Qt adds these features to C++: + + \list + \li a very powerful mechanism for seamless object + communication called \l{signals and slots} + \li queryable and designable \l{Qt's Property System}{object + properties} + \li powerful \l{The Event System}{events and event filters} + \li contextual \l{i18n}{string translation for internationalization} + \li sophisticated interval driven \l timers that make it possible + to elegantly integrate many tasks in an event-driven GUI + \li hierarchical and queryable \l{Object Trees & Ownership}{object + trees} that organize object ownership in a natural way + \li guarded pointers (QPointer) that are automatically + set to 0 when the referenced object is destroyed, unlike normal C++ + pointers which become dangling pointers when their objects are destroyed + \li a \l{metaobjects.html#qobjectcast}{dynamic cast} that works across + library boundaries. + \endlist + + Many of these Qt features are implemented with standard C++ + techniques, based on inheritance from QObject. Others, like the + object communication mechanism and the dynamic property system, + require the \l{Meta-Object System} provided + by Qt's own \l{moc}{Meta-Object Compiler (moc)}. + + The meta-object system is a C++ extension that makes the language + better suited to true component GUI programming. Although + templates can be used to extend C++, the meta-object system + provides benefits using standard C++ that cannot be achieved with + templates; see \l{Why Doesn't Qt Use Templates for Signals and + Slots?} + + \section1 Important Classes + + These classes form the basis of the Qt Object Model. + + \annotatedlist objectmodel + + \target Identity vs Value + \section1 Qt Objects: Identity vs Value + + Some of the added features listed above for the Qt Object Model, + require that we think of Qt Objects as identities, not values. + Values are copied or assigned; identities are cloned. Cloning + means to create a new identity, not an exact copy of the old + one. For example, twins have different identities. They may look + identical, but they have different names, different locations, and + may have completely different social networks. + + Then cloning an identity is a more complex operation than copying + or assigning a value. We can see what this means in the Qt Object + Model. + + \b{A Qt Object...} + + \list + + \li might have a unique \l{QObject::objectName()}. If we copy a Qt + Object, what name should we give the copy? + + \li has a location in an \l{Object Trees & Ownership} + {object hierarchy}. If we copy a Qt Object, where should the copy + be located? + + \li can be connected to other Qt Objects to emit signals to them or + to receive signals emitted by them. If we copy a Qt Object, how + should we transfer these connections to the copy? + + \li can have \l{Qt's Property System} {new properties} added to it + at runtime that are not declared in the C++ class. If we copy a Qt + Object, should the copy include the properties that were added to + the original? + + \endlist + + For these reasons, Qt Objects should be treated as identities, not + as values. Identities are cloned, not copied or assigned, and + cloning an identity is a more complex operation than copying or + assigning a value. Therefore, QObject and all subclasses of + QObject (direct or indirect) have their \l{No copy constructor} + {copy constructor and assignment operator} disabled. + + */ diff --git a/src/corelib/doc/src/objectmodel/objecttrees.qdoc b/src/corelib/doc/src/objectmodel/objecttrees.qdoc new file mode 100644 index 0000000000..e03a93ab3d --- /dev/null +++ b/src/corelib/doc/src/objectmodel/objecttrees.qdoc @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page objecttrees.html + \title Object Trees & Ownership + \ingroup qt-basic-concepts + \brief Information about the parent-child pattern used to describe + object ownership in Qt. + + \section1 Overview + + \link QObject QObjects\endlink organize themselves in object trees. + When you create a QObject with another object as parent, it's added to + the parent's \link QObject::children() children() \endlink list, and + is deleted when the parent is. It turns out that this approach fits + the needs of GUI objects very well. For example, a \l QShortcut + (keyboard shortcut) is a child of the relevant window, so when the + user closes that window, the shorcut is deleted too. + + \l QWidget, the base class of everything that appears on the screen, + extends the parent-child relationship. A child normally also becomes a + child widget, i.e. it is displayed in its parent's coordinate system + and is graphically clipped by its parent's boundaries. For example, + when the application deletes a message box after it has been + closed, the message box's buttons and label are also deleted, just as + we'd want, because the buttons and label are children of the message + box. + + You can also delete child objects yourself, and they will remove + themselves from their parents. For example, when the user removes a + toolbar it may lead to the application deleting one of its \l QToolBar + objects, in which case the tool bar's \l QMainWindow parent would + detect the change and reconfigure its screen space accordingly. + + The debugging functions \l QObject::dumpObjectTree() and \l + QObject::dumpObjectInfo() are often useful when an application looks or + acts strangely. + + \target note on the order of construction/destruction of QObjects + \section1 Construction/Destruction Order of QObjects + + When \l {QObject} {QObjects} are created on the heap (i.e., created + with \e new), a tree can be constructed from them in any order, and + later, the objects in the tree can be destroyed in any order. When any + QObject in the tree is deleted, if the object has a parent, the + destructor automatically removes the object from its parent. If the + object has children, the destructor automatically deletes each + child. No QObject is deleted twice, regardless of the order of + destruction. + + When \l {QObject} {QObjects} are created on the stack, the same + behavior applies. Normally, the order of destruction still doesn't + present a problem. Consider the following snippet: + + \snippet code/doc_src_objecttrees.cpp 0 + + The parent, \c window, and the child, \c quit, are both \l {QObject} + {QObjects} because QPushButton inherits QWidget, and QWidget inherits + QObject. This code is correct: the destructor of \c quit is \e not + called twice because the C++ language standard \e {(ISO/IEC 14882:2003)} + specifies that destructors of local objects are called in the reverse + order of their constructors. Therefore, the destructor of + the child, \c quit, is called first, and it removes itself from its + parent, \c window, before the destructor of \c window is called. + + But now consider what happens if we swap the order of construction, as + shown in this second snippet: + + \snippet code/doc_src_objecttrees.cpp 1 + + In this case, the order of destruction causes a problem. The parent's + destructor is called first because it was created last. It then calls + the destructor of its child, \c quit, which is incorrect because \c + quit is a local variable. When \c quit subsequently goes out of scope, + its destructor is called again, this time correctly, but the damage has + already been done. +*/ diff --git a/src/corelib/doc/src/objectmodel/properties.qdoc b/src/corelib/doc/src/objectmodel/properties.qdoc new file mode 100644 index 0000000000..9d248f00de --- /dev/null +++ b/src/corelib/doc/src/objectmodel/properties.qdoc @@ -0,0 +1,273 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page properties.html + \title The Property System + \brief An overview of Qt's property system. + + \ingroup qt-basic-concepts + \target Qt's Property System + + Qt provides a sophisticated property system similar to the ones + supplied by some compiler vendors. However, as a compiler- and + platform-independent library, Qt does not rely on non-standard + compiler features like \c __property or \c [property]. The Qt + solution works with \e any standard C++ compiler on every platform + Qt supports. It is based on the \l {Meta-Object System} that also + provides inter-object communication via \l{signals and slots}. + + \section1 Requirements for Declaring Properties + + To declare a property, use the \l {Q_PROPERTY()} {Q_PROPERTY()} + macro in a class that inherits QObject. + + \snippet code/doc_src_properties.cpp 0 + + Here are some typical examples of property declarations taken from + class QWidget. + + \snippet code/doc_src_properties.cpp 1 + + A property behaves like a class data member, but it has additional + features accessible through the \l {Meta-Object System}. + + \list + + \li A \c READ accessor function is required. It is for reading the + property value. Ideally, a const function is used for this purpose, + and it must return either the property's type or a pointer or + reference to that type. e.g., QWidget::focus is a read-only property + with \c READ function, QWidget::hasFocus(). + + \li A \c WRITE accessor function is optional. It is for setting the + property value. It must return void and must take exactly one + argument, either of the property's type or a pointer or reference + to that type. e.g., QWidget::enabled has the \c WRITE function + QWidget::setEnabled(). Read-only properties do not need \c WRITE + functions. e.g., QWidget::focus has no \c WRITE function. + + \li A \c RESET function is optional. It is for setting the property + back to its context specific default value. e.g., QWidget::cursor + has the typical \c READ and \c WRITE functions, QWidget::cursor() + and QWidget::setCursor(), and it also has a \c RESET function, + QWidget::unsetCursor(), since no call to QWidget::setCursor() can + mean \e {reset to the context specific cursor}. The \c RESET + function must return void and take no parameters. + + \li A \c NOTIFY signal is optional. If defined, it should specify one + existing signal in that class that is emitted whenever the value + of the property changes. + + \li A \c REVISION number is optional. If included, it defines the + the property and its notifier signal to be used in a particular + revision of the API that is exposed to QML. + + \li The \c DESIGNABLE attribute indicates whether the property + should be visible in the property editor of GUI design tool (e.g., + \l {Qt Designer}). Most properties are \c DESIGNABLE (default + true). Instead of true or false, you can specify a boolean + member function. + + \li The \c SCRIPTABLE attribute indicates whether this property + should be accessible by a scripting engine (default true). + Instead of true or false, you can specify a boolean member + function. + + \li The \c STORED attribute indicates whether the property should + be thought of as existing on its own or as depending on other + values. It also indicates whether the property value must be saved + when storing the object's state. Most properties are \c STORED + (default true), but e.g., QWidget::minimumWidth() has \c STORED + false, because its value is just taken from the width component + of property QWidget::minimumSize(), which is a QSize. + + \li The \c USER attribute indicates whether the property is + designated as the user-facing or user-editable property for the + class. Normally, there is only one \c USER property per class + (default false). e.g., QAbstractButton::checked is the user + editable property for (checkable) buttons. Note that QItemDelegate + gets and sets a widget's \c USER property. + + \li The presence of the \c CONSTANT attibute indicates that the property + value is constant. For a given object instance, the READ method of a + constant property must return the same value every time it is called. This + constant value may be different for different instances of the object. A + constant property cannot have a WRITE method or a NOTIFY signal. + + \li The presence of the \c FINAL attribute indicates that the property + will not be overridden by a derived class. This can be used for performance + optimizations in some cases, but is not enforced by moc. Care must be taken + never to override a \c FINAL property. + + \endlist + + The \c READ, \c WRITE, and \c RESET functions can be inherited. + They can also be virtual. When they are inherited in classes where + multiple inheritance is used, they must come from the first + inherited class. + + The property type can be any type supported by QVariant, or it can + be a user-defined type. In this example, class QDate is considered + to be a user-defined type. + + \snippet code/doc_src_properties.cpp 2 + + Because QDate is user-defined, you must include the \c{} + header file with the property declaration. + + For QMap, QList, and QValueList properties, the property value is + a QVariant whose value is the entire list or map. Note that the + Q_PROPERTY string cannot contain commas, because commas separate + macro arguments. Therefore, you must use \c QMap as the property + type instead of \c QMap. For consistency, also + use \c QList and \c QValueList instead of \c QList and + \c QValueList. + + \section1 Reading and Writing Properties with the Meta-Object System + + A property can be read and written using the generic functions + QObject::property() and QObject::setProperty(), without knowing + anything about the owning class except the property's name. In + the code snippet below, the call to QAbstractButton::setDown() and + the call to QObject::setProperty() both set property "down". + + \snippet code/doc_src_properties.cpp 3 + + Accessing a property through its \c WRITE accessor is the better + of the two, because it is faster and gives better diagnostics at + compile time, but setting the property this way requires that you + know about the class at compile time. Accessing properties by name + lets you access classes you don't know about at compile time. You + can \e discover a class's properties at run time by querying its + QObject, QMetaObject, and \l {QMetaProperty} {QMetaProperties}. + + \snippet code/doc_src_properties.cpp 4 + + In the above snippet, QMetaObject::property() is used to get \l + {QMetaProperty} {metadata} about each property defined in some + unknown class. The property name is fetched from the metadata and + passed to QObject::property() to get the \l {QVariant} {value} of + the property in the current \l {QObject}{object}. + + \section1 A Simple Example + + Suppose we have a class MyClass, which is derived from QObject and + which uses the Q_OBJECT macro in its private section. We want to + declare a property in MyClass to keep track of a priorty + value. The name of the property will be \e priority, and its type + will be an enumeration type named \e Priority, which is defined in + MyClass. + + We declare the property with the Q_PROPERTY() macro in the private + section of the class. The required \c READ function is named \c + priority, and we include a \c WRITE function named \c setPriority. + The enumeration type must be registered with the \l {Meta-Object + System} using the Q_ENUMS() macro. Registering an enumeration type + makes the enumerator names available for use in calls to + QObject::setProperty(). We must also provide our own declarations + for the \c READ and \c WRITE functions. The declaration of MyClass + then might look like this: + + \snippet code/doc_src_properties.cpp 5 + + The \c READ function is const and returns the property type. The + \c WRITE function returns void and has exactly one parameter of + the property type. The meta-object compiler enforces these + requirements. + + Given a pointer to an instance of MyClass or a pointer to a + QObject that is an instance of MyClass, we have two ways to set + its priority property: + + \snippet code/doc_src_properties.cpp 6 + + In the example, the enumeration type that is the property type is + declared in MyClass and registered with the \l{Meta-Object System} + using the Q_ENUMS() macro. This makes the enumeration values + available as strings for use as in the call to setProperty(). Had + the enumeration type been declared in another class, its fully + qualified name (i.e., OtherClass::Priority) would be required, and + that other class would also have to inherit QObject and register + the enumeration type there using the Q_ENUMS() macro. + + A similar macro, Q_FLAGS(), is also available. Like Q_ENUMS(), it + registers an enumeration type, but it marks the type as being a + set of \e flags, i.e. values that can be OR'd together. An I/O + class might have enumeration values \c Read and \c Write and then + QObject::setProperty() could accept \c{Read | Write}. Q_FLAGS() + should be used to register this enumeration type. + + \section1 Dynamic Properties + + QObject::setProperty() can also be used to add \e new properties + to an instance of a class at runtime. When it is called with a + name and a value, if a property with the given name exists in the + QObject, and if the given value is compatible with the property's + type, the value is stored in the property, and true is returned. + If the value is \e not compatible with the property's type, the + property is \e not changed, and false is returned. But if the + property with the given name doesn't exist in the QObject (i.e., + if it wasn't declared with Q_PROPERTY(), a new property with the + given name and value is automatically added to the QObject, but + false is still returned. This means that a return of false can't + be used to determine whether a particular property was actually + set, unless you know in advance that the property already exists + in the QObject. + + Note that \e dynamic properties are added on a per instance basis, + i.e., they are added to QObject, not QMetaObject. A property can + be removed from an instance by passing the property name and an + invalid QVariant value to QObject::setProperty(). The default + constructor for QVariant constructs an invalid QVariant. + + Dynamic properties can be queried with QObject::property(), just + like properties declared at compile time with Q_PROPERTY(). + + \sa {Meta-Object System}, {Signals and Slots} + + \section1 Properties and Custom Types + + Custom types used by properties need to be registered using the + Q_DECLARE_METATYPE() macro so that their values can be stored in + QVariant objects. This makes them suitable for use with both + static properties declared using the Q_PROPERTY() macro in class + definitions and dynamic properties created at run-time. + + \sa Q_DECLARE_METATYPE(), QMetaType, QVariant + + \section1 Adding Additional Information to a Class + + Connected to the property system is an additional macro, + Q_CLASSINFO(), that can be used to attach additional + \e{name}--\e{value} pairs to a class's meta-object, for example: + + \snippet code/doc_src_properties.cpp 7 + + Like other meta-data, class information is accessible at run-time + through the meta-object; see QMetaObject::classInfo() for details. +*/ diff --git a/src/corelib/doc/src/objectmodel/signalsandslots.qdoc b/src/corelib/doc/src/objectmodel/signalsandslots.qdoc new file mode 100644 index 0000000000..0f12c9c8f2 --- /dev/null +++ b/src/corelib/doc/src/objectmodel/signalsandslots.qdoc @@ -0,0 +1,468 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page signalsandslots.html + \title Signals & Slots + \ingroup qt-basic-concepts + \brief An overview of Qt's signals and slots inter-object + communication mechanism. + + Signals and slots are used for communication between objects. The + signals and slots mechanism is a central feature of Qt and + probably the part that differs most from the features provided by + other frameworks. + + \tableofcontents + + \section1 Introduction + + In GUI programming, when we change one widget, we often want + another widget to be notified. More generally, we want objects of + any kind to be able to communicate with one another. For example, + if a user clicks a \uicontrol{Close} button, we probably want the + window's \l{QWidget::close()}{close()} function to be called. + + Older toolkits achieve this kind of communication using + callbacks. A callback is a pointer to a function, so if you want + a processing function to notify you about some event you pass a + pointer to another function (the callback) to the processing + function. The processing function then calls the callback when + appropriate. Callbacks have two fundamental flaws: Firstly, they + are not type-safe. We can never be certain that the processing + function will call the callback with the correct arguments. + Secondly, the callback is strongly coupled to the processing + function since the processing function must know which callback + to call. + + \section1 Signals and Slots + + In Qt, we have an alternative to the callback technique: We use + signals and slots. A signal is emitted when a particular event + occurs. Qt's widgets have many predefined signals, but we can + always subclass widgets to add our own signals to them. A slot + is a function that is called in response to a particular signal. + Qt's widgets have many pre-defined slots, but it is common + practice to subclass widgets and add your own slots so that you + can handle the signals that you are interested in. + + \image abstract-connections.png + \omit + \caption An abstract view of some signals and slots connections + \endomit + + The signals and slots mechanism is type safe: The signature of a + signal must match the signature of the receiving slot. (In fact a + slot may have a shorter signature than the signal it receives + because it can ignore extra arguments.) Since the signatures are + compatible, the compiler can help us detect type mismatches. + Signals and slots are loosely coupled: A class which emits a + signal neither knows nor cares which slots receive the signal. + Qt's signals and slots mechanism ensures that if you connect a + signal to a slot, the slot will be called with the signal's + parameters at the right time. Signals and slots can take any + number of arguments of any type. They are completely type safe. + + All classes that inherit from QObject or one of its subclasses + (e.g., QWidget) can contain signals and slots. Signals are emitted by + objects when they change their state in a way that may be interesting + to other objects. This is all the object does to communicate. It + does not know or care whether anything is receiving the signals it + emits. This is true information encapsulation, and ensures that the + object can be used as a software component. + + Slots can be used for receiving signals, but they are also normal + member functions. Just as an object does not know if anything receives + its signals, a slot does not know if it has any signals connected to + it. This ensures that truly independent components can be created with + Qt. + + You can connect as many signals as you want to a single slot, and a + signal can be connected to as many slots as you need. It is even + possible to connect a signal directly to another signal. (This will + emit the second signal immediately whenever the first is emitted.) + + Together, signals and slots make up a powerful component programming + mechanism. + + \section1 A Small Example + + A minimal C++ class declaration might read: + + \snippet signalsandslots/signalsandslots.h 0 + + A small QObject-based class might read: + + \snippet signalsandslots/signalsandslots.h 1 + \codeline + \snippet signalsandslots/signalsandslots.h 2 + \snippet signalsandslots/signalsandslots.h 3 + + The QObject-based version has the same internal state, and provides + public methods to access the state, but in addition it has support + for component programming using signals and slots. This class can + tell the outside world that its state has changed by emitting a + signal, \c{valueChanged()}, and it has a slot which other objects + can send signals to. + + All classes that contain signals or slots must mention + Q_OBJECT at the top of their declaration. They must also derive + (directly or indirectly) from QObject. + + Slots are implemented by the application programmer. + Here is a possible implementation of the \c{Counter::setValue()} + slot: + + \snippet signalsandslots/signalsandslots.cpp 0 + + The \c{emit} line emits the signal \c valueChanged() from the + object, with the new value as argument. + + In the following code snippet, we create two \c Counter objects + and connect the first object's \c valueChanged() signal to the + second object's \c setValue() slot using QObject::connect(): + + \snippet signalsandslots/signalsandslots.cpp 1 + \snippet signalsandslots/signalsandslots.cpp 2 + \codeline + \snippet signalsandslots/signalsandslots.cpp 3 + \snippet signalsandslots/signalsandslots.cpp 4 + + Calling \c{a.setValue(12)} makes \c{a} emit a + \c{valueChanged(12)} signal, which \c{b} will receive in its + \c{setValue()} slot, i.e. \c{b.setValue(12)} is called. Then + \c{b} emits the same \c{valueChanged()} signal, but since no slot + has been connected to \c{b}'s \c{valueChanged()} signal, the + signal is ignored. + + Note that the \c{setValue()} function sets the value and emits + the signal only if \c{value != m_value}. This prevents infinite + looping in the case of cyclic connections (e.g., if + \c{b.valueChanged()} were connected to \c{a.setValue()}). + + By default, for every connection you make, a signal is emitted; + two signals are emitted for duplicate connections. You can break + all of these connections with a single disconnect() call. + If you pass the Qt::UniqueConnection \a type, the connection will only + be made if it is not a duplicate. If there is already a duplicate + (exact same signal to the exact same slot on the same objects), + the connection will fail and connect will return false + + This example illustrates that objects can work together without needing to + know any information about each other. To enable this, the objects only + need to be connected together, and this can be achieved with some simple + QObject::connect() function calls, or with \c{uic}'s + \l{Using a Designer UI File in Your Application#Automatic Connections} + {automatic connections} feature. + + \section1 Building the Example + + The C++ preprocessor changes or removes the \c{signals}, + \c{slots}, and \c{emit} keywords so that the compiler is + presented with standard C++. + + By running the \l moc on class definitions that contain signals + or slots, a C++ source file is produced which should be compiled + and linked with the other object files for the application. If + you use \l qmake, the makefile rules to automatically invoke \c + moc will be added to your project's makefile. + + \section1 Signals + + Signals are emitted by an object when its internal state has changed + in some way that might be interesting to the object's client or owner. + Signals are public access functions and can be emitted from anywhere, + but we recommend to only emit them from the class that defines the + signal and its subclasses. + + When a signal is emitted, the slots connected to it are usually + executed immediately, just like a normal function call. When this + happens, the signals and slots mechanism is totally independent of + any GUI event loop. Execution of the code following the \c emit + statement will occur once all slots have returned. The situation is + slightly different when using \l{Qt::ConnectionType}{queued + connections}; in such a case, the code following the \c emit keyword + will continue immediately, and the slots will be executed later. + + If several slots are connected to one signal, the slots will be + executed one after the other, in the order they have been connected, + when the signal is emitted. + + Signals are automatically generated by the \l moc and must not be + implemented in the \c .cpp file. They can never have return types + (i.e. use \c void). + + A note about arguments: Our experience shows that signals and slots + are more reusable if they do not use special types. If + QScrollBar::valueChanged() were to use a special type such as the + hypothetical QScrollBar::Range, it could only be connected to + slots designed specifically for QScrollBar. Connecting different + input widgets together would be impossible. + + \section1 Slots + + A slot is called when a signal connected to it is emitted. Slots are + normal C++ functions and can be called normally; their only special + feature is that signals can be connected to them. + + Since slots are normal member functions, they follow the normal C++ + rules when called directly. However, as slots, they can be invoked + by any component, regardless of its access level, via a signal-slot + connection. This means that a signal emitted from an instance of an + arbitrary class can cause a private slot to be invoked in an instance + of an unrelated class. + + You can also define slots to be virtual, which we have found quite + useful in practice. + + Compared to callbacks, signals and slots are slightly slower + because of the increased flexibility they provide, although the + difference for real applications is insignificant. In general, + emitting a signal that is connected to some slots, is + approximately ten times slower than calling the receivers + directly, with non-virtual function calls. This is the overhead + required to locate the connection object, to safely iterate over + all connections (i.e. checking that subsequent receivers have not + been destroyed during the emission), and to marshall any + parameters in a generic fashion. While ten non-virtual function + calls may sound like a lot, it's much less overhead than any \c + new or \c delete operation, for example. As soon as you perform a + string, vector or list operation that behind the scene requires + \c new or \c delete, the signals and slots overhead is only + responsible for a very small proportion of the complete function + call costs. The same is true whenever you do a system call in a slot; + or indirectly call more than ten functions. + The simplicity and flexibility of the signals and slots mechanism is + well worth the overhead, which your users won't even notice. + + Note that other libraries that define variables called \c signals + or \c slots may cause compiler warnings and errors when compiled + alongside a Qt-based application. To solve this problem, \c + #undef the offending preprocessor symbol. + + \section1 Meta-Object Information + + The meta-object compiler (\l moc) parses the class declaration in + a C++ file and generates C++ code that initializes the + meta-object. The meta-object contains the names of all the signal + and slot members, as well as pointers to these functions. + + The meta-object contains additional information such as the + object's \link QObject::className() class name\endlink. You can + also check if an object \link QObject::inherits() + inherits\endlink a specific class, for example: + + \snippet signalsandslots/signalsandslots.cpp 5 + \snippet signalsandslots/signalsandslots.cpp 6 + + The meta-object information is also used by qobject_cast(), which + is similar to QObject::inherits() but is less error-prone: + + \snippet signalsandslots/signalsandslots.cpp 7 + + See \l{Meta-Object System} for more information. + + \section1 A Real Example + + Here is a simple commented example of a widget. + + \snippet signalsandslots/lcdnumber.h 0 + \snippet signalsandslots/lcdnumber.h 1 + \codeline + \snippet signalsandslots/lcdnumber.h 2 + \codeline + \snippet signalsandslots/lcdnumber.h 3 + \snippet signalsandslots/lcdnumber.h 4 + \snippet signalsandslots/lcdnumber.h 5 + + \c LcdNumber inherits QObject, which has most of the signal-slot + knowledge, via QFrame and QWidget. It is somewhat similar to the + built-in QLCDNumber widget. + + The Q_OBJECT macro is expanded by the preprocessor to declare + several member functions that are implemented by the \c{moc}; if + you get compiler errors along the lines of "undefined reference + to vtable for \c{LcdNumber}", you have probably forgotten to + \l{moc}{run the moc} or to include the moc output in the link + command. + + \snippet signalsandslots/lcdnumber.h 6 + \snippet signalsandslots/lcdnumber.h 7 + + It's not obviously relevant to the moc, but if you inherit + QWidget you almost certainly want to have the \c parent argument + in your constructor and pass it to the base class's constructor. + + Some destructors and member functions are omitted here; the \c + moc ignores member functions. + + \snippet signalsandslots/lcdnumber.h 8 + \snippet signalsandslots/lcdnumber.h 9 + + \c LcdNumber emits a signal when it is asked to show an impossible + value. + + If you don't care about overflow, or you know that overflow + cannot occur, you can ignore the \c overflow() signal, i.e. don't + connect it to any slot. + + If on the other hand you want to call two different error + functions when the number overflows, simply connect the signal to + two different slots. Qt will call both (in the order they were connected). + + \snippet signalsandslots/lcdnumber.h 10 + \snippet signalsandslots/lcdnumber.h 11 + \snippet signalsandslots/lcdnumber.h 12 + \codeline + \snippet signalsandslots/lcdnumber.h 13 + + A slot is a receiving function used to get information about + state changes in other widgets. \c LcdNumber uses it, as the code + above indicates, to set the displayed number. Since \c{display()} + is part of the class's interface with the rest of the program, + the slot is public. + + Several of the example programs connect the + \l{QScrollBar::valueChanged()}{valueChanged()} signal of a + QScrollBar to the \c display() slot, so the LCD number + continuously shows the value of the scroll bar. + + Note that \c display() is overloaded; Qt will select the + appropriate version when you connect a signal to the slot. With + callbacks, you'd have to find five different names and keep track + of the types yourself. + + Some irrelevant member functions have been omitted from this + example. + + \section1 Signals And Slots With Default Arguments + + The signatures of signals and slots may contain arguments, and the + arguments can have default values. Consider QObject::destroyed(): + + \code + void destroyed(QObject* = 0); + \endcode + + When a QObject is deleted, it emits this QObject::destroyed() + signal. We want to catch this signal, wherever we might have a + dangling reference to the deleted QObject, so we can clean it up. + A suitable slot signature might be: + + \code + void objectDestroyed(QObject* obj = 0); + \endcode + + To connect the signal to the slot, we use QObject::connect(). + There are several ways to connect signal and slots. The first is to use + function pointers: + \code + connect(sender, &QObject::destroyed, this, &MyObject::objectDestroyed); + \endcode + + There are several advantages to using connect() with function pointers. + First, it allows the compiler to check that the signal's arguments are + compatible with the slot's arguments. Arguments can also be implicitly + converted by the compiler, if needed. + + You can also connect to functors or C++11 lamdas: + + \code + connect(sender, &QObject::destroyed, [=](){ this->m_objects.remove(sender); }); + \endcode + + Note that if your compiler does not support C++11 variadic templates, + this syntax only works if the signal and slot have 6 arguments or less. + + The other way to connect a signal to a slot is to use QObject::connect() + and the \c{SIGNAL} and \c{SLOT} macros. + The rule about whether to + include arguments or not in the \c{SIGNAL()} and \c{SLOT()} + macros, if the arguments have default values, is that the + signature passed to the \c{SIGNAL()} macro must \e not have fewer + arguments than the signature passed to the \c{SLOT()} macro. + + All of these would work: + \code + connect(sender, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(Qbject*))); + connect(sender, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed())); + connect(sender, SIGNAL(destroyed()), this, SLOT(objectDestroyed())); + \endcode + But this one won't work: + \code + connect(sender, SIGNAL(destroyed()), this, SLOT(objectDestroyed(QObject*))); + \endcode + + ...because the slot will be expecting a QObject that the signal + will not send. This connection will report a runtime error. + + Note that signal and slot arguments are not checked by the compiler when + using this QObject::connect() overload. + + \section1 Advanced Signals and Slots Usage + + For cases where you may require information on the sender of the + signal, Qt provides the QObject::sender() function, which returns + a pointer to the object that sent the signal. + + The QSignalMapper class is provided for situations where many + signals are connected to the same slot and the slot needs to + handle each signal differently. + + Suppose you have three push buttons that determine which file you + will open: "Tax File", "Accounts File", or "Report File". + + In order to open the correct file, you use QSignalMapper::setMapping() to + map all the clicked() signals to a QSignalMapper object. Then you connect + the file's QPushButton::clicked() signal to the QSignalMapper::map() slot. + + \snippet signalmapper/filereader.cpp 0 + + Then, you connect the \l{QSignalMapper::}{mapped()} signal to + \c{readFile()} where a different file will be opened, depending on + which push button is pressed. + + \snippet signalmapper/filereader.cpp 1 + + \sa {Meta-Object System}, {Qt's Property System} + + \target 3rd Party Signals and Slots + \section2 Using Qt with 3rd Party Signals and Slots + + It is possible to use Qt with a 3rd party signal/slot mechanism. + You can even use both mechanisms in the same project. Just add the + following line to your qmake project (.pro) file. + + \snippet code/doc_src_containers.cpp 22 + + It tells Qt not to define the moc keywords \c{signals}, \c{slots}, + and \c{emit}, because these names will be used by a 3rd party + library, e.g. Boost. Then to continue using Qt signals and slots + with the \c{no_keywords} flag, simply replace all uses of the Qt + moc keywords in your sources with the corresponding Qt macros + Q_SIGNALS (or Q_SIGNAL), Q_SLOTS (or Q_SLOT), and Q_EMIT. +*/ diff --git a/src/corelib/doc/src/qtcore.qdoc b/src/corelib/doc/src/qtcore.qdoc new file mode 100644 index 0000000000..66c8704322 --- /dev/null +++ b/src/corelib/doc/src/qtcore.qdoc @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \module QtCore + \title QtCore Module + \ingroup modules + + \keyword QtCore + + \brief The QtCore module contains core non-GUI functionality. + + All other Qt modules rely on this module. To include the + definitions of the module's classes, use the following directive: + + \snippet code/doc_src_qtcore.cpp 0 +*/ + diff --git a/src/corelib/doc/src/threads-basics.qdoc b/src/corelib/doc/src/threads-basics.qdoc new file mode 100644 index 0000000000..0f455c01e5 --- /dev/null +++ b/src/corelib/doc/src/threads-basics.qdoc @@ -0,0 +1,572 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page thread-basics.html + \ingroup tutorials + \startpage {index.html}{Qt Reference Documentation} + + \title Threading Basics + \brief An introduction to threads + + \section1 What Are Threads? + + Threads are about doing things in parallel, just like processes. So how do + threads differ from processes? While you are making calculations on a + spreadsheet, there may also be a media player running on the same desktop + playing your favorite song. Here is an example of two processes working in + parallel: one running the spreadsheet program; one running a media player. + Multitasking is a well known term for this. A closer look at the media + player reveals that there are again things going on in parallel within one + single process. While the media player is sending music to the audio driver, + the user interface with all its bells and whistles is being constantly + updated. This is what threads are for -- concurrency within one single + process. + + So how is concurrency implemented? Parallel work on single core CPUs is an + illusion which is somewhat similar to the illusion of moving images in + cinema. + For processes, the illusion is produced by interrupting the processor's + work on one process after a very short time. Then the processor moves on to + the next process. In order to switch between processes, the current program + counter is saved and the next processor's program counter is loaded. This + is not sufficient because the same needs to be done with registers and + certain architecture and OS specific data. + + Just as one CPU can power two or more processes, it is also possible to let + the CPU run on two different code segments of one single process. When a + process starts, it always executes one code segment and therefore the + process is said to have one thread. However, the program may decide to + start a second thread. Then, two different code sequences are processed + simultaneously inside one process. Concurrency is achieved on single core + CPUs by repeatedly saving program counters and registers then loading the + next thread's program counters and registers. No cooperation from the + program is required to cycle between the active threads. A thread may be in + any state when the switch to the next thread occurs. + + The current trend in CPU design is to have several cores. A typical + single-threaded application can make use of only one core. However, a + program with multiple threads can be assigned to multiple cores, making + things happen in a truly concurrent way. As a result, distributing work + to more than one thread can make a program run much faster on multicore + CPUs because additional cores can be used. + + \section2 GUI Thread and Worker Thread + + As mentioned, each program has one thread when it is started. This thread + is called the "main thread" (also known as the "GUI thread" in Qt + applications). The Qt GUI must run in this thread. All widgets and several + related classes, for example QPixmap, don't work in secondary threads. + A secondary thread is commonly referred to as a "worker thread" because it + is used to offload processing work from the main thread. + + \section2 Simultaneous Access to Data + + Each thread has its own stack, which means each thread has its own call + history and local variables. Unlike processes, threads share the same + address space. The following diagram shows how the building blocks of + threads are located in memory. Program counter and registers of inactive + threads are typically kept in kernel space. There is a shared copy of the + code and a separate stack for each thread. + + \image threadvisual-example.png "Thread visualization" + + If two threads have a pointer to the same object, it is possible that both + threads will access that object at the same time and this can potentially + destroy the object's integrity. It's easy to imagine the many things that + can go wrong when two methods of the same object are executed + simultaneously. + + Sometimes it is necessary to access one object from different threads; + for example, when objects living in different threads need to communicate. + Since threads use the same address space, it is easier and faster for + threads to exchange data than it is for processes. Data does not have to be + serialized and copied. Passing pointers is possible, but there must be a + strict coordination of what thread touches which object. Simultaneous + execution of operations on one object must be prevented. There are several + ways of achieving this and some of them are described below. + + So what can be done safely? All objects created in a thread can be used + safely within that thread provided that other threads don't have references + to them and objects don't have implicit coupling with other threads. Such + implicit coupling may happen when data is shared between instances as with + static members, singletons or global data. Familiarize yourself with the + concept of \l{Reentrancy and Thread-Safety}{thread safe and reentrant} + classes and functions. + + \section1 Using Threads + + There are basically two use cases for threads: + + \list + \li Make processing faster by making use of multicore processors. + \li Keep the GUI thread or other time critical threads responsive by + offloading long lasting processing or blocking calls to other threads. + \endlist + + \section2 When to Use Alternatives to Threads + + Developers need to be very careful with threads. It is easy to start other + threads, but very hard to ensure that all shared data remains consistent. + Problems are often hard to find because they may only show up once in a + while or only on specific hardware configurations. Before creating threads + to solve certain problems, possible alternatives should be considered. + + \table + \header + \li Alternative + \li Comment + \row + \li QEventLoop::processEvents() + \li Calling QEventLoop::processEvents() repeatedly during a + time-consuming calculation prevents GUI blocking. However, this + solution doesn't scale well because the call to processEvents() may + occur too often, or not often enough, depending on hardware. + \row + \li QTimer + \li Background processing can sometimes be done conveniently using a + timer to schedule execution of a slot at some point in the future. + A timer with an interval of 0 will time out as soon as there are no + more events to process. + \row + \li QSocketNotifier QNetworkAccessManager QIODevice::readyRead() + \li This is an alternative to having one or multiple threads, each with + a blocking read on a slow network connection. As long as the + calculation in response to a chunk of network data can be executed + quickly, this reactive design is better than synchronous waiting in + threads. Reactive design is less error prone and energy efficient + than threading. In many cases there are also performance benefits. + \endtable + + In general, it is recommended to only use safe and tested paths and to + avoid introducing ad-hoc threading concepts. QtConcurrent provides an easy + interface for distributing work to all of the processor's cores. The + threading code is completely hidden in the QtConcurrent framework, so you + don't have to take care of the details. However, QtConcurrent can't be used + when communication with the running thread is needed, and it shouldn't be + used to handle blocking operations. + + \section2 Which Qt Thread Technology Should You Use? + + Sometimes you want to do more than just running a method in the context of + another thread. You may want to have an object which lives in another + thread that provides a service to the GUI thread. Maybe you want another + thread to stay alive forever to poll hardware ports and send a signal to + the GUI thread when something noteworthy has happened. Qt provides + different solutions for developing threaded applications. The right + solution depends on the purpose of the new thread as well as on the + thread's lifetime. + + \table + \header + \li Lifetime of thread + \li Development task + \li Solution + \row + \li One call + \li Run one method within another thread and quit the thread when the + method is finished. + \li Qt provides different solutions: + \list + \li Write a function and run it with QtConcurrent::run() + \li Derive a class from QRunnable and run it in the global thread + pool with QThreadPool::globalInstance()->start() + \li Derive a class from QThread, reimplement the QThread::run() + method and use QThread::start() to run it. + \endlist + + \row + \li One call + \li Operations are to be performed on all items of a container. + Processing should be performed using all available cores. A common + example is to produce thumbnails from a list of images. + \li QtConcurrent provides the \l{QtConcurrent::}{map()} function for + applying operations on every container element, + \l{QtConcurrent::}{filter()} for selecting container elements, and + the option of specifying a reduce function for combining the + remaining elements. + \row + \li One call + \li A long running operation has to be put in another thread. During the + course of processing, status information should be sent to the GUI + thread. + \li Use QThread, reimplement run and emit signals as needed. Connect the + signals to the GUI thread's slots using queued signal/slot + connections. + + \row + \li Permanent + \li Have an object living in another thread and let it perform different + tasks upon request. + This means communication to and from the worker thread is required. + \li Derive a class from QObject and implement the necessary slots and + signals, move the object to a thread with a running event loop and + communicate with the object over queued signal/slot connections. + \row + \li Permanent + \li Have an object living in another thread, let the object perform + repeated tasks such as polling a port and enable communication with + the GUI thread. + \li Same as above but also use a timer in the worker thread to implement + polling. However, the best solution for polling is to avoid it + completely. Sometimes using QSocketNotifier is an alternative. + \endtable + + + \section1 Qt Thread Basics + + QThread is a very convenient cross platform abstraction of native platform + threads. Starting a thread is very simple. Let us look at a short piece of + code that generates another thread which says hello in that thread and then + exits. + + \snippet tutorials/threads/hellothread/hellothread.h 1 + + We derive a class from QThread and reimplement the \l{QThread::}{run()} + method. + + \snippet tutorials/threads/hellothread/hellothread.cpp 1 + + The run method contains the code that will be run in a separate thread. In + this example, a message containing the thread ID will be printed. + QThread::start() will call the method in another thread. + + \snippet tutorials/threads/hellothread/main.cpp 1 + + To start the thread, our thread object needs to be instantiated. The + \l{QThread::}{start()} method creates a new thread and calls the + reimplemented \l{QThread::}{run()} method in this new thread. Right after + \l{QThread::}{start()} is called, two program counters walk through the + program code. The main function starts with only the GUI thread running and + it should terminate with only the GUI thread running. Exiting the program + when another thread is still busy is a programming error, and therefore, + wait is called which blocks the calling thread until the + \l{QThread::}{run()} method has completed. + + This is the result of running the code: + + \badcode + hello from GUI thread 3079423696 + hello from worker thread 3076111216 + \endcode + + + \section2 QObject and Threads + + A QObject is said to have a \e{thread affinity} or, in other words, that it + lives in a certain thread. This means that, at creation time, QObject saves + a pointer to the current thread. This information becomes relevant when an + event is posted with \l{QCoreApplication::}{postEvent()}. The event will be + put in the corresponding thread's event loop. If the thread where the + QObject lives doesn't have an event loop, the event will never be delivered. + + To start an event loop, \l{QThread::}{exec()} must be called inside + \l{QThread::}{run()}. Thread affinity can be changed using + \l{QObject::}{moveToThread()}. + + As mentioned above, developers must always be careful when calling objects' + methods from other threads. Thread affinity does not change this situation. + Qt documentation marks several methods as thread-safe. + \l{QCoreApplication::}{postEvent()} is a noteworthy example. A thread-safe + method may be called from different threads simultaneously. + + In cases where there is usually no concurrent access to methods, calling + non-thread-safe methods of objects in other threads may work thousands + of times before a concurrent access occurs, causing unexpected behavior. + Writing test code does not entirely ensure thread correctness, but it is + still important. + On Linux, Valgrind and Helgrind can help detect threading errors. + + The anatomy of QThread is quite interesting: + + \list + \li QThread does not live in the new thread where \l{QThread::}{run()} is + executed. It lives in the old thread. + \li Most QThread methods are the thread's control interface and are meant to + be called from the old thread. Do not move this interface to the newly + created thread using \l{QObject::}{moveToThread()}; i.e., calling + \l{QObject::moveToThread()}{moveToThread(this)} is regarded as bad + practice. + \li \l{QThread::}{exec()} and the static methods + \l{QThread::}{usleep()}, \l{QThread::}{msleep()}, + \l{QThread::}{sleep()} are meant to be called from the newly created + thread. + \li Additional members defined in the QThread subclass are + accessible by both threads. The developer is responsible for + coordinating access. A typical strategy is to set the members before + \l{QThread::}{start()} is called. Once the worker thread is running, + the main thread should not touch the additional members anymore. After + the worker has terminated, the main thread can access the additional + members again. This is a convenient strategy for passing parameters to a + thread before it is started as well as for collecting the result once it + has terminated. + \endlist + + A QObject's parent must always be in the same thread. This has a surprising + consequence for objects generated within the \l{QThread::}{run()} method: + + \code + void HelloThread::run() + { + QObject *object1 = new QObject(this); //error, parent must be in the same thread + QObject object2; // OK + QSharedPointer object3(new QObject); // OK + } + \endcode + + \section2 Using a Mutex to Protect the Integrity of Data + + A mutex is an object that has \l{QMutex::}{lock()} and \l{QMutex::}{unlock()} + methods and remembers if it is already locked. A mutex is designed to be + called from multiple threads. \l{QMutex::}{lock()} returns immediately if + the mutex is not locked. The next call from another thread will find the + mutex in a locked state and then \l{QMutex::}{lock()} will block the thread + until the other thread calls \l{QMutex::}{unlock()}. This functionality can + make sure that a code section will be executed by only one thread at a time. + + The following line sketches how a mutex can be used to make a method + thread-safe: + + \code + void Worker::work() + { + this->mutex.lock(); // first thread can pass, other threads will be blocked here + doWork(); + this->mutex.unlock(); + } + \endcode + + What happens if one thread does not unlock a mutex? The result can be a + frozen application. In the example above, an exception might be thrown and + \c{mutex.unlock()} will never be reached. To prevent problems like this, + QMutexLocker should be used. + + \code + void Worker::work() + { + QMutexLocker locker(&mutex); // Locks the mutex and unlocks when locker exits the scope + doWork(); + } + \endcode + + This looks easy, but mutexes introduce a new class of problems: deadlocks. + A deadlock happens when a thread waits for a mutex to become unlocked, but + the mutex remains locked because the owning thread is waiting for the first + thread to unlock it. The result is a frozen application. Mutexes can be + used to make a method thread safe. Most Qt methods aren't thread safe + because there is always a performance penalty when using mutexes. + + It isn't always possible to lock and unlock a mutex in a method. Sometimes + the need to lock spans several calls. For example, modifying a container + with an iterator requires a sequence of several calls which should not be + interrupted by other threads. In such a scenario, locking can be achieved + with a mutex that is kept outside of the object to be manipulated. With an + external mutex, the duration of locking can be adjusted to the needs of the + operation. One disadvantage is that external mutexes aid locking, but do + not enforce it because users of the object may forget to use it. + + \section2 Using the Event Loop to Prevent Data Corruption + + The event loops of Qt are a very valuable tool for inter-thread + communication. Every thread may have its own event loop. A safe way of + calling a slot in another thread is by placing that call in another + thread's event loop. This ensures that the target object finishes the + method that is currently running before another method is started. + + So how is it possible to put a method invocation in an event loop? Qt has + two ways of doing this. One way is via queued signal-slot connections; the + other way is to post an event with QCoreApplication::postEvent(). A queued + signal-slot connection is a signal slot connection that is executed + asynchronously. The internal implementation is based on posted events. The + arguments of the signal are put into the event loop and the signal method + returns immediately. + + The connected slot will be executed at a time which depends on what else is + in the event loop. + + Communication via the event loop eliminates the deadlock problem we face + when using mutexes. This is why we recommend using the event loop rather + than locking an object using a mutex. + + \section2 Dealing with Asynchronous Execution + + One way to obtain a worker thread's result is by waiting for the thread + to terminate. In many cases, however, a blocking wait isn't acceptable. The + alternative to a blocking wait are asynchronous result deliveries with + either posted events or queued signals and slots. This generates a certain + overhead because an operation's result does not appear on the next source + line, but in a slot located somewhere else in the source file. Qt + developers are used to working with this kind of asynchronous behavior + because it is much similar to the kind of event-driven programming used in + GUI applications. + + \section1 Examples + + This tutorial comes with examples for Qt's three basic ways of working with + threads. Two more examples show how to communicate with a running thread + and how a QObject can be placed in another thread, providing service to the + main thread. + + \list + \li Using QThread as shown \l{Qt thread basics}{above} + \li \l{Example 1: Using the Thread Pool}{Using the global QThreadPool} + \li \l{Example 2: Using QtConcurrent}{Using QtConcurrent} + \li \l{Example 3: Clock}{Communication with the GUI thread} + \li \l{Example 4: A Permanent Thread}{A permanent QObject in another thread + provides service to the main thread} + \endlist + + The following examples can all be compiled and run independently. The source can + be found in the examples directory: examples/tutorials/threads/ + + \section2 Example 1: Using the Thread Pool + + Creating and destroying threads frequently can be expensive. To avoid the + cost of thread creation, a thread pool can be used. A thread pool is a + place where threads can be parked and fetched. We can write the same + "hello thread" program as \l{Qt Thread Basics}{above} using the global + thread pool. We derive a class from QRunnable. The code we want to run in + another thread needs to be placed in the reimplemented QRunnable::run() + method. + + \snippet tutorials/threads/hellothreadpool/hellothreadpool.cpp 1 + + We instantiate Work in main(), locate the global thread pool and use the + QThreadPool::start() method. Now the thread pool runs our worker in another + thread. Using the thread pool has a performance advantage because threads + are not destroyed after they have finished running. They are kept in a pool + and wait to be used again later. + + \section2 Example 2: Using QtConcurrent + + \snippet tutorials/threads/helloconcurrent/helloconcurrent.cpp 1 + + We write a global function hello() to implement the work. QtConcurrent::run() + is used to run the function in another thread. The result is a QFuture. + QFuture provides a method called \l{QFuture::}{waitForFinished()}, which + blocks until the calculation is completed. The real power of QtConcurrent + becomes visible when data can be made available in a container. QtConcurrent + provides several functions that are able to process itemized data on all + available cores simultaneously. The use of QtConcurrent is very similar to + applying an STL algorithm to an STL container. + \l{examples-threadandconcurrent.html}{QtConcurrent Map} is a very short and + clear example about how a container of images can be scaled on all available + cores. The image scaling example uses the blocking variants of the functions + used. For every blocking function there is also a non-blocking, asynchronous + counterpart. Getting results asynchronously is implemented with QFuture and + QFutureWatcher. + + \section2 Example 3: Clock + + \image thread_clock.png "clock" + + We want to produce a clock application. The application has a GUI and a + worker thread. The worker thread checks every 10 milliseconds what time it + is. If the formatted time has changed, the result will be sent to the GUI + thread where it is displayed. + + Of course, this is an overly complicated way of designing a clock and, + actually, a separate thread is unnecessary. We would be better off placing + the timer in the main thread because the calculation made in the timer slot + is very short-lived. This example is purely for instructional use and shows + how to communicate from a worker thread to a GUI thread. Note that + communication in this direction is easy. We only need to add a signal + to QThread and make a queued signal/slot connection to the main thread. + Communication from the GUI to the worker thread is shown in the next + example. + + \snippet tutorials/threads/clock/main.cpp 1 + + We've connected the \c clockThread with the label. The connection must be a + queued signal-slot connection because we want to put the call in the event + loop. + + \snippet tutorials/threads/clock/clockthread.h 1 + + We have derived a class from QThread and declared the \c sendTime() signal. + + \snippet tutorials/threads/clock/clockthread.cpp 1 + + The trickiest part of this example is that the timer is connected to its + slot via a direct connection. A default connection would produce a queued + signal-slot connection because the connected objects live in different + threads; remember that QThread does not live in the thread it creates. + + Still it is safe to access ClockThread::timerHit() from the worker thread + because ClockThread::timerHit() is private and only touches local variables + and a private member that isn't touched by public methods. + QDateTime::currentDateTime() isn't marked as thread-safe in Qt + documentation, however we can get away with using it in this small + example because we know that the QDateTime::currentDateTime() static + method isn't used in any other threads. + + \section2 Example 4: A Permanent Thread + + This example shows how it is possible to have a QObject in a worker thread + that accepts requests from the GUI thread, does polling using a timer and + continuously reports results back to the GUI thread. The actual work + including the polling must be implemented in a class derived from QObject. + We have called this class \c WorkerObject in the code shown below. The + thread-specific code is hidden in a class called \c Thread, derived from + QThread. + \c Thread has two additional public members. The \c launchWorker() member + takes the worker object and moves it to another thread with a started event + loop. + The call blocks for a very short moment until the thread creation operation + is completed, allowing the worker object to be used again on the next line. + The \c Thread class's code is short but somewhat involved, so we only show + how to use the class. + + \snippet tutorials/threads/movedobject/main.cpp 1 + + QMetaObject::invokeMethod() calls a slot via the event loop. The worker + object's methods should not be called directly after the object has been + moved to another thread. We let the worker thread do some work and polling, + and use a timer to shut the application down after 3 seconds. Shutting the + worker down needs some care. We call \c{Thread::stop()} to exit the event + loop. We wait for the thread to terminate and, after this has occurred, we + delete the worker. + + \section1 Digging Deeper + + Threading is a very complicated subject. Qt offers more classes for + threading than we have presented in this tutorial. The following materials + can help you go into the subject in more depth: + + \list + \li Good video tutorials about threads with Qt can be found in the material + from the \l{Training Day at Qt Developer Days 2009}. + \li The \l{Thread Support in Qt} document is a good starting point into + the reference documentation. + \li Qt comes with several additional examples for + \l{Threading and Concurrent Programming Examples}{QThread and QtConcurrent}. + \li Several good books describe how to work with Qt threads. The most + extensive coverage can be found in \e{Advanced Qt Programming} by Mark + Summerfield, Prentice Hall - roughly 70 of 500 pages cover QThread and + QtConcurrent. + \endlist +*/ diff --git a/src/corelib/doc/src/threads.qdoc b/src/corelib/doc/src/threads.qdoc new file mode 100644 index 0000000000..80c9445f6f --- /dev/null +++ b/src/corelib/doc/src/threads.qdoc @@ -0,0 +1,705 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \group thread + \title Threading Classes +*/ + +/*! + \page threads.html + \title Thread Support in Qt + \ingroup qt-basic-concepts + \brief A detailed discussion of thread handling in Qt. + + \ingroup frameworks-technologies + + \nextpage Starting Threads with QThread + + Qt provides thread support in the form of platform-independent + threading classes, a thread-safe way of posting events, and + signal-slot connections across threads. This makes it easy to + develop portable multithreaded Qt applications and take advantage + of multiprocessor machines. Multithreaded programming is also a + useful paradigm for performing time-consuming operations without + freezing the user interface of an application. + + Earlier versions of Qt offered an option to build the library + without thread support. Since Qt 4.0, threads are always enabled. + + \section1 Topics: + + \list + \li \l{Recommended Reading} + \li \l{The Threading Classes} + \li \l{Starting Threads with QThread} + \li \l{Synchronizing Threads} + \li \l{Reentrancy and Thread-Safety} + \li \l{Threads and QObjects} + \li \l{Concurrent Programming} + \li \l{Thread-Support in Qt Modules} + \endlist + + \section1 Recommended Reading + + This document is intended for an audience that has knowledge of, + and experience with, multithreaded applications. If you are new + to threading see our Recommended Reading list: + + \list + \li \l{Threads Primer: A Guide to Multithreaded Programming} + \li \l{Thread Time: The Multithreaded Programming Guide} + \li \l{Pthreads Programming: A POSIX Standard for Better Multiprocessing} + \li \l{Win32 Multithreaded Programming} + \endlist + + \section1 The Threading Classes + + These classes are relevant to threaded applications. + + \annotatedlist thread + +\omit + \list + \li QThread provides the means to start a new thread. + \li QThreadStorage provides per-thread data storage. + \li QThreadPool manages a pool of threads that run QRunnable objects. + \li QRunnable is an abstract class representing a runnable object. + \li QMutex provides a mutual exclusion lock, or mutex. + \li QMutexLocker is a convenience class that automatically locks + and unlocks a QMutex. + \li QReadWriteLock provides a lock that allows simultaneous read access. + \li QReadLocker and QWriteLocker are convenience classes that automatically + lock and unlock a QReadWriteLock. + \li QSemaphore provides an integer semaphore (a generalization of a mutex). + \li QWaitCondition provides a way for threads to go to sleep until + woken up by another thread. + \li QAtomicInt provides atomic operations on integers. + \li QAtomicPointer provides atomic operations on pointers. + \endlist +\endomit + + \note Qt's threading classes are implemented with native threading APIs; + e.g., Win32 and pthreads. Therefore, they can be used with threads of the + same native API. +*/ + +/*! + \page threads-starting.html + \title Starting Threads with QThread + + \contentspage Thread Support in Qt + \nextpage Synchronizing Threads + + A QThread instance represents a thread and provides the means to + \l{QThread::start()}{start()} a thread, which will then execute the + reimplementation of QThread::run(). The \c run() implementation is for a + thread what the \c main() entry point is for the application. All code + executed in a call stack that starts in the \c run() function is executed + by the new thread, and the thread finishes when the function returns. + QThread emits signals to indicate that the thread started or finished + executing. + + \section1 Creating a Thread + + To create a thread, subclass QThread and reimplement its + \l{QThread::run()}{run()} function. For example: + + \snippet threads/threads.h 0 + \codeline + \snippet threads/threads.cpp 0 + \snippet threads/threads.cpp 1 + \dots + \snippet threads/threads.cpp 2 + + \section1 Starting a Thread + + Then, create an instance of the thread object and call + QThread::start(). Note that you must create the QApplication (or + QCoreApplication) object before you can create a QThread. + + The function will return immediately and the + main thread will continue. The code that appears in the + \l{QThread::run()}{run()} reimplementation will then be executed + in a separate thread. + + Creating threads is explained in more detail in the QThread + documentation. + + Note that QCoreApplication::exec() must always be called from the + main thread (the thread that executes \c{main()}), not from a + QThread. In GUI applications, the main thread is also called the + GUI thread because it's the only thread that is allowed to + perform GUI-related operations. +*/ + +/*! + \page threads-synchronizing.html + \title Synchronizing Threads + + \previouspage Starting Threads with QThread + \contentspage Thread Support in Qt + \nextpage Reentrancy and Thread-Safety + + The QMutex, QReadWriteLock, QSemaphore, and QWaitCondition + classes provide means to synchronize threads. While the main idea + with threads is that they should be as concurrent as possible, + there are points where threads must stop and wait for other + threads. For example, if two threads try to access the same + global variable simultaneously, the results are usually + undefined. + + QMutex provides a mutually exclusive lock, or mutex. At most one + thread can hold the mutex at any time. If a thread tries to + acquire the mutex while the mutex is already locked, the thread will + be put to sleep until the thread that currently holds the mutex + unlocks it. Mutexes are often used to protect accesses to shared + data (i.e., data that can be accessed from multiple threads + simultaneously). In the \l{Reentrancy and Thread-Safety} section + below, we will use it to make a class thread-safe. + + QReadWriteLock is similar to QMutex, except that it distinguishes + between "read" and "write" access to shared data and allows + multiple readers to access the data simultaneously. Using + QReadWriteLock instead of QMutex when it is possible can make + multithreaded programs more concurrent. + + QSemaphore is a generalization of QMutex that protects a certain + number of identical resources. In contrast, a mutex protects + exactly one resource. The \l{threads/semaphores}{Semaphores} + example shows a typical application of semaphores: synchronizing + access to a circular buffer between a producer and a consumer. + + QWaitCondition allows a thread to wake up other threads when some + condition has been met. One or many threads can block waiting for + a QWaitCondition to set a condition with + \l{QWaitCondition::wakeOne()}{wakeOne()} or + \l{QWaitCondition::wakeAll()}{wakeAll()}. Use + \l{QWaitCondition::wakeOne()}{wakeOne()} to wake one randomly + selected event or \l{QWaitCondition::wakeAll()}{wakeAll()} to + wake them all. The \l{threads/waitconditions}{Wait Conditions} + example shows how to solve the producer-consumer problem using + QWaitCondition instead of QSemaphore. + + Note that Qt's synchronization classes rely on the use of properly + aligned pointers. For instance, you cannot use packed classes with + MSVC. +*/ + +/*! + \page threads-reentrancy.html + \title Reentrancy and Thread-Safety + + \keyword reentrant + \keyword thread-safe + + \previouspage Synchronizing Threads + \contentspage Thread Support in Qt + \nextpage Threads and QObjects + + Throughout the documentation, the terms \e{reentrant} and + \e{thread-safe} are used to mark classes and functions to indicate + how they can be used in multithread applications: + + \list + \li A \e thread-safe function can be called simultaneously from + multiple threads, even when the invocations use shared data, + because all references to the shared data are serialized. + \li A \e reentrant function can also be called simultaneously from + multiple threads, but only if each invocation uses its own data. + \endlist + + Hence, a \e{thread-safe} function is always \e{reentrant}, but a + \e{reentrant} function is not always \e{thread-safe}. + + By extension, a class is said to be \e{reentrant} if its member + functions can be called safely from multiple threads, as long as + each thread uses a \e{different} instance of the class. The class + is \e{thread-safe} if its member functions can be called safely + from multiple threads, even if all the threads use the \e{same} + instance of the class. + + \note Qt classes are only documented as \e{thread-safe} if they + are intended to be used by multiple threads. If a function is not + marked as thread-safe or reentrant, it should not be used from + different threads. If a class is not marked as thread-safe or + reentrant then a specific instance of that class should not be + accessed from different threads. + + \section1 Reentrancy + + C++ classes are often reentrant, simply because they only access + their own member data. Any thread can call a member function on an + instance of a reentrant class, as long as no other thread can call + a member function on the \e{same} instance of the class at the + same time. For example, the \c Counter class below is reentrant: + + \snippet threads/threads.cpp 3 + \snippet threads/threads.cpp 4 + + The class isn't thread-safe, because if multiple threads try to + modify the data member \c n, the result is undefined. This is + because the \c ++ and \c -- operators aren't always atomic. + Indeed, they usually expand to three machine instructions: + + \list 1 + \li Load the variable's value in a register. + \li Increment or decrement the register's value. + \li Store the register's value back into main memory. + \endlist + + If thread A and thread B load the variable's old value + simultaneously, increment their register, and store it back, they + end up overwriting each other, and the variable is incremented + only once! + + \section1 Thread-Safety + + Clearly, the access must be serialized: Thread A must perform + steps 1, 2, 3 without interruption (atomically) before thread B + can perform the same steps; or vice versa. An easy way to make + the class thread-safe is to protect all access to the data + members with a QMutex: + + \snippet threads/threads.cpp 5 + \snippet threads/threads.cpp 6 + + The QMutexLocker class automatically locks the mutex in its + constructor and unlocks it when the destructor is invoked, at the + end of the function. Locking the mutex ensures that access from + different threads will be serialized. The \c mutex data member is + declared with the \c mutable qualifier because we need to lock + and unlock the mutex in \c value(), which is a const function. + + \section1 Notes on Qt Classes + + Many Qt classes are \e{reentrant}, but they are not made + \e{thread-safe}, because making them thread-safe would incur the + extra overhead of repeatedly locking and unlocking a QMutex. For + example, QString is reentrant but not thread-safe. You can safely + access \e{different} instances of QString from multiple threads + simultaneously, but you can't safely access the \e{same} instance + of QString from multiple threads simultaneously (unless you + protect the accesses yourself with a QMutex). + + Some Qt classes and functions are thread-safe. These are mainly + the thread-related classes (e.g. QMutex) and fundamental functions + (e.g. QCoreApplication::postEvent()). + + \note Terminology in the multithreading domain isn't entirely + standardized. POSIX uses definitions of reentrant and thread-safe + that are somewhat different for its C APIs. When using other + object-oriented C++ class libraries with Qt, be sure the + definitions are understood. +*/ + +/*! + \page threads-qobject.html + \title Threads and QObjects + + \previouspage Reentrancy and Thread Safety + \contentspage Thread Support in Qt + \nextpage Concurrent Programming + + QThread inherits QObject. It emits signals to indicate that the + thread started or finished executing, and provides a few slots as + well. + + More interesting is that \l{QObject}s can be used in multiple + threads, emit signals that invoke slots in other threads, and + post events to objects that "live" in other threads. This is + possible because each thread is allowed to have its own event + loop. + + \section1 QObject Reentrancy + + QObject is reentrant. Most of its non-GUI subclasses, such as + QTimer, QTcpSocket, QUdpSocket and QProcess, are also + reentrant, making it possible to use these classes from multiple + threads simultaneously. Note that these classes are designed to be + created and used from within a single thread; creating an object + in one thread and calling its functions from another thread is not + guaranteed to work. There are three constraints to be aware of: + + \list + \li \e{The child of a QObject must always be created in the thread + where the parent was created.} This implies, among other + things, that you should never pass the QThread object (\c + this) as the parent of an object created in the thread (since + the QThread object itself was created in another thread). + + \li \e{Event driven objects may only be used in a single thread.} + Specifically, this applies to the \l{timers.html}{timer + mechanism} and the \l{QtNetwork}{network module}. For example, + you cannot start a timer or connect a socket in a thread that + is not the \l{QObject::thread()}{object's thread}. + + \li \e{You must ensure that all objects created in a thread are + deleted before you delete the QThread.} This can be done + easily by creating the objects on the stack in your + \l{QThread::run()}{run()} implementation. + \endlist + + Although QObject is reentrant, the GUI classes, notably QWidget + and all its subclasses, are not reentrant. They can only be used + from the main thread. As noted earlier, QCoreApplication::exec() + must also be called from that thread. + + In practice, the impossibility of using GUI classes in other + threads than the main thread can easily be worked around by + putting time-consuming operations in a separate worker thread and + displaying the results on screen in the main thread when the + worker thread is finished. This is the approach used for + implementing the \l{threads/mandelbrot}{Mandelbrot} and + the \l{network/blockingfortuneclient}{Blocking Fortune Client} + example. + + \section1 Per-Thread Event Loop + + Each thread can have its own event loop. The initial thread + starts its event loops using QCoreApplication::exec(); other + threads can start an event loop using QThread::exec(). Like + QCoreApplication, QThread provides an + \l{QThread::exit()}{exit(int)} function and a + \l{QThread::quit()}{quit()} slot. + + An event loop in a thread makes it possible for the thread to use + certain non-GUI Qt classes that require the presence of an event + loop (such as QTimer, QTcpSocket, and QProcess). It also makes it + possible to connect signals from any threads to slots of a + specific thread. This is explained in more detail in the + \l{Signals and Slots Across Threads} section below. + + \image threadsandobjects.png Threads, objects, and event loops + + A QObject instance is said to \e live in the thread in which it + is created. Events to that object are dispatched by that thread's + event loop. The thread in which a QObject lives is available using + QObject::thread(). + + Note that for QObjects that are created before QApplication, + QObject::thread() returns zero. This means that the main thread + will only handle posted events for these objects; other event + processing is not done at all for objects with no thread. Use the + QObject::moveToThread() function to change the thread affinity for + an object and its children (the object cannot be moved if it has a + parent). + + Calling \c delete on a QObject from a thread other than the one + that \e owns the object (or accessing the object in other ways) is + unsafe, unless you guarantee that the object isn't processing + events at that moment. Use QObject::deleteLater() instead, and a + \l{QEvent::DeferredDelete}{DeferredDelete} event will be posted, + which the event loop of the object's thread will eventually pick + up. By default, the thread that \e owns a QObject is the thread + that \e creates the QObject, but not after QObject::moveToThread() + has been called. + + If no event loop is running, events won't be delivered to the + object. For example, if you create a QTimer object in a thread but + never call \l{QThread::exec()}{exec()}, the QTimer will never emit + its \l{QTimer::timeout()}{timeout()} signal. Calling + \l{QObject::deleteLater()}{deleteLater()} won't work + either. (These restrictions apply to the main thread as well.) + + You can manually post events to any object in any thread at any + time using the thread-safe function + QCoreApplication::postEvent(). The events will automatically be + dispatched by the event loop of the thread where the object was + created. + + Event filters are supported in all threads, with the restriction + that the monitoring object must live in the same thread as the + monitored object. Similarly, QCoreApplication::sendEvent() + (unlike \l{QCoreApplication::postEvent()}{postEvent()}) can only + be used to dispatch events to objects living in the thread from + which the function is called. + + \section1 Accessing QObject Subclasses from Other Threads + + QObject and all of its subclasses are not thread-safe. This + includes the entire event delivery system. It is important to keep + in mind that the event loop may be delivering events to your + QObject subclass while you are accessing the object from another + thread. + + If you are calling a function on an QObject subclass that doesn't + live in the current thread and the object might receive events, + you must protect all access to your QObject subclass's internal + data with a mutex; otherwise, you may experience crashes or other + undesired behavior. + + Like other objects, QThread objects live in the thread where the + object was created -- \e not in the thread that is created when + QThread::run() is called. It is generally unsafe to provide slots + in your QThread subclass, unless you protect the member variables + with a mutex. + + On the other hand, you can safely emit signals from your + QThread::run() implementation, because signal emission is + thread-safe. + + \section1 Signals and Slots Across Threads + + Qt supports these signal-slot connection types: + + \list + + \li \l{Qt::AutoConnection}{Auto Connection} (default) If the signal is + emitted in the thread which the receiving object has affinity then + the behavior is the same as the Direct Connection. Otherwise, + the behavior is the same as the Queued Connection." + + \li \l{Qt::DirectConnection}{Direct Connection} The slot is invoked + immediately, when the signal is emitted. The slot is executed + in the emitter's thread, which is not necessarily the + receiver's thread. + + \li \l{Qt::QueuedConnection}{Queued Connection} The slot is invoked + when control returns to the event loop of the receiver's + thread. The slot is executed in the receiver's thread. + + \li \l{Qt::BlockingQueuedConnection}{Blocking Queued Connection} + The slot is invoked as for the Queued Connection, except the + current thread blocks until the slot returns. \note Using this + type to connect objects in the same thread will cause deadlock. + + \li \l{Qt::UniqueConnection}{Unique Connection} The behavior is the + same as the Auto Connection, but the connection is made only if + it does not duplicate an existing connection. i.e., if the same + signal is already connected to the same slot for the same pair + of objects, then the connection is not made and connect() + returns false. + + \endlist + + The connection type can be specified by passing an additional + argument to \l{QObject::connect()}{connect()}. Be aware that + using direct connections when the sender and receiver live in + different threads is unsafe if an event loop is running in the + receiver's thread, for the same reason that calling any function + on an object living in another thread is unsafe. + + QObject::connect() itself is thread-safe. + + The \l{threads/mandelbrot}{Mandelbrot} example uses a queued + connection to communicate between a worker thread and the main + thread. To avoid freezing the main thread's event loop (and, as a + consequence, the application's user interface), all the + Mandelbrot fractal computation is done in a separate worker + thread. The thread emits a signal when it is done rendering the + fractal. + + Similarly, the \l{network/blockingfortuneclient}{Blocking Fortune + Client} example uses a separate thread for communicating with + a TCP server asynchronously. +*/ + +/*! + \page threads-qtconcurrent.html + \title Concurrent Programming + + \previouspage Threads and QObjects + \contentspage Thread Support in Qt + \nextpage Thread-Support in Qt Modules + + \target qtconcurrent intro + + The QtConcurrent namespace provides high-level APIs that make it + possible to write multi-threaded programs without using low-level + threading primitives such as mutexes, read-write locks, wait + conditions, or semaphores. Programs written with QtConcurrent + automatically adjust the number of threads used according to the + number of processor cores available. This means that applications + written today will continue to scale when deployed on multi-core + systems in the future. + + QtConcurrent includes functional programming style APIs for + parallel list processing, including a MapReduce and FilterReduce + implementation for shared-memory (non-distributed) systems, and + classes for managing asynchronous computations in GUI + applications: + + \list + + \li QtConcurrent::map() applies a function to every item in a container, + modifying the items in-place. + + \li QtConcurrent::mapped() is like map(), except that it returns a new + container with the modifications. + + \li QtConcurrent::mappedReduced() is like mapped(), except that the + modified results are reduced or folded into a single result. + + \li QtConcurrent::filter() removes all items from a container based on the + result of a filter function. + + \li QtConcurrent::filtered() is like filter(), except that it returns a new + container with the filtered results. + + \li QtConcurrent::filteredReduced() is like filtered(), except that the + filtered results are reduced or folded into a single result. + + \li QtConcurrent::run() runs a function in another thread. + + \li QFuture represents the result of an asynchronous computation. + + \li QFutureIterator allows iterating through results available via QFuture. + + \li QFutureWatcher allows monitoring a QFuture using signals-and-slots. + + \li QFutureSynchronizer is a convenience class that automatically + synchronizes several QFutures. + + \endlist + + Qt Concurrent supports several STL-compatible container and iterator types, + but works best with Qt containers that have random-access iterators, such as + QList or QVector. The map and filter functions accept both containers and begin/end iterators. + + STL Iterator support overview: + + \table + \header + \li Iterator Type + \li Example classes + \li Support status + \row + \li Input Iterator + \li + \li Not Supported + \row + \li Output Iterator + \li + \li Not Supported + \row + \li Forward Iterator + \li std::slist + \li Supported + \row + \li Bidirectional Iterator + \li QLinkedList, std::list + \li Supported + \row + \li Random Access Iterator + \li QList, QVector, std::vector + \li Supported and Recommended + \endtable + + Random access iterators can be faster in cases where Qt Concurrent is iterating + over a large number of lightweight items, since they allow skipping to any point + in the container. In addition, using random access iterators allows Qt Concurrent + to provide progress information trough QFuture::progressValue() and QFutureWatcher:: + progressValueChanged(). + + The non in-place modifying functions such as mapped() and filtered() makes a + copy of the container when called. If you are using STL containers this copy operation + might take some time, in this case we recommend specifying the begin and end iterators + for the container instead. +*/ + +/*! + \page threads-modules.html + \title Thread-Support in Qt Modules + + \previouspage Concurrent Programming + \contentspage Thread Support in Qt + + \section1 Threads and the SQL Module + + A connection can only be used from within the thread that created it. + Moving connections between threads or creating queries from a different + thread is not supported. + + In addition, the third party libraries used by the QSqlDrivers can impose + further restrictions on using the SQL Module in a multithreaded program. + Consult the manual of your database client for more information + + \section1 Painting in Threads + + QPainter can be used in a thread to paint onto QImage, QPrinter, and + QPicture paint devices. Painting onto QPixmaps and QWidgets is \e not + supported. On Mac OS X the automatic progress dialog will not be + displayed if you are printing from outside the GUI thread. + + Any number of threads can paint at any given time, however only + one thread at a time can paint on a given paint device. In other + words, two threads can paint at the same time if each paints onto + separate QImages, but the two threads cannot paint onto the same + QImage at the same time. + + Note that on X11 systems without FontConfig support, Qt cannot + render text outside of the GUI thread. You can use the + QFontDatabase::supportsThreadedFontRendering() function to detect + whether or not font rendering can be used outside the GUI thread. + + \section1 Threads and Rich Text Processing + + The QTextDocument, QTextCursor, and \link richtext.html all + related classes\endlink are reentrant. + + Note that a QTextDocument instance created in the GUI thread may + contain QPixmap image resources. Use QTextDocument::clone() to + create a copy of the document, and pass the copy to another thread for + further processing (such as printing). + + \section1 Threads and the SVG module + + The QSvgGenerator and QSvgRenderer classes in the QtSvg module + are reentrant. + + \section1 Threads and Implicitly Shared Classes + + Qt uses an optimization called \l{implicit sharing} for many of + its value class, notably QImage and QString. Beginning with Qt 4, + implicit shared classes can safely be copied across threads, like + any other value classes. They are fully + \l{Reentrancy and Thread-Safety}{reentrant}. The implicit sharing + is really \e implicit. + + In many people's minds, implicit sharing and multithreading are + incompatible concepts, because of the way the reference counting + is typically done. Qt, however, uses atomic reference counting to + ensure the integrity of the shared data, avoiding potential + corruption of the reference counter. + + Note that atomic reference counting does not guarantee + \l{Reentrancy and Thread-Safety}{thread-safety}. Proper locking should be used + when sharing an instance of an implicitly shared class between + threads. This is the same requirement placed on all + \l{Reentrancy and Thread-Safety}{reentrant} classes, shared or not. Atomic reference + counting does, however, guarantee that a thread working on its + own, local instance of an implicitly shared class is safe. We + recommend using \l{Signals and Slots Across Threads}{signals and + slots} to pass data between threads, as this can be done without + the need for any explicit locking. + + To sum it up, implicitly shared classes in Qt 4 are really \e + implicitly shared. Even in multithreaded applications, you can + safely use them as if they were plain, non-shared, reentrant + value-based classes. +*/ diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 2f7611f774..99078b17f4 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -126,7 +126,7 @@ QT_BEGIN_NAMESPACE Qt::Alignment parameter, which means that any combination of Qt::AlignmentFlag values,or 0, is legal: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 0 + \snippet code/src_corelib_global_qglobal.cpp 0 If you try to pass a value from another enum or just a plain integer other than 0, the compiler will report an error. If you @@ -138,7 +138,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 1 + \snippet code/src_corelib_global_qglobal.cpp 1 You can then use the \c MyClass::Options type to store combinations of \c MyClass::Option values. @@ -150,7 +150,7 @@ QT_BEGIN_NAMESPACE To make the flags available for these purposes, the Q_FLAGS() macro must be used: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp meta-object flags + \snippet code/src_corelib_global_qglobal.cpp meta-object flags \section1 Naming Convention @@ -353,18 +353,18 @@ QT_BEGIN_NAMESPACE The curious user will have seen that the Qt classes derived from QObject typically include this macro in a private section: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 43 + \snippet code/src_corelib_global_qglobal.cpp 43 It declares a copy constructor and an assignment operator in the private section, so that if you use them by mistake, the compiler will report an error. - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 44 + \snippet code/src_corelib_global_qglobal.cpp 44 But even this might not catch absolutely every case. You might be tempted to do something like this: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 45 + \snippet code/src_corelib_global_qglobal.cpp 45 First of all, don't do that. Most compilers will generate code that uses the copy constructor, so the privacy violation error will be @@ -382,7 +382,7 @@ QT_BEGIN_NAMESPACE The Q_DECLARE_FLAGS() macro expands to - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 2 + \snippet code/src_corelib_global_qglobal.cpp 2 \a Enum is the name of an existing enum type, whereas \a Flags is the name of the QFlags<\e{Enum}> typedef. @@ -461,7 +461,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 3 + \snippet code/src_corelib_global_qglobal.cpp 3 also contains functions that generate messages from the given string argument: qCritical(), qDebug(), qFatal() and @@ -470,7 +470,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 4 + \snippet code/src_corelib_global_qglobal.cpp 4 The remaining functions are qRound() and qRound64(), which both accept a \l qreal value as their argument returning the value @@ -532,22 +532,6 @@ QT_BEGIN_NAMESPACE Convenience typedef for \c{unsigned char}. */ -/*! - \fn qt_set_sequence_auto_mnemonic(bool on) - \relates - - Enables automatic mnemonics on Mac if \a on is true; otherwise - this feature is disabled. - - Note that this function is only available on Mac where mnemonics - are disabled by default. - - To access to this function, use an extern declaration: - extern void qt_set_sequence_auto_mnemonic(bool b); - - \sa {QShortcut#mnemonic}{QShortcut} -*/ - /*! \typedef ushort \relates @@ -619,7 +603,7 @@ QT_BEGIN_NAMESPACE Literals of this type can be created using the Q_INT64_C() macro: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 5 + \snippet code/src_corelib_global_qglobal.cpp 5 \sa Q_INT64_C(), quint64, qlonglong */ @@ -635,7 +619,7 @@ QT_BEGIN_NAMESPACE Literals of this type can be created using the Q_UINT64_C() macro: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 6 + \snippet code/src_corelib_global_qglobal.cpp 6 \sa Q_UINT64_C(), qint64, qulonglong */ @@ -712,7 +696,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 8 + \snippet code/src_corelib_global_qglobal.cpp 8 \sa qint64, Q_UINT64_C() */ @@ -725,7 +709,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 9 + \snippet code/src_corelib_global_qglobal.cpp 9 \sa quint64, Q_INT64_C() */ @@ -758,7 +742,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 10 + \snippet code/src_corelib_global_qglobal.cpp 10 */ /*! \fn int qRound(qreal value) @@ -768,7 +752,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 11 + \snippet code/src_corelib_global_qglobal.cpp 11 */ /*! \fn qint64 qRound64(qreal value) @@ -778,7 +762,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 12 + \snippet code/src_corelib_global_qglobal.cpp 12 */ /*! \fn const T &qMin(const T &value1, const T &value2) @@ -788,7 +772,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 13 + \snippet code/src_corelib_global_qglobal.cpp 13 \sa qMax(), qBound() */ @@ -800,7 +784,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 14 + \snippet code/src_corelib_global_qglobal.cpp 14 \sa qMin(), qBound() */ @@ -813,7 +797,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 15 + \snippet code/src_corelib_global_qglobal.cpp 15 \sa qMin(), qMax() */ @@ -843,7 +827,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 16 + \snippet code/src_corelib_global_qglobal.cpp 16 \sa QT_VERSION_STR, qVersion() */ @@ -1769,12 +1753,12 @@ const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion() Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 17 + \snippet code/src_corelib_global_qglobal.cpp 17 If \c b is zero, the Q_ASSERT statement will output the following message using the qFatal() function: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 18 + \snippet code/src_corelib_global_qglobal.cpp 18 \sa Q_ASSERT_X(), qFatal(), {Debugging Techniques} */ @@ -1792,12 +1776,12 @@ const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion() Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 19 + \snippet code/src_corelib_global_qglobal.cpp 19 If \c b is zero, the Q_ASSERT_X statement will output the following message using the qFatal() function: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 20 + \snippet code/src_corelib_global_qglobal.cpp 20 \sa Q_ASSERT(), qFatal(), {Debugging Techniques} */ @@ -1812,7 +1796,7 @@ const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion() conditions that it would not otherwise know about. However, there is no guarantee that the compiler will actually use those hints. - This macro could be considered a "lighter" version of \ref Q_ASSERT. While + This macro could be considered a "lighter" version of \l{Q_ASSERT}. While Q_ASSERT will abort the program's execution if the condition is false, Q_ASSUME will tell the compiler not to generate code for those conditions. Therefore, it is important that the assumptions always hold, otherwise @@ -1841,11 +1825,11 @@ const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion() This macro is useful to mark impossible conditions. For example, given the following enum: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qunreachable-enum + \snippet code/src_corelib_global_qglobal.cpp qunreachable-enum One can write a switch table like so: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qunreachable-switch + \snippet code/src_corelib_global_qglobal.cpp qunreachable-switch The advantage of inserting Q_UNREACHABLE() at that point is that the compiler is told not to generate code for a shape variable containing that @@ -1872,7 +1856,7 @@ const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion() Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 21 + \snippet code/src_corelib_global_qglobal.cpp 21 \sa qWarning(), {Debugging Techniques} */ @@ -1896,7 +1880,7 @@ const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion() Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 22 + \snippet code/src_corelib_global_qglobal.cpp 22 when instantiated with the integer type, will with the GCC compiler produce: @@ -2217,14 +2201,14 @@ int qrand() Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 31 + \snippet code/src_corelib_global_qglobal.cpp 31 It is equivalent to \c{for (;;)}. If you're worried about namespace pollution, you can disable this macro by adding the following line to your \c .pro file: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 32 + \snippet code/src_corelib_global_qglobal.cpp 32 \sa Q_FOREVER */ @@ -2254,7 +2238,7 @@ int qrand() If you're worried about namespace pollution, you can disable this macro by adding the following line to your \c .pro file: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 33 + \snippet code/src_corelib_global_qglobal.cpp 33 \sa Q_FOREACH() */ @@ -2283,7 +2267,7 @@ int qrand() Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 34 + \snippet code/src_corelib_global_qglobal.cpp 34 The macro QT_TR_NOOP_UTF8() is identical except that it tells lupdate that the source string is encoded in UTF-8. Corresponding variants @@ -2305,7 +2289,7 @@ int qrand() Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 35 + \snippet code/src_corelib_global_qglobal.cpp 35 \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP3(), {Internationalization with Qt} */ @@ -2326,7 +2310,7 @@ int qrand() Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 36 + \snippet code/src_corelib_global_qglobal.cpp 36 \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP(), {Internationalization with Qt} */ @@ -2354,11 +2338,11 @@ int qrand() or - \tt{\begincomment% \endcomment} + \tt{\\begincomment% \\endcomment} Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qttrid + \snippet code/src_corelib_global_qglobal.cpp qttrid Creating QM files suitable for use with this function requires passing the \c -idbased option to the \c lrelease tool. @@ -2385,7 +2369,7 @@ int qrand() Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qttrid_noop + \snippet code/src_corelib_global_qglobal.cpp qttrid_noop \sa qtTrId(), {Internationalization with Qt} */ @@ -2402,7 +2386,7 @@ int qrand() Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qlikely + \snippet code/src_corelib_global_qglobal.cpp qlikely \sa Q_UNLIKELY() */ @@ -2419,7 +2403,7 @@ int qrand() Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qunlikely + \snippet code/src_corelib_global_qglobal.cpp qunlikely \sa Q_LIKELY() */ @@ -2496,7 +2480,7 @@ int qrand() Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 37 + \snippet code/src_corelib_global_qglobal.cpp 37 \sa qDebug(), qWarning(), qCritical(), qFatal() @@ -2528,7 +2512,7 @@ int qrand() Example of a "primitive" type: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 38 + \snippet code/src_corelib_global_qglobal.cpp 38 An example of a non-POD "primitive" type is QUuid: Even though QUuid has constructors (and therefore isn't POD), every bit @@ -2537,7 +2521,7 @@ int qrand() Example of a movable type: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 39 + \snippet code/src_corelib_global_qglobal.cpp 39 */ /*! @@ -2607,7 +2591,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) Use this macro as in the following examples. - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 40 + \snippet code/src_corelib_global_qglobal.cpp 40 \sa Q_BIG_ENDIAN, Q_LITTLE_ENDIAN */ @@ -2622,7 +2606,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) lowest address. The other bytes follow in increasing order of significance. - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 41 + \snippet code/src_corelib_global_qglobal.cpp 41 \sa Q_BYTE_ORDER, Q_BIG_ENDIAN */ @@ -2637,7 +2621,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) lowest address. The other bytes follow in decreasing order of significance. - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 42 + \snippet code/src_corelib_global_qglobal.cpp 42 \sa Q_BYTE_ORDER, Q_LITTLE_ENDIAN */ @@ -2720,7 +2704,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) This macro expands to - \snippet snippets/code/src_corelib_global_qglobal.cpp begin namespace macro + \snippet code/src_corelib_global_qglobal.cpp begin namespace macro if \c QT_NAMESPACE is defined and nothing otherwise. If should always appear in the file-level scope and be followed by \c QT_END_NAMESPACE @@ -2754,7 +2738,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) This macro expands to - \snippet snippets/code/src_corelib_global_qglobal.cpp end namespace macro + \snippet code/src_corelib_global_qglobal.cpp end namespace macro if \c QT_NAMESPACE is defined and nothing otherwise. It is used to cancel the effect of \c QT_BEGIN_NAMESPACE. @@ -2821,7 +2805,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) Note that comparing values where either \a p1 or \a p2 is 0.0 will not work. The solution to this is to compare against values greater than or equal to 1.0. - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 46 + \snippet code/src_corelib_global_qglobal.cpp 46 The two numbers are compared in a relative way, where the exactness is stronger the smaller the numbers are. @@ -2856,7 +2840,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) Example: - \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 4 + \snippet code/src_gui_dialogs_qmessagebox.cpp 4 */ /*! @@ -2908,12 +2892,12 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 24 + \snippet code/src_corelib_global_qglobal.cpp 24 If you include \c , a more convenient syntax is also available: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 25 + \snippet code/src_corelib_global_qglobal.cpp 25 With this syntax, the function returns a QDebug object that is configured to use the QtDebugMsg message type. It automatically @@ -2943,12 +2927,12 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) string. Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 26 + \snippet code/src_corelib_global_qglobal.cpp 26 If you include , a more convenient syntax is also available: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 27 + \snippet code/src_corelib_global_qglobal.cpp 27 This syntax inserts a space between each item, and appends a newline at the end. @@ -2973,12 +2957,12 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) string. Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 28 + \snippet code/src_corelib_global_qglobal.cpp 28 If you include , a more convenient syntax is also available: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 29 + \snippet code/src_corelib_global_qglobal.cpp 29 A space is inserted between the items, and a newline is appended at the end. @@ -3007,7 +2991,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) similar to the C printf() function. Example: - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 30 + \snippet code/src_corelib_global_qglobal.cpp 30 To suppress the output at runtime, install your own message handler with qInstallMessageHandler(). @@ -3016,77 +3000,4 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) {Debugging Techniques} */ -/*! - \typedef QtMsgHandler - \relates - \deprecated - - This is a typedef for a pointer to a function with the following - signature: - - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 7 - - This typedef is deprecated, you should use QMessageHandler instead. - \sa QtMsgType, QMessageHandler, qInstallMsgHandler(), qInstallMessageHandler() -*/ - -/*! - \typedef QMessageHandler - \relates - \since 5.0 - - This is a typedef for a pointer to a function with the following - signature: - - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 49 - - \sa QtMsgType, qInstallMessageHandler() -*/ - -/*! - \fn QMessageHandler qInstallMessageHandler(QMessageHandler handler) - \relates - \since 5.0 - - Installs a Qt message \a handler which has been defined - previously. Returns a pointer to the previous message handler - (which may be 0). - - The message handler is a function that prints out debug messages, - warnings, critical and fatal error messages. The Qt library (debug - mode) contains hundreds of warning messages that are printed - when internal errors (usually invalid function arguments) - occur. Qt built in release mode also contains such warnings unless - QT_NO_WARNING_OUTPUT and/or QT_NO_DEBUG_OUTPUT have been set during - compilation. If you implement your own message handler, you get total - control of these messages. - - The default message handler prints the message to the standard - output under X11 or to the debugger under Windows. If it is a - fatal message, the application aborts immediately. - - Only one message handler can be defined, since this is usually - done on an application-wide basis to control debug output. - - To restore the message handler, call \c qInstallMessageHandler(0). - - Example: - - \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 23 - - \sa QMessageHandler, QtMsgType, qDebug(), qWarning(), qCritical(), qFatal(), - {Debugging Techniques} -*/ - -/*! - \fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler) - \relates - \deprecated - - Installs a Qt message \a handler which has been defined - previously. This method is deprecated, use qInstallMessageHandler - instead. - \sa QtMsgHandler, qInstallMessageHandler -*/ - QT_END_NAMESPACE diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index afefb11aa1..f30df92a54 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -82,7 +82,7 @@ QT_BEGIN_NAMESPACE One example of direct use is to forward errors that stem from a scripting language, e.g. QML: - \snippet doc/src/snippets/code/qlogging/qloggingsnippet.cpp 1 + \snippet code/qlogging/qlogging.cpp 1 \sa QMessageLogContext, qDebug(), qWarning(), qCritical(), qFatal() */ @@ -132,7 +132,6 @@ static void qt_message(QtMsgType msgType, const QMessageLogContext &context, con } #undef qDebug - void QMessageLogger::debug(const char *msg, ...) { va_list ap; @@ -178,7 +177,6 @@ QDebug QMessageLogger::warning() #endif #undef qCritical - void QMessageLogger::critical(const char *msg, ...) { va_list ap; @@ -198,7 +196,6 @@ QDebug QMessageLogger::critical() #endif #undef qFatal - void QMessageLogger::fatal(const char *msg, ...) { va_list ap; @@ -652,6 +649,79 @@ extern Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogConte const char *str); #endif +/*! + \typedef QtMsgHandler + \relates + \deprecated + + This is a typedef for a pointer to a function with the following + signature: + + \snippet code/src_corelib_global_qglobal.cpp 7 + + This typedef is deprecated, you should use QMessageHandler instead. + \sa QtMsgType, QMessageHandler, qInstallMsgHandler(), qInstallMessageHandler() +*/ + +/*! + \fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler) + \relates + \deprecated + + Installs a Qt message \a handler which has been defined + previously. This method is deprecated, use qInstallMessageHandler + instead. + \sa QtMsgHandler, qInstallMessageHandler +*/ + +/*! + \typedef QMessageHandler + \relates + \since 5.0 + + This is a typedef for a pointer to a function with the following + signature: + + \snippet code/src_corelib_global_qglobal.cpp 49 + + \sa QtMsgType, qInstallMessageHandler() +*/ + +/*! + \fn QMessageHandler qInstallMessageHandler(QMessageHandler handler) + \relates + \since 5.0 + + Installs a Qt message \a handler which has been defined + previously. Returns a pointer to the previous message handler + (which may be 0). + + The message handler is a function that prints out debug messages, + warnings, critical and fatal error messages. The Qt library (debug + mode) contains hundreds of warning messages that are printed + when internal errors (usually invalid function arguments) + occur. Qt built in release mode also contains such warnings unless + QT_NO_WARNING_OUTPUT and/or QT_NO_DEBUG_OUTPUT have been set during + compilation. If you implement your own message handler, you get total + control of these messages. + + The default message handler prints the message to the standard + output under X11 or to the debugger under Windows. If it is a + fatal message, the application aborts immediately. + + Only one message handler can be defined, since this is usually + done on an application-wide basis to control debug output. + + To restore the message handler, call \c qInstallMessageHandler(0). + + Example: + + \snippet code/src_corelib_global_qglobal.cpp 23 + + \sa qDebug(), qWarning(), qCritical(), qFatal(), QtMsgType, + {Debugging Techniques} +*/ + QMessageHandler qInstallMessageHandler(QMessageHandler h) { if (!messageHandler) diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 881b55037d..76ad61d299 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -230,7 +230,7 @@ actual 'Mouse Buttons', the device must be re-configured (using the vendor's configuration tool). - \sa KeyboardModifier Modifier + \sa KeyboardModifier, Modifier */ /*! @@ -257,7 +257,7 @@ \note On Windows Keyboards, Qt::MetaModifier and Qt::Key_Meta are mapped to the Windows key. - \sa MouseButton Modifier + \sa MouseButton, Modifier */ /*! @@ -278,7 +278,7 @@ point, not as a Qt Key. \omitvalue MODIFIER_MASK - \sa KeyboardModifier MouseButton + \sa KeyboardModifier, MouseButton */ /*! @@ -542,7 +542,7 @@ arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message: - \snippet doc/src/snippets/code/doc_src_qnamespace.qdoc 0 + \snippet code/doc_src_qnamespace.qdoc 0 Call qRegisterMetaType() to register the data type before you establish the connection. @@ -1981,8 +1981,6 @@ system supports it, a tool window can be decorated with a somewhat lighter frame. It can also be combined with Qt::FramelessWindowHint. - \br - \br On Mac OS X, tool windows correspond to the \l{http://developer.apple.com/documentation/Carbon/Conceptual/HandlingWindowsControls/hitb-wind_cont_concept/chapter_2_section_2.html}{Floating} class of windows. This means that the window lives on a @@ -2174,9 +2172,7 @@ should be taken over by the target application, i.e., the source application should not delete the data. - \br On X11 this value is used to do a move. - \br TargetMoveAction is not used on the Mac. */ @@ -2643,7 +2639,7 @@ for other strings (e.g., "\l{http://qt.nokia.com/doc/qq/qq09-mac-deployment.html}{Deploying Applications on Ma...}"). - \sa QAbstractItemView::textElideMode, QFontMetrics::elidedText(), AlignmentFlag QTabBar::elideMode + \sa QAbstractItemView::textElideMode, QFontMetrics::elidedText(), AlignmentFlag, QTabBar::elideMode */ /*! @@ -2721,7 +2717,7 @@ INT_MIN, inclusive. For example, you can define custom priorities as being relative to each other: - \snippet doc/src/snippets/code/doc_src_qnamespace.cpp 1 + \snippet code/doc_src_qnamespace.cpp 1 \sa QCoreApplication::postEvent() */ diff --git a/src/corelib/io/qabstractfileengine.cpp b/src/corelib/io/qabstractfileengine.cpp index 021698115c..6c10c6cb00 100644 --- a/src/corelib/io/qabstractfileengine.cpp +++ b/src/corelib/io/qabstractfileengine.cpp @@ -87,7 +87,7 @@ QT_BEGIN_NAMESPACE For example: - \snippet doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp 0 + \snippet code/src_corelib_io_qabstractfileengine.cpp 0 When the handler is destroyed, it is automatically removed from Qt. @@ -184,7 +184,7 @@ QAbstractFileEngine *qt_custom_file_engine_handler_create(const QString &path) Example: - \snippet doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp 1 + \snippet code/src_corelib_io_qabstractfileengine.cpp 1 \sa QAbstractFileEngine::create() */ @@ -461,7 +461,7 @@ bool QAbstractFileEngine::isSequential() const This virtual function must be reimplemented by all subclasses. - \sa setFileName() rmdir() + \sa setFileName(), rmdir() */ bool QAbstractFileEngine::remove() { @@ -515,7 +515,7 @@ bool QAbstractFileEngine::link(const QString &newName) This virtual function must be reimplemented by all subclasses. - \sa setFileName() rmdir() isRelativePath() + \sa setFileName(), rmdir(), isRelativePath() */ bool QAbstractFileEngine::mkdir(const QString &dirName, bool createParentDirectories) const { @@ -535,7 +535,7 @@ bool QAbstractFileEngine::mkdir(const QString &dirName, bool createParentDirecto This virtual function must be reimplemented by all subclasses. - \sa setFileName() remove() mkdir() isRelativePath() + \sa setFileName(), remove(), mkdir(), isRelativePath() */ bool QAbstractFileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const { @@ -671,7 +671,7 @@ QString QAbstractFileEngine::fileName(FileName file) const This virtual function must be reimplemented by all subclasses. - \sa owner() setFileName(), FileOwner + \sa owner(), setFileName(), FileOwner */ uint QAbstractFileEngine::ownerId(FileOwner owner) const { @@ -687,7 +687,7 @@ uint QAbstractFileEngine::ownerId(FileOwner owner) const This virtual function must be reimplemented by all subclasses. - \sa ownerId() setFileName(), FileOwner + \sa ownerId(), setFileName(), FileOwner */ QString QAbstractFileEngine::owner(FileOwner owner) const { @@ -821,7 +821,7 @@ bool QAbstractFileEngine::unmap(uchar *address) Example: - \snippet doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp 2 + \snippet code/src_corelib_io_qabstractfileengine.cpp 2 QAbstractFileEngineIterator is associated with a path, name filters, and entry filters. The path is the directory that the iterator lists entries @@ -846,7 +846,7 @@ bool QAbstractFileEngine::unmap(uchar *address) Here is an example of how to implement an iterator that returns each of three fixed entries in sequence. - \snippet doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp 3 + \snippet code/src_corelib_io_qabstractfileengine.cpp 3 Note: QAbstractFileEngineIterator does not deal with QDir::IteratorFlags; it simply returns entries for a single directory. @@ -1080,7 +1080,7 @@ qint64 QAbstractFileEngine::write(const char *data, qint64 len) } /*! - This function reads one line, terminated by a '\n' character, from the + This function reads one line, terminated by a '\\n' character, from the file info \a data. At most \a maxlen characters will be read. The end-of-line character is included. */ diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp index dfc85a434d..af71af1fc4 100644 --- a/src/corelib/io/qbuffer.cpp +++ b/src/corelib/io/qbuffer.cpp @@ -112,7 +112,7 @@ QByteArray QBufferPrivate::peek(qint64 maxSize) interface. The QByteArray is treated just as a standard random-accessed file. Example: - \snippet doc/src/snippets/buffer/buffer.cpp 0 + \snippet buffer/buffer.cpp 0 By default, an internal QByteArray buffer is created for you when you create a QBuffer. You can access this buffer directly by @@ -130,12 +130,12 @@ QByteArray QBufferPrivate::peek(qint64 maxSize) The following code snippet shows how to write data to a QByteArray using QDataStream and QBuffer: - \snippet doc/src/snippets/buffer/buffer.cpp 1 + \snippet buffer/buffer.cpp 1 Effectively, we convert the application's QPalette into a byte array. Here's how to read the data from the QByteArray: - \snippet doc/src/snippets/buffer/buffer.cpp 2 + \snippet buffer/buffer.cpp 2 QTextStream and QDataStream also provide convenience constructors that take a QByteArray and that create a QBuffer behind the @@ -194,7 +194,7 @@ QBuffer::QBuffer(QObject *parent) Example: - \snippet doc/src/snippets/buffer/buffer.cpp 3 + \snippet buffer/buffer.cpp 3 \sa open(), setBuffer(), setData() */ @@ -230,7 +230,7 @@ QBuffer::~QBuffer() Example: - \snippet doc/src/snippets/buffer/buffer.cpp 4 + \snippet buffer/buffer.cpp 4 If \a byteArray is 0, the buffer creates its own internal QByteArray to work on. This byte array is initially empty. diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp index 1fe2a793a6..559c5a0743 100644 --- a/src/corelib/io/qdatastream.cpp +++ b/src/corelib/io/qdatastream.cpp @@ -81,11 +81,11 @@ QT_BEGIN_NAMESPACE Example (write binary data to a stream): - \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 0 + \snippet code/src_corelib_io_qdatastream.cpp 0 Example (read binary data from a stream): - \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 1 + \snippet code/src_corelib_io_qdatastream.cpp 1 Each item written to the stream is written in a predefined binary format that varies depending on the item's type. Supported Qt @@ -119,7 +119,7 @@ QT_BEGIN_NAMESPACE compatibility, you can hardcode the version number in the application: - \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 2 + \snippet code/src_corelib_io_qdatastream.cpp 2 If you are producing a new binary data format, such as a file format for documents created by your application, you could use a @@ -127,11 +127,11 @@ QT_BEGIN_NAMESPACE would write a brief header containing a magic string and a version number to give yourself room for future expansion. For example: - \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 3 + \snippet code/src_corelib_io_qdatastream.cpp 3 Then read it in with: - \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 4 + \snippet code/src_corelib_io_qdatastream.cpp 4 You can select which byte order to use when serializing data. The default setting is big endian (MSB first). Changing it to little @@ -187,7 +187,7 @@ QT_BEGIN_NAMESPACE defined, check the \b {Related Non-Members} section of the class's documentation page. - \sa QTextStream QVariant + \sa QTextStream, QVariant */ /*! @@ -421,7 +421,7 @@ bool QDataStream::atEnd() const \since 4.6 - \sa FloatingPointPrecision setFloatingPointPrecision() + \sa FloatingPointPrecision, setFloatingPointPrecision() */ QDataStream::FloatingPointPrecision QDataStream::floatingPointPrecision() const { @@ -455,7 +455,7 @@ void QDataStream::setFloatingPointPrecision(QDataStream::FloatingPointPrecision /*! Returns the status of the data stream. - \sa Status setStatus() resetStatus() + \sa Status, setStatus(), resetStatus() */ QDataStream::Status QDataStream::status() const @@ -466,7 +466,7 @@ QDataStream::Status QDataStream::status() const /*! Resets the status of the data stream. - \sa Status status() setStatus() + \sa Status, status(), setStatus() */ void QDataStream::resetStatus() { @@ -479,7 +479,7 @@ void QDataStream::resetStatus() Subsequent calls to setStatus() are ignored until resetStatus() is called. - \sa Status status() resetStatus() + \sa Status, status(), resetStatus() */ void QDataStream::setStatus(Status status) { @@ -589,7 +589,7 @@ void QDataStream::setByteOrder(ByteOrder bo) The \l Version enum provides symbolic constants for the different versions of Qt. For example: - \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 5 + \snippet code/src_corelib_io_qdatastream.cpp 5 \sa version(), Version */ @@ -813,7 +813,7 @@ QDataStream &QDataStream::operator>>(double &f) /*! \overload - Reads the '\0'-terminated string \a s from the stream and returns + Reads the '\\0'-terminated string \a s from the stream and returns a reference to the stream. Space for the string is allocated using \c new -- the caller must @@ -1094,7 +1094,7 @@ QDataStream &QDataStream::operator<<(double f) /*! \overload - Writes the '\0'-terminated string \a s to the stream and returns a + Writes the '\\0'-terminated string \a s to the stream and returns a reference to the stream. The string is serialized using writeBytes(). diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 6726537842..a9d0fd4b3f 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -63,7 +63,7 @@ In the common case, it is useful to call the qDebug() function to obtain a default QDebug object to use for writing debugging information. - \snippet doc/src/snippets/qdebug/qdebugsnippet.cpp 1 + \snippet qdebug/qdebugsnippet.cpp 1 This constructs a QDebug object using the constructor that accepts a QtMsgType value of QtDebugMsg. Similarly, the qWarning(), qCritical() and qFatal() @@ -80,7 +80,7 @@ most Qt value types. To add support for custom types, you need to implement a streaming operator, as in the following example: - \snippet doc/src/snippets/qdebug/qdebugsnippet.cpp 0 + \snippet qdebug/qdebugsnippet.cpp 0 This is described in the \l{Debugging Techniques} and \l{Creating Custom Qt Types#Making the Type Printable}{Creating Custom Qt Types} @@ -251,7 +251,7 @@ /*! \fn QDebug &QDebug::operator<<(const char *s) - Writes the '\0'-terminated string, \a s, to the stream and returns a + Writes the '\\0'-terminated string, \a s, to the stream and returns a reference to the stream. */ diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 23bf3c5f4b..222192b11c 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -358,14 +358,14 @@ inline void QDirPrivate::initFileEngine() Examples of absolute paths: - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 0 + \snippet code/src_corelib_io_qdir.cpp 0 On Windows, the second example above will be translated to \c{C:\Documents and Settings} when used to access files. Examples of relative paths: - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 1 + \snippet code/src_corelib_io_qdir.cpp 1 You can use the isRelative() or isAbsolute() functions to check if a QDir is using a relative or an absolute file path. Call @@ -382,7 +382,7 @@ inline void QDirPrivate::initFileEngine() the location of the directory. However, it can also return "." if the QDir represents the current directory. - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 2 + \snippet code/src_corelib_io_qdir.cpp 2 The path for a directory can also be changed with the cd() and cdUp() functions, both of which operate like familiar shell commands. @@ -418,7 +418,7 @@ inline void QDirPrivate::initFileEngine() file or directory. Neither of these functions checks for the existence of files or directory; they only construct paths. - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 3 + \snippet code/src_corelib_io_qdir.cpp 3 Files can be removed by using the remove() function. Directories cannot be removed in the same way as files; use rmdir() to remove @@ -490,19 +490,19 @@ inline void QDirPrivate::initFileEngine() Check if a directory exists: - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 4 + \snippet code/src_corelib_io_qdir.cpp 4 (We could also use the static convenience function QFile::exists().) Traversing directories and reading a file: - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 5 + \snippet code/src_corelib_io_qdir.cpp 5 A program that lists all the files in the current directory (excluding symbolic links), sorted by size, smallest first: - \snippet doc/src/snippets/qdir-listfiles/main.cpp 0 + \snippet qdir-listfiles/main.cpp 0 \sa QFileInfo, QFile, QFileDialog, QApplication::applicationDirPath(), {Find Files Example} */ @@ -630,7 +630,7 @@ QString QDir::absolutePath() const Example: - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 6 + \snippet code/src_corelib_io_qdir.cpp 6 \sa path(), absolutePath(), exists(), cleanPath(), dirName(), absoluteFilePath() @@ -669,7 +669,7 @@ QString QDir::dirName() const be relative. Redundant multiple separators or "." and ".." directories in \a fileName are not removed (see cleanPath()). - \sa dirName() absoluteFilePath(), isRelative(), canonicalPath() + \sa dirName(), absoluteFilePath(), isRelative(), canonicalPath() */ QString QDir::filePath(const QString &fileName) const { @@ -692,7 +692,7 @@ QString QDir::filePath(const QString &fileName) const exists(). Redundant multiple separators or "." and ".." directories in \a fileName are not removed (see cleanPath()). - \sa relativeFilePath() filePath() canonicalPath() + \sa relativeFilePath(), filePath(), canonicalPath() */ QString QDir::absoluteFilePath(const QString &fileName) const { @@ -711,9 +711,9 @@ QString QDir::absoluteFilePath(const QString &fileName) const /*! Returns the path to \a fileName relative to the directory. - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 7 + \snippet code/src_corelib_io_qdir.cpp 7 - \sa absoluteFilePath() filePath() canonicalPath() + \sa absoluteFilePath(), filePath(), canonicalPath() */ QString QDir::relativeFilePath(const QString &fileName) const { @@ -941,7 +941,7 @@ QStringList QDir::nameFilters() const to ensure that only files with extensions typically used for C++ source files are listed: - \snippet doc/src/snippets/qdir-namefilters/main.cpp 0 + \snippet qdir-namefilters/main.cpp 0 \sa nameFilters(), setFilter() */ @@ -988,7 +988,7 @@ void QDir::addResourceSearchPath(const QString &path) Qt uses this search path to locate files with a known prefix. The search path entries are tested in order, starting with the first entry. - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 8 + \snippet code/src_corelib_io_qdir.cpp 8 File name prefix must be at least 2 characters long to avoid conflicts with Windows drive letters. @@ -1146,7 +1146,7 @@ void QDir::setFilter(Filters filters) /*! Returns the value set by setSorting() - \sa setSorting() SortFlag + \sa setSorting(), SortFlag */ QDir::SortFlags QDir::sorting() const { @@ -1190,7 +1190,7 @@ QDir::SortFlags QDir::sorting() const The \a sort is specified by OR-ing values from the enum \l{QDir::SortFlag}. - \sa sorting() SortFlag + \sa sorting(), SortFlag */ void QDir::setSorting(SortFlags sort) { @@ -1561,7 +1561,7 @@ bool QDir::exists() const this function returns false. If you want to test for this use canonicalPath(), e.g. - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 9 + \snippet code/src_corelib_io_qdir.cpp 9 \sa root(), rootPath() */ @@ -1578,7 +1578,7 @@ bool QDir::isRoot() const Returns true if the directory's path is absolute; otherwise returns false. See isAbsolutePath(). - \sa isRelative() makeAbsolute() cleanPath() + \sa isRelative(), makeAbsolute(), cleanPath() */ /*! @@ -1587,7 +1587,7 @@ bool QDir::isRoot() const Returns true if \a path is absolute; returns false if it is relative. - \sa isAbsolute() isRelativePath() makeAbsolute() cleanPath() + \sa isAbsolute(), isRelativePath(), makeAbsolute(), cleanPath() */ /*! @@ -1595,7 +1595,7 @@ bool QDir::isRoot() const false. (Under Unix a path is relative if it does not start with a "/"). - \sa makeAbsolute() isAbsolute() isAbsolutePath() cleanPath() + \sa makeAbsolute(), isAbsolute(), isAbsolutePath(), cleanPath() */ bool QDir::isRelative() const { @@ -1610,7 +1610,7 @@ bool QDir::isRelative() const absolute nothing happens. Returns true if the conversion succeeded; otherwise returns false. - \sa isAbsolute() isAbsolutePath() isRelative() cleanPath() + \sa isAbsolute(), isAbsolutePath(), isRelative(), cleanPath() */ bool QDir::makeAbsolute() { @@ -1639,7 +1639,7 @@ bool QDir::makeAbsolute() Example: - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 10 + \snippet code/src_corelib_io_qdir.cpp 10 */ bool QDir::operator==(const QDir &dir) const { @@ -1718,7 +1718,7 @@ QDir &QDir::operator=(const QString &path) Example: - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 11 + \snippet code/src_corelib_io_qdir.cpp 11 */ /*! @@ -1873,7 +1873,7 @@ QString QDir::currentPath() Under Windows this function will return the directory of the current user's profile. Typically, this is: - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 12 + \snippet code/src_corelib_io_qdir.cpp 12 Use the toNativeSeparators() function to convert the separators to the ones that are appropriate for the underlying operating system. @@ -1966,7 +1966,7 @@ QString QDir::rootPath() patterns in the list of \a filters; otherwise returns false. The matching is case insensitive. - \sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList() + \sa {QRegExp wildcard matching}, QRegExp::exactMatch(), entryList(), entryInfoList() */ bool QDir::match(const QStringList &filters, const QString &fileName) { @@ -1984,7 +1984,7 @@ bool QDir::match(const QStringList &filters, const QString &fileName) contain multiple patterns separated by spaces or semicolons. The matching is case insensitive. - \sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList() + \sa {QRegExp wildcard matching}, QRegExp::exactMatch(), entryList(), entryInfoList() */ bool QDir::match(const QString &filter, const QString &fileName) { @@ -2001,7 +2001,7 @@ bool QDir::match(const QString &filter, const QString &fileName) For example, "./local" becomes "local", "local/../bin" becomes "bin" and "/local/usr/../bin" becomes "/local/bin". - \sa absolutePath() canonicalPath() + \sa absolutePath(), canonicalPath() */ QString QDir::cleanPath(const QString &path) { @@ -2129,7 +2129,7 @@ QString QDir::cleanPath(const QString &path) Returns true if \a path is relative; returns false if it is absolute. - \sa isRelative() isAbsolutePath() makeAbsolute() + \sa isRelative(), isAbsolutePath(), makeAbsolute() */ bool QDir::isRelativePath(const QString &path) { @@ -2181,7 +2181,7 @@ QStringList QDir::nameFiltersFromString(const QString &nameFilter) initialized at startup by adding this line to your \c main() function: - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 13 + \snippet code/src_corelib_io_qdir.cpp 13 If the file name contains characters that cannot be part of a valid C++ function name (such as '-'), they have to be replaced by the underscore character ('_'). @@ -2190,7 +2190,7 @@ QStringList QDir::nameFiltersFromString(const QString &nameFilter) main(). If that is not possible, the following workaround can be used to init the resource \c myapp from the function \c{MyNamespace::myFunction}: - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 14 + \snippet code/src_corelib_io_qdir.cpp 14 \sa Q_CLEANUP_RESOURCE(), {The Qt Resource System} */ @@ -2213,7 +2213,7 @@ QStringList QDir::nameFiltersFromString(const QString &nameFilter) Example: - \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 15 + \snippet code/src_corelib_io_qdir.cpp 15 \sa Q_INIT_RESOURCE(), {The Qt Resource System} */ diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp index 56912e8706..f2a259be64 100644 --- a/src/corelib/io/qdiriterator.cpp +++ b/src/corelib/io/qdiriterator.cpp @@ -55,7 +55,7 @@ argument. After construction, the iterator is located before the first directory entry. Here's how to iterate over all the entries sequentially: - \snippet doc/src/snippets/code/src_corelib_io_qdiriterator.cpp 0 + \snippet code/src_corelib_io_qdiriterator.cpp 0 The next() function returns the path to the next directory entry and advances the iterator. You can also call filePath() to get the current diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 120c5a8c23..b3e3bdde53 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -170,7 +170,7 @@ QAbstractFileEngine *QFilePrivate::engine() const The following example reads a text file line by line: - \snippet doc/src/snippets/file/file.cpp 0 + \snippet file/file.cpp 0 The QIODevice::Text flag passed to open() tells Qt to convert Windows-style line terminators ("\\r\\n") into C++-style @@ -182,7 +182,7 @@ QAbstractFileEngine *QFilePrivate::engine() const The next example uses QTextStream to read a text file line by line: - \snippet doc/src/snippets/file/file.cpp 1 + \snippet file/file.cpp 1 QTextStream takes care of converting the 8-bit data stored on disk into a 16-bit Unicode QString. By default, it assumes that @@ -194,7 +194,7 @@ QAbstractFileEngine *QFilePrivate::engine() const take a QTextStream on the left and various data types (including QString) on the right: - \snippet doc/src/snippets/file/file.cpp 2 + \snippet file/file.cpp 2 QDataStream is similar, in that you can use operator<<() to write data and operator>>() to read it back. See the class @@ -217,7 +217,7 @@ QAbstractFileEngine *QFilePrivate::engine() const read() or readLine() repeatedly until no more data can be read. The next example uses QTextStream to read \c /proc/modules line by line: - \snippet doc/src/snippets/file/file.cpp 3 + \snippet file/file.cpp 3 \section1 Signals @@ -325,7 +325,7 @@ QString QFile::fileName() const \e{at the time of the open()} call. Example: - \snippet doc/src/snippets/code/src_corelib_io_qfile.cpp 0 + \snippet code/src_corelib_io_qfile.cpp 0 Note that the directory separator "/" works for all operating systems supported by Qt. @@ -363,7 +363,7 @@ QFile::setFileName(const QString &name) file names that the user chooses. File names hard-coded into the application should only use 7-bit ASCII filename characters. - \sa decodeName() setEncodingFunction() + \sa decodeName(), setEncodingFunction() */ QByteArray @@ -378,7 +378,7 @@ QFile::encodeName(const QString &fileName) This is a typedef for a pointer to a function with the following signature: - \snippet doc/src/snippets/code/src_corelib_io_qfile.cpp 1 + \snippet code/src_corelib_io_qfile.cpp 1 \sa setEncodingFunction(), encodeName() */ @@ -420,7 +420,7 @@ QFile::setEncodingFunction(EncoderFn f) This is a typedef for a pointer to a function with the following signature: - \snippet doc/src/snippets/code/src_corelib_io_qfile.cpp 2 + \snippet code/src_corelib_io_qfile.cpp 2 \sa setDecodingFunction() */ @@ -485,7 +485,7 @@ QFile::exists(const QString &fileName) This name may not represent an existing file; it is only a string. QFile::exists() returns true if the symlink points to an existing file. - \sa fileName() setFileName() + \sa fileName(), setFileName() */ /*! @@ -896,7 +896,7 @@ bool QFile::open(OpenMode mode) Returns true if successful; otherwise returns false. Example: - \snippet doc/src/snippets/code/src_corelib_io_qfile.cpp 3 + \snippet code/src_corelib_io_qfile.cpp 3 When a QFile is opened using this function, behaviour of close() is controlled by the AutoCloseHandle flag. @@ -930,7 +930,7 @@ bool QFile::open(OpenMode mode) stdin, stdout and stderr streams at the console. To do this, add the following declaration to your application's project file: - \snippet doc/src/snippets/code/src_corelib_io_qfile.cpp 4 + \snippet code/src_corelib_io_qfile.cpp 4 */ bool QFile::open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags) { diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 1805e759ab..1dcde0496d 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -244,14 +244,14 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) transparently; similarly, opening a symlink using QFile effectively opens the link's target. For example: - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 0 + \snippet code/src_corelib_io_qfileinfo.cpp 0 On Windows, symlinks (shortcuts) are \c .lnk files. The reported size() is that of the symlink (not the link's target), and opening a symlink using QFile opens the \c .lnk file. For example: - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 1 + \snippet code/src_corelib_io_qfileinfo.cpp 1 Elements of the file's name can be extracted with path() and fileName(). The fileName()'s parts can be extracted with @@ -442,7 +442,7 @@ QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo) path relative to the current directory. Example: - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 2 + \snippet code/src_corelib_io_qfileinfo.cpp 2 \sa isRelative(), QDir::setCurrent(), QDir::isRelativePath() */ @@ -496,7 +496,7 @@ void QFileInfo::setFile(const QDir &dir, const QString &file) QFileInfo will uppercase drive letters. Note that QDir does not do this. The code snippet below shows this. - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp newstuff + \snippet code/src_corelib_io_qfileinfo.cpp newstuff This function returns the same as filePath(), unless isRelative() is true. In contrast to canonicalFilePath(), symbolic links or @@ -688,7 +688,7 @@ QString QFileInfo::filePath() const Returns the name of the file, excluding the path. Example: - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 3 + \snippet code/src_corelib_io_qfileinfo.cpp 3 Note that, if this QFileInfo object is given a path ending in a slash, the name of the file is considered empty. @@ -711,7 +711,7 @@ QString QFileInfo::fileName() const path isBundle(). On all other platforms an empty QString is returned. Example: - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 4 + \snippet code/src_corelib_io_qfileinfo.cpp 4 \sa isBundle(), filePath(), baseName(), extension() */ @@ -730,7 +730,7 @@ QString QFileInfo::bundleName() const not including) the \e first '.' character. Example: - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 5 + \snippet code/src_corelib_io_qfileinfo.cpp 5 The base name of a file is computed equally on all platforms, independent @@ -754,7 +754,7 @@ QString QFileInfo::baseName() const to (but not including) the \e last '.' character. Example: - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 6 + \snippet code/src_corelib_io_qfileinfo.cpp 6 \sa fileName(), suffix(), completeSuffix(), baseName() */ @@ -773,7 +773,7 @@ QString QFileInfo::completeBaseName() const (but not including) the first '.'. Example: - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 7 + \snippet code/src_corelib_io_qfileinfo.cpp 7 \sa fileName(), suffix(), baseName(), completeBaseName() */ @@ -792,7 +792,7 @@ QString QFileInfo::completeSuffix() const including) the last '.'. Example: - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 8 + \snippet code/src_corelib_io_qfileinfo.cpp 8 The suffix of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, @@ -818,12 +818,12 @@ QString QFileInfo::suffix() const For each of the following, dir() returns a QDir for \c{"~/examples/191697"}. - \snippet doc/src/snippets/fileinfo/main.cpp 0 + \snippet fileinfo/main.cpp 0 For each of the following, dir() returns a QDir for \c{"."}. - \snippet doc/src/snippets/fileinfo/main.cpp 1 + \snippet fileinfo/main.cpp 1 \sa absolutePath(), filePath(), fileName(), isRelative(), absoluteDir() */ @@ -1010,7 +1010,7 @@ bool QFileInfo::isBundle() const Example: - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 9 + \snippet code/src_corelib_io_qfileinfo.cpp 9 \note If the symlink points to a non existing file, exists() returns false. @@ -1172,7 +1172,7 @@ uint QFileInfo::groupId() const always returns true. Example: - \snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 10 + \snippet code/src_corelib_io_qfileinfo.cpp 10 \sa isReadable(), isWritable(), isExecutable() */ @@ -1243,7 +1243,7 @@ qint64 QFileInfo::size() const If neither creation time nor "last status change" time are not available, returns the same as lastModified(). - \sa lastModified() lastRead() + \sa lastModified(), lastRead() */ QDateTime QFileInfo::created() const { @@ -1261,7 +1261,7 @@ QDateTime QFileInfo::created() const /*! Returns the date and time when the file was last modified. - \sa created() lastRead() + \sa created(), lastRead() */ QDateTime QFileInfo::lastModified() const { @@ -1282,7 +1282,7 @@ QDateTime QFileInfo::lastModified() const On platforms where this information is not available, returns the same as lastModified(). - \sa created() lastModified() + \sa created(), lastModified() */ QDateTime QFileInfo::lastRead() const { diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 1cdfc61627..3c2da7fa85 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -215,7 +215,7 @@ QIODevicePrivate::~QIODevicePrivate() Calling these functions from the main, GUI thread, may cause your user interface to freeze. Example: - \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 0 + \snippet code/src_corelib_io_qiodevice.cpp 0 By subclassing QIODevice, you can provide the same interface to your own I/O devices. Subclasses of QIODevice are only required to @@ -239,7 +239,7 @@ QIODevicePrivate::~QIODevicePrivate() subclassing QIODevice, remember to bypass any buffer you may use when the device is open in Unbuffered mode. - \sa QBuffer QFile QTcpSocket + \sa QBuffer, QFile, QTcpSocket */ /*! @@ -257,9 +257,9 @@ QIODevicePrivate::~QIODevicePrivate() \value Truncate If possible, the device is truncated before it is opened. All earlier contents of the device are lost. \value Text When reading, the end-of-line terminators are - translated to '\n'. When writing, the end-of-line + translated to '\\n'. When writing, the end-of-line terminators are translated to the local encoding, for - example '\r\n' for Win32. + example '\\r\\n' for Win32. \value Unbuffered Any buffer in the device is bypassed. Certain flags, such as \c Unbuffered and \c Truncate, are @@ -431,7 +431,7 @@ QIODevice::OpenMode QIODevice::openMode() const function to set the open mode if the flags change after the device has been opened. - \sa openMode() OpenMode + \sa openMode(), OpenMode */ void QIODevice::setOpenMode(OpenMode openMode) { @@ -484,7 +484,7 @@ bool QIODevice::isTextModeEnabled() const default, this function returns false if openMode() returns \c NotOpen. - \sa openMode() OpenMode + \sa openMode(), OpenMode */ bool QIODevice::isOpen() const { @@ -498,7 +498,7 @@ bool QIODevice::isOpen() const This is a convenience function which checks if the OpenMode of the device contains the ReadOnly flag. - \sa openMode() OpenMode + \sa openMode(), OpenMode */ bool QIODevice::isReadable() const { @@ -512,7 +512,7 @@ bool QIODevice::isReadable() const This is a convenience function which checks if the OpenMode of the device contains the WriteOnly flag. - \sa openMode() OpenMode + \sa openMode(), OpenMode */ bool QIODevice::isWritable() const { @@ -524,7 +524,7 @@ bool QIODevice::isWritable() const otherwise returns false. This function should be called from any reimplementations of open() or other functions that open the device. - \sa openMode() OpenMode + \sa openMode(), OpenMode */ bool QIODevice::open(OpenMode mode) { @@ -544,7 +544,7 @@ bool QIODevice::open(OpenMode mode) First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen. The error string is also reset. - \sa setOpenMode() OpenMode + \sa setOpenMode(), OpenMode */ void QIODevice::close() { @@ -704,7 +704,7 @@ bool QIODevice::reset() Subclasses that reimplement this function must call the base implementation in order to include the size of QIODevices' buffer. Example: - \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 1 + \snippet code/src_corelib_io_qiodevice.cpp 1 \sa bytesToWrite(), readyRead(), isSequential() */ @@ -745,7 +745,7 @@ qint64 QIODevice::bytesToWrite() const function returns -1 in those cases (that is, reading on a closed socket or after a process has died). - \sa readData() readLine() write() + \sa readData(), readLine(), write() */ qint64 QIODevice::read(char *data, qint64 maxSize) { @@ -1032,13 +1032,13 @@ QByteArray QIODevice::readAll() occurs, this function returns the length of what could be read, or -1 if nothing was read. - A terminating '\0' byte is always appended to \a data, so \a + A terminating '\\0' byte is always appended to \a data, so \a maxSize must be larger than 1. Data is read until either of the following conditions are met: \list - \li The first '\n' character is read. + \li The first '\\n' character is read. \li \a maxSize - 1 bytes are read. \li The end of the device data is detected. \endlist @@ -1046,12 +1046,12 @@ QByteArray QIODevice::readAll() For example, the following code reads a line of characters from a file: - \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 2 + \snippet code/src_corelib_io_qiodevice.cpp 2 - The newline character ('\n') is included in the buffer. If a + The newline character ('\\n') is included in the buffer. If a newline is not encountered before maxSize - 1 bytes are read, a newline will not be inserted into the buffer. On windows newline - characters are replaced with '\n'. + characters are replaced with '\\n'. This function calls readLineData(), which is implemented using repeated calls to getChar(). You can provide a more efficient @@ -1208,7 +1208,7 @@ QByteArray QIODevice::readLine(qint64 maxSize) implementation, using getChar(). Buffered devices can improve the performance of readLine() by reimplementing this function. - readLine() appends a '\0' byte to \a data; readLineData() does not + readLine() appends a '\\0' byte to \a data; readLineData() does not need to do this. If you reimplement this function, be careful to return the correct @@ -1258,7 +1258,7 @@ qint64 QIODevice::readLineData(char *data, qint64 maxSize) Subclasses that reimplement this function must call the base implementation in order to include the contents of the QIODevice's buffer. Example: - \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 3 + \snippet code/src_corelib_io_qiodevice.cpp 3 \sa readyRead(), readLine() */ @@ -1272,7 +1272,7 @@ bool QIODevice::canReadLine() const device. Returns the number of bytes that were actually written, or -1 if an error occurred. - \sa read() writeData() + \sa read(), writeData() */ qint64 QIODevice::write(const char *data, qint64 maxSize) { @@ -1362,7 +1362,7 @@ qint64 QIODevice::write(const char *data, qint64 maxSize) ... \endcode - \sa read() writeData() + \sa read(), writeData() */ qint64 QIODevice::write(const char *data) { @@ -1376,7 +1376,7 @@ qint64 QIODevice::write(const char *data) Writes the content of \a byteArray to the device. Returns the number of bytes that were actually written, or -1 if an error occurred. - \sa read() writeData() + \sa read(), writeData() */ /*! @@ -1407,7 +1407,7 @@ void QIODevice::ungetChar(char c) Writes the character \a c to the device. Returns true on success; otherwise returns false. - \sa write() getChar() ungetChar() + \sa write(), getChar(), ungetChar() */ bool QIODevice::putChar(char c) { @@ -1457,7 +1457,7 @@ QByteArray QIODevicePrivate::peek(qint64 maxSize) is 0, the character is discarded. Returns true on success; otherwise returns false. - \sa read() putChar() ungetChar() + \sa read(), putChar(), ungetChar() */ bool QIODevice::getChar(char *c) { @@ -1479,7 +1479,7 @@ bool QIODevice::getChar(char *c) Example: - \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 4 + \snippet code/src_corelib_io_qiodevice.cpp 4 \sa read() */ @@ -1497,7 +1497,7 @@ qint64 QIODevice::peek(char *data, qint64 maxSize) Example: - \snippet doc/src/snippets/code/src_corelib_io_qiodevice.cpp 5 + \snippet code/src_corelib_io_qiodevice.cpp 5 This function has no way of reporting errors; returning an empty QByteArray() can mean either that no data was currently available @@ -1620,7 +1620,7 @@ QString QIODevice::errorString() const all the requested information was read and therefore does not retry reading if there was a problem. - \sa read() readLine() writeData() + \sa read(), readLine(), writeData() */ /*! @@ -1638,7 +1638,7 @@ QString QIODevice::errorString() const all the information was written and therefore does not retry writing if there was a problem. - \sa read() write() + \sa read(), write() */ diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index f3680decc7..b75c9c1974 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -451,10 +451,10 @@ void QProcessPrivate::Channel::clear() containing "-style" and "motif" as two items in the list of arguments: - \snippet doc/src/snippets/qprocess/qprocess-simpleexecution.cpp 0 + \snippet qprocess/qprocess-simpleexecution.cpp 0 \dots - \snippet doc/src/snippets/qprocess/qprocess-simpleexecution.cpp 1 - \snippet doc/src/snippets/qprocess/qprocess-simpleexecution.cpp 2 + \snippet qprocess/qprocess-simpleexecution.cpp 1 + \snippet qprocess/qprocess-simpleexecution.cpp 2 QProcess then enters the \l Starting state, and when the program has started, QProcess enters the \l Running state and emits @@ -550,7 +550,7 @@ void QProcessPrivate::Channel::clear() The following example runs \c gzip to compress the string "Qt rocks!", without an event loop: - \snippet doc/src/snippets/process/process.cpp 0 + \snippet process/process.cpp 0 \section1 Notes for Windows Users @@ -1184,7 +1184,7 @@ QProcess::ProcessChannelMode QProcess::processChannelMode() const error channels to the \a mode specified. This mode will be used the next time start() is called. For example: - \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 0 + \snippet code/src_corelib_io_qprocess.cpp 0 \sa processChannelMode(), ProcessChannelMode, setReadChannel() */ @@ -1261,7 +1261,7 @@ void QProcess::closeReadChannel(ProcessChannel channel) Unix and Windows. But it will not display the text data until QProcess's write channel has been closed. Example: - \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 1 + \snippet code/src_corelib_io_qprocess.cpp 1 The write channel is implicitly opened when start() is called. @@ -1363,10 +1363,10 @@ void QProcess::setStandardErrorFile(const QString &fileName, OpenMode mode) destination process' standard input. The following shell command: - \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 2 + \snippet code/src_corelib_io_qprocess.cpp 2 Can be accomplished with QProcesses with the following code: - \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 3 + \snippet code/src_corelib_io_qprocess.cpp 3 */ void QProcess::setStandardOutputProcess(QProcess *destination) { @@ -1567,7 +1567,7 @@ QProcess::ProcessState QProcess::state() const For example, the following code adds the \c{C:\\BIN} directory to the list of executable paths (\c{PATHS}) on Windows: - \snippet doc/src/snippets/qprocess-environment/main.cpp 0 + \snippet qprocess-environment/main.cpp 0 \note This function is less efficient than the setProcessEnvironment() function. @@ -1605,7 +1605,7 @@ QStringList QProcess::environment() const For example, the following code adds the \c{C:\\BIN} directory to the list of executable paths (\c{PATHS}) on Windows and sets \c{TMPDIR}: - \snippet doc/src/snippets/qprocess-environment/main.cpp 1 + \snippet qprocess-environment/main.cpp 1 Note how, on Windows, environment variable names are case-insensitive. @@ -1755,7 +1755,7 @@ void QProcess::setProcessState(ProcessState state) \e execve()). Reimplement this function to do last minute initialization of the child process. Example: - \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 4 + \snippet code/src_corelib_io_qprocess.cpp 4 You cannot exit the process (by calling exit(), for instance) from this function. If you need to stop the program before it starts @@ -2002,12 +2002,12 @@ static QStringList parseCombinedArgString(const QString &program) program name and its arguments. The arguments are separated by one or more spaces. For example: - \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 5 + \snippet code/src_corelib_io_qprocess.cpp 5 The \a program string can also contain quotes, to ensure that arguments containing spaces are correctly supplied to the new process. For example: - \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 6 + \snippet code/src_corelib_io_qprocess.cpp 6 If the QProcess object is already running a process, a warning may be printed at the console, and the existing process will continue running. @@ -2017,7 +2017,7 @@ static QStringList parseCombinedArgString(const QString &program) way to ensure that \c{"My Documents"} is used as the argument to the \c dir executable: - \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 7 + \snippet code/src_corelib_io_qprocess.cpp 7 The OpenMode is set to \a mode. */ @@ -2235,7 +2235,7 @@ QT_END_INCLUDE_NAMESPACE Returns the environment of the calling process as a list of key=value pairs. Example: - \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 8 + \snippet code/src_corelib_io_qprocess.cpp 8 This function does not cache the system environment. Therefore, it's possible to obtain an updated version of the environment if low-level C diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index 4a0211c00a..0937e1e795 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -584,7 +584,7 @@ QResource::addSearchPath(const QString &path) Returns the current search path list. This list is consulted when creating a relative resource. - \sa QDir::addSearchPath() QDir::setSearchPaths() + \sa QDir::addSearchPath(), QDir::setSearchPaths() */ QStringList diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 8a6eef053e..33c1d4301d 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -2028,7 +2028,7 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, company is called MySoft, you would construct the QSettings object as follows: - \snippet doc/src/snippets/settings/settings.cpp 0 + \snippet settings/settings.cpp 0 QSettings objects can be created either on the stack or on the heap (i.e. using \c new). Constructing and destroying a @@ -2040,11 +2040,11 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, QCoreApplication::setApplicationName(), and then use the default QSettings constructor: - \snippet doc/src/snippets/settings/settings.cpp 1 - \snippet doc/src/snippets/settings/settings.cpp 2 - \snippet doc/src/snippets/settings/settings.cpp 3 + \snippet settings/settings.cpp 1 + \snippet settings/settings.cpp 2 + \snippet settings/settings.cpp 3 \dots - \snippet doc/src/snippets/settings/settings.cpp 4 + \snippet settings/settings.cpp 4 (Here, we also specify the organization's Internet domain. When the Internet domain is set, it is used on Mac OS X instead of the @@ -2058,7 +2058,7 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, that stores the data associated with the key. To write a setting, use setValue(). For example: - \snippet doc/src/snippets/settings/settings.cpp 5 + \snippet settings/settings.cpp 5 If there already exists a setting with the same key, the existing value is overwritten by the new value. For efficiency, the @@ -2067,14 +2067,14 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, You can get a setting's value back using value(): - \snippet doc/src/snippets/settings/settings.cpp 6 + \snippet settings/settings.cpp 6 If there is no setting with the specified name, QSettings returns a null QVariant (which can be converted to the integer 0). You can specify another default value by passing a second argument to value(): - \snippet doc/src/snippets/settings/settings.cpp 7 + \snippet settings/settings.cpp 7 To test whether a given key exists, call contains(). To remove the setting associated with a key, call remove(). To obtain the @@ -2091,13 +2091,13 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, Instead, you can use the QVariant::value() or the qVariantValue() template function. For example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 0 + \snippet code/src_corelib_io_qsettings.cpp 0 The inverse conversion (e.g., from QColor to QVariant) is automatic for all data types supported by QVariant, including GUI-related types: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 1 + \snippet code/src_corelib_io_qsettings.cpp 1 Custom types registered using qRegisterMetaType() and qRegisterMetaTypeStreamOperators() can be stored using QSettings. @@ -2127,18 +2127,18 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, You can form hierarchical keys using the '/' character as a separator, similar to Unix file paths. For example: - \snippet doc/src/snippets/settings/settings.cpp 8 - \snippet doc/src/snippets/settings/settings.cpp 9 - \snippet doc/src/snippets/settings/settings.cpp 10 + \snippet settings/settings.cpp 8 + \snippet settings/settings.cpp 9 + \snippet settings/settings.cpp 10 If you want to save or restore many settings with the same prefix, you can specify the prefix using beginGroup() and call endGroup() at the end. Here's the same example again, but this time using the group mechanism: - \snippet doc/src/snippets/settings/settings.cpp 11 + \snippet settings/settings.cpp 11 \codeline - \snippet doc/src/snippets/settings/settings.cpp 12 + \snippet settings/settings.cpp 12 If a group is set using beginGroup(), the behavior of most functions changes consequently. Groups can be set recursively. @@ -2178,8 +2178,8 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, Let's see with an example: - \snippet doc/src/snippets/settings/settings.cpp 13 - \snippet doc/src/snippets/settings/settings.cpp 14 + \snippet settings/settings.cpp 13 + \snippet settings/settings.cpp 14 The table below summarizes which QSettings objects access which location. "\b{X}" means that the location is the main @@ -2205,7 +2205,7 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, argument to the QSettings constructor, followed by the scope, the organization name, and the application name: - \snippet doc/src/snippets/settings/settings.cpp 15 + \snippet settings/settings.cpp 15 The \l{tools/settingseditor}{Settings Editor} example lets you experiment with different settings location and with fallbacks @@ -2217,9 +2217,9 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, application. The following example illustrates how to use QSettings to save and restore the geometry of an application's main window. - \snippet doc/src/snippets/settings/settings.cpp 16 + \snippet settings/settings.cpp 16 \codeline - \snippet doc/src/snippets/settings/settings.cpp 17 + \snippet settings/settings.cpp 17 See \l{Window Geometry} for a discussion on why it is better to call QWidget::resize() and QWidget::move() rather than QWidget::setGeometry() @@ -2229,12 +2229,12 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, called from the main window's constructor and close event handler as follows: - \snippet doc/src/snippets/settings/settings.cpp 18 + \snippet settings/settings.cpp 18 \dots - \snippet doc/src/snippets/settings/settings.cpp 19 - \snippet doc/src/snippets/settings/settings.cpp 20 + \snippet settings/settings.cpp 19 + \snippet settings/settings.cpp 20 \codeline - \snippet doc/src/snippets/settings/settings.cpp 21 + \snippet settings/settings.cpp 21 See the \l{mainwindows/application}{Application} example for a self-contained example that uses QSettings. @@ -2341,7 +2341,7 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, takes a file name as first argument and pass QSettings::IniFormat as second argument. For example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 2 + \snippet code/src_corelib_io_qsettings.cpp 2 You can then use the QSettings object to read and write settings in the file. @@ -2349,7 +2349,7 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, On Mac OS X, you can access XML-based \c .plist files by passing QSettings::NativeFormat as second argument. For example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 3 + \snippet code/src_corelib_io_qsettings.cpp 3 \section2 Accessing the Windows Registry Directly @@ -2360,13 +2360,13 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, For example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 4 + \snippet code/src_corelib_io_qsettings.cpp 4 All the registry entries that appear under the specified path can be read or written through the QSettings object as usual (using forward slashes instead of backslashes). For example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 5 + \snippet code/src_corelib_io_qsettings.cpp 5 Note that the backslash character is, as mentioned, used by QSettings to separate subkeys. As a result, you cannot read or @@ -2380,7 +2380,7 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, Its default value is accessed by using "Default" or "." in place of a subkey: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 6 + \snippet code/src_corelib_io_qsettings.cpp 6 On other platforms than Windows, "Default" and "." would be treated as regular subkeys. @@ -2421,7 +2421,7 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, Another solution is to use preprocessor directives, for example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 7 + \snippet code/src_corelib_io_qsettings.cpp 7 \li On Unix and Mac OS X systems, the advisory file locking is disabled if NFS (or AutoFS or CacheFS) is detected to work around a bug in the @@ -2487,7 +2487,7 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, (e.g., QPoint, QRect, and QSize), Qt uses an \c{@}-based syntax to encode the type. For example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 8 + \snippet code/src_corelib_io_qsettings.cpp 8 To minimize compatibility issues, any \c @ that doesn't appear at the first position in the value or that isn't @@ -2498,7 +2498,7 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, Windows applications don't escape backslashes (\c{\}) in file paths: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 9 + \snippet code/src_corelib_io_qsettings.cpp 9 QSettings always treats backslash as a special character and provides no API for reading or writing such entries. @@ -2547,7 +2547,7 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, organization, and with parent \a parent. Example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 10 + \snippet code/src_corelib_io_qsettings.cpp 10 The scope is set to QSettings::UserScope, and the format is set to QSettings::NativeFormat (i.e. calling setDefaultFormat() @@ -2659,11 +2659,11 @@ QSettings::QSettings(const QString &fileName, Format format, QObject *parent) The code - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 11 + \snippet code/src_corelib_io_qsettings.cpp 11 is equivalent to - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 12 + \snippet code/src_corelib_io_qsettings.cpp 12 If QCoreApplication::setOrganizationName() and QCoreApplication::setApplicationName() has not been previously @@ -2926,7 +2926,7 @@ QSettings::Status QSettings::status() const Groups are useful to avoid typing in the same setting paths over and over. For example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 13 + \snippet code/src_corelib_io_qsettings.cpp 13 This will set the value of three settings: @@ -2953,7 +2953,7 @@ void QSettings::beginGroup(const QString &prefix) Example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 14 + \snippet code/src_corelib_io_qsettings.cpp 14 \sa beginGroup(), group() */ @@ -2991,7 +2991,7 @@ QString QSettings::group() const Example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 15 + \snippet code/src_corelib_io_qsettings.cpp 15 Use beginWriteArray() to write the array in the first place. @@ -3014,7 +3014,7 @@ int QSettings::beginReadArray(const QString &prefix) that you want to save a variable-length list of user names and passwords. You could then write: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 16 + \snippet code/src_corelib_io_qsettings.cpp 16 The generated keys will have the form @@ -3099,12 +3099,12 @@ void QSettings::setArrayIndex(int i) Example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 17 + \snippet code/src_corelib_io_qsettings.cpp 17 If a group is set using beginGroup(), only the keys in the group are returned, without the group prefix: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 18 + \snippet code/src_corelib_io_qsettings.cpp 18 \sa childGroups(), childKeys() */ @@ -3120,12 +3120,12 @@ QStringList QSettings::allKeys() const Example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 19 + \snippet code/src_corelib_io_qsettings.cpp 19 If a group is set using beginGroup(), the top-level keys in that group are returned, without the group prefix: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 20 + \snippet code/src_corelib_io_qsettings.cpp 20 You can navigate through the entire setting hierarchy using childKeys() and childGroups() recursively. @@ -3144,12 +3144,12 @@ QStringList QSettings::childKeys() const Example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 21 + \snippet code/src_corelib_io_qsettings.cpp 21 If a group is set using beginGroup(), the first-level keys in that group are returned, without the group prefix. - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 22 + \snippet code/src_corelib_io_qsettings.cpp 22 You can navigate through the entire setting hierarchy using childKeys() and childGroups() recursively. @@ -3192,7 +3192,7 @@ bool QSettings::isWritable() const Example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 23 + \snippet code/src_corelib_io_qsettings.cpp 23 \sa value(), remove(), contains() */ @@ -3209,7 +3209,7 @@ void QSettings::setValue(const QString &key, const QVariant &value) Example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 24 + \snippet code/src_corelib_io_qsettings.cpp 24 Be aware that if one of the fallback locations contains a setting with the same key, that setting will be visible after calling @@ -3218,7 +3218,7 @@ void QSettings::setValue(const QString &key, const QVariant &value) If \a key is an empty string, all keys in the current group() are removed. For example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 25 + \snippet code/src_corelib_io_qsettings.cpp 25 Note that the Windows registry and INI files use case-insensitive keys, whereas the Carbon Preferences API on Mac OS X uses @@ -3324,7 +3324,7 @@ bool QSettings::event(QEvent *event) Example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 26 + \snippet code/src_corelib_io_qsettings.cpp 26 \sa setValue(), contains(), remove() */ @@ -3457,7 +3457,7 @@ void QSettings::setPath(Format format, Scope scope, const QString &path) Typedef for a pointer to a function with the following signature: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 27 + \snippet code/src_corelib_io_qsettings.cpp 27 \c ReadFunc is used in \c registerFormat() as a pointer to a function that reads a set of key/value pairs. \c ReadFunc should read all the @@ -3472,7 +3472,7 @@ void QSettings::setPath(Format format, Scope scope, const QString &path) Typedef for a pointer to a function with the following signature: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 28 + \snippet code/src_corelib_io_qsettings.cpp 28 \c WriteFunc is used in \c registerFormat() as a pointer to a function that writes a set of key/value pairs. \c WriteFunc is only called once, @@ -3508,7 +3508,7 @@ void QSettings::setPath(Format format, Scope scope, const QString &path) Example: - \snippet doc/src/snippets/code/src_corelib_io_qsettings.cpp 29 + \snippet code/src_corelib_io_qsettings.cpp 29 \sa setPath() */ diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index c6103b3f2f..700b80b062 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -94,7 +94,7 @@ QT_BEGIN_NAMESPACE \value DownloadLocation Returns a directory for user's downloaded files. - \sa writableLocation() standardLocations() displayName() locate() locateAll() + \sa writableLocation(), standardLocations(), displayName(), locate(), locateAll() */ /*! diff --git a/src/corelib/io/qtemporarydir.cpp b/src/corelib/io/qtemporarydir.cpp index 579d569a01..1abc257fa1 100644 --- a/src/corelib/io/qtemporarydir.cpp +++ b/src/corelib/io/qtemporarydir.cpp @@ -171,7 +171,7 @@ void QTemporaryDirPrivate::create(const QString &templateName) Example: - \snippet doc/src/snippets/code/src_corelib_io_qtemporarydir.cpp 0 + \snippet code/src_corelib_io_qtemporarydir.cpp 0 It is very important to test that the temporary directory could be created, using isValid(). Do not use exists(), since a default-constructed diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 75681dadff..cb8b5dbefc 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -466,7 +466,7 @@ static QString defaultTemplateName() Example: - \snippet doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp 0 + \snippet code/src_corelib_io_qtemporaryfile.cpp 0 Reopening a QTemporaryFile after calling close() is safe. For as long as the QTemporaryFile object itself is not destroyed, the unique temporary diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp index 0411b463b3..73ffdfe0a4 100644 --- a/src/corelib/io/qtextstream.cpp +++ b/src/corelib/io/qtextstream.cpp @@ -58,13 +58,13 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384; generating text, QTextStream supports formatting options for field padding and alignment, and formatting of numbers. Example: - \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 0 + \snippet code/src_corelib_io_qtextstream.cpp 0 It's also common to use QTextStream to read console input and write console output. QTextStream is locale aware, and will automatically decode standard input using the correct codec. Example: - \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 1 + \snippet code/src_corelib_io_qtextstream.cpp 1 Besides using QTextStream's constructors, you can also set the device or string QTextStream operates on by calling setDevice() or @@ -117,7 +117,7 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384; the integer base, thereby disabling the automatic detection, by calling setIntegerBase(). Example: - \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 2 + \snippet code/src_corelib_io_qtextstream.cpp 2 QTextStream supports many formatting options for generating text. You can set the field width and pad character by calling @@ -154,7 +154,7 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384; \row \li \c left \li Same as setFieldAlignment(AlignLeft). \row \li \c right \li Same as setFieldAlignment(AlignRight). \row \li \c center \li Same as setFieldAlignment(AlignCenter). - \row \li \c endl \li Same as operator<<('\n') and flush(). + \row \li \c endl \li Same as operator<<('\\n') and flush(). \row \li \c flush \li Same as flush(). \row \li \c reset \li Same as reset(). \row \li \c ws \li Same as skipWhiteSpace(). @@ -1081,7 +1081,7 @@ QTextStream::QTextStream(QByteArray *array, QIODevice::OpenMode openMode) This constructor is convenient for working on constant strings. Example: - \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 3 + \snippet code/src_corelib_io_qtextstream.cpp 3 */ QTextStream::QTextStream(const QByteArray &array, QIODevice::OpenMode openMode) : d_ptr(new QTextStreamPrivate(this)) @@ -1111,7 +1111,7 @@ QTextStream::QTextStream(const QByteArray &array, QIODevice::OpenMode openMode) This constructor is useful for working directly with the common FILE based input and output streams: stdin, stdout and stderr. Example: - \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 4 + \snippet code/src_corelib_io_qtextstream.cpp 4 */ QTextStream::QTextStream(FILE *fileHandle, QIODevice::OpenMode openMode) @@ -1404,11 +1404,11 @@ QTextStream::FieldAlignment QTextStream::fieldAlignment() const Example: - \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 5 + \snippet code/src_corelib_io_qtextstream.cpp 5 The string \c s contains: - \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 6 + \snippet code/src_corelib_io_qtextstream.cpp 6 \sa padChar(), setFieldWidth() */ @@ -1601,7 +1601,7 @@ void QTextStream::resetStatus() Subsequent calls to setStatus() are ignored until resetStatus() is called. - \sa Status status() resetStatus() + \sa Status, status(), resetStatus() */ void QTextStream::setStatus(Status status) { @@ -2023,7 +2023,7 @@ bool QTextStreamPrivate::getReal(double *f) reference to the QTextStream, so several operators can be nested. Example: - \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 7 + \snippet code/src_corelib_io_qtextstream.cpp 7 Whitespace is \e not skipped. */ @@ -2241,8 +2241,8 @@ QTextStream &QTextStream::operator>>(QByteArray &array) /*! \overload - Stores the word in \a c, terminated by a '\0' character. If no word is - available, only the '\0' character is stored. + Stores the word in \a c, terminated by a '\\0' character. If no word is + available, only the '\\0' character is stored. Warning: Although convenient, this operator is dangerous and must be used with care. QTextStream assumes that \a c points to a @@ -2561,11 +2561,11 @@ QTextStream &QTextStream::operator<<(const QByteArray &array) string is assumed to be in ISO-8859-1 encoding. This operator is convenient when working with constant string data. Example: - \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 8 + \snippet code/src_corelib_io_qtextstream.cpp 8 Warning: QTextStream assumes that \a string points to a string of - text, terminated by a '\0' character. If there is no terminating - '\0' character, your application may crash. + text, terminated by a '\\0' character. If there is no terminating + '\\0' character, your application may crash. */ QTextStream &QTextStream::operator<<(const char *string) { @@ -2865,13 +2865,13 @@ QTextStream ¢er(QTextStream &stream) /*! \relates QTextStream - Writes '\n' to the \a stream and flushes the stream. + Writes '\\n' to the \a stream and flushes the stream. Equivalent to - \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 9 + \snippet code/src_corelib_io_qtextstream.cpp 9 - Note: On Windows, all '\n' characters are written as '\r\n' if + Note: On Windows, all '\\n' characters are written as '\\r\\n' if QTextStream's device or string is opened using the QIODevice::Text flag. \sa flush(), reset(), {QTextStream manipulators} @@ -2993,7 +2993,7 @@ void QTextStream::setCodec(QTextCodec *codec) Example: - \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 10 + \snippet code/src_corelib_io_qtextstream.cpp 10 \sa QTextCodec::codecForName(), setLocale() */ diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index fbc8d761c2..b6667d6790 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -64,7 +64,7 @@ unencoded representation is suitable for showing to users, but the encoded representation is typically what you would send to a web server. For example, the unencoded URL - "http://b\uuml\c{}hler.example.com" would be sent to the server as + "http://b\\uuml\c{}hler.example.com" would be sent to the server as "http://xn--bhler-kva.example.com/List%20of%20applicants.xml". A URL can also be constructed piece by piece by calling @@ -155,7 +155,7 @@ */ /*! - \enum QUrl::FormattingOption + \enum QUrl::FormattingOptions The formatting options define how the URL is formatted when written out as text. @@ -1400,11 +1400,11 @@ const QByteArray &QUrlPrivate::normalized() const Example: - \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 0 + \snippet code/src_corelib_io_qurl.cpp 0 To construct a URL from an encoded string, call fromEncoded(): - \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 1 + \snippet code/src_corelib_io_qurl.cpp 1 \sa setUrl(), setEncodedUrl(), fromEncoded(), TolerantMode */ @@ -1445,7 +1445,7 @@ QUrl::~QUrl() must conform to the standard encoding rules of the URI standard for the URL to be reported as valid. - \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 2 + \snippet code/src_corelib_io_qurl.cpp 2 */ bool QUrl::isValid() const { @@ -1501,7 +1501,7 @@ void QUrl::setUrl(const QString &url, ParsingMode parsingMode) and is followed by a ':'. The following example shows a URL where the scheme is "ftp": - \img qurl-authority2.png + \image qurl-authority2.png The scheme can also be empty, in which case the URL is interpreted as relative. @@ -1548,7 +1548,7 @@ QString QUrl::scheme() const The following example shows a valid authority string: - \img qurl-authority.png + \image qurl-authority.png */ void QUrl::setAuthority(const QString &authority) { @@ -1585,7 +1585,7 @@ QString QUrl::authority(ComponentFormattingOptions options) const separated by a ':'. If the password is empty, the colon must be omitted. The following example shows a valid user info string: - \img qurl-authority3.png + \image qurl-authority3.png \sa userInfo(), setUserName(), setPassword(), setAuthority() */ @@ -1746,7 +1746,7 @@ void QUrl::setPort(int port) Example: - \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 3 + \snippet code/src_corelib_io_qurl.cpp 3 */ int QUrl::port(int defaultPort) const { @@ -1758,12 +1758,12 @@ int QUrl::port(int defaultPort) const Sets the path of the URL to \a path. The path is the part of the URL that comes after the authority but before the query string. - \img qurl-ftppath.png + \image qurl-ftppath.png For non-hierarchical schemes, the path will be everything following the scheme declaration, as in the following example: - \img qurl-mailtopath.png + \image qurl-mailtopath.png \sa path() */ @@ -1862,7 +1862,7 @@ QString QUrl::query(ComponentFormattingOptions options) const characters. It is typically used in HTTP for referring to a certain link or point on a page: - \img qurl-fragment.png + \image qurl-fragment.png The fragment is sometimes also referred to as the URL "reference". @@ -1938,7 +1938,7 @@ QString QUrl::topLevelDomain(ComponentFormattingOptions options) const the base URL, but with the merged path, as in the following example: - \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 5 + \snippet code/src_corelib_io_qurl.cpp 5 Calling resolved() with ".." returns a QUrl whose directory is one level higher than the original. Similarly, calling resolved() @@ -2173,7 +2173,7 @@ QString QUrl::fromPercentEncoding(const QByteArray &input) Unreserved is defined as: ALPHA / DIGIT / "-" / "." / "_" / "~" - \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 6 + \snippet code/src_corelib_io_qurl.cpp 6 */ QByteArray QUrl::toPercentEncoding(const QString &input, const QByteArray &exclude, const QByteArray &include) { diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 3d9af90682..dc53021432 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -339,7 +339,7 @@ qint64 QPersistentModelIndex::internalId() const Returns the parent QModelIndex for this persistent index, or an invalid QModelIndex if it has no parent. - \sa child() sibling() model() + \sa child(), sibling(), model() */ QModelIndex QPersistentModelIndex::parent() const { @@ -352,7 +352,7 @@ QModelIndex QPersistentModelIndex::parent() const Returns the sibling at \a row and \a column or an invalid QModelIndex if there is no sibling at this position. - \sa parent() child() + \sa parent(), child() */ QModelIndex QPersistentModelIndex::sibling(int row, int column) const @@ -366,7 +366,7 @@ QModelIndex QPersistentModelIndex::sibling(int row, int column) const Returns the child of the model index that is stored in the given \a row and \a column. - \sa parent() sibling() + \sa parent(), sibling() */ QModelIndex QPersistentModelIndex::child(int row, int column) const @@ -906,7 +906,7 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, Creates a new empty model index. This type of model index is used to indicate that the position in the model is invalid. - \sa isValid() QAbstractItemModel + \sa isValid(), QAbstractItemModel */ /*! @@ -1217,7 +1217,7 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, Returns true if the column is inserted; otherwise returns false. - \sa insertColumns() insertRow() removeColumn() + \sa insertColumns(), insertRow(), removeColumn() */ /*! @@ -1230,7 +1230,7 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, Returns true if the row is inserted; otherwise returns false. - \sa insertRows() insertColumn() removeRow() + \sa insertRows(), insertColumn(), removeRow() */ /*! @@ -1407,7 +1407,7 @@ QAbstractItemModel::~QAbstractItemModel() For example: - \snippet examples/itemviews/simpledommodel/dommodel.cpp 2 + \snippet itemviews/simpledommodel/dommodel.cpp 2 \note When implementing a table based model, columnCount() should return 0 when the parent is valid. @@ -1627,7 +1627,7 @@ bool QAbstractItemModel::hasIndex(int row, int column, const QModelIndex &parent Use rowCount() on the parent to find out the number of children. - \sa parent() index() + \sa parent(), index() */ bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const { @@ -1696,7 +1696,7 @@ bool QAbstractItemModel::setData(const QModelIndex &index, const QVariant &value Roles that are not in \a roles will not be modified. - \sa setData() data() itemData() + \sa setData(), data(), itemData() */ bool QAbstractItemModel::setItemData(const QModelIndex &index, const QMap &roles) { @@ -2195,6 +2195,7 @@ QSize QAbstractItemModel::span(const QModelIndex &) const } /*! + \fn void QAbstractItemModel::setRoleNames(const QHash &theRoleNames) \since 4.6 \obsolete @@ -2445,7 +2446,7 @@ bool QAbstractItemModel::decodeData(int row, int column, const QModelIndex &pare For example, as shown in the diagram, we insert three rows before row 2, so \a first is 2 and \a last is 4: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 0 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 0 This inserts the three new rows as rows 2, 3, and 4. \row @@ -2456,7 +2457,7 @@ bool QAbstractItemModel::decodeData(int row, int column, const QModelIndex &pare collection of 4 existing rows (ending in row 3), so \a first is 4 and \a last is 5: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 1 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 1 This appends the two new rows as rows 4 and 5. \endtable @@ -2511,7 +2512,7 @@ void QAbstractItemModel::endInsertRows() For example, as shown in the diagram, we remove the two rows from row 2 to row 3, so \a first is 2 and \a last is 3: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 2 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 2 \endtable \note This function emits the rowsAboutToBeRemoved() signal which connected @@ -2626,7 +2627,7 @@ bool QAbstractItemModelPrivate::allowMove(const QModelIndex &srcParent, int star row 2 to 4 in the source, so \a sourceFirst is 2 and \a sourceLast is 4. We move those items to above row 2 in the destination, so \a destinationChild is 2. - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 6 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 6 This moves the three rows rows 2, 3, and 4 in the source to become 2, 3 and 4 in the destination. Other affected siblings are displaced accordingly. @@ -2637,7 +2638,7 @@ bool QAbstractItemModelPrivate::allowMove(const QModelIndex &srcParent, int star For example, as shown in the diagram, we move three rows to a collection of 6 existing rows (ending in row 5), so \a destinationChild is 6: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 7 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 7 This moves the target rows to the end of the target parent as 6, 7 and 8. \row @@ -2647,7 +2648,7 @@ bool QAbstractItemModelPrivate::allowMove(const QModelIndex &srcParent, int star For example, as shown in the diagram, we move one item from row 2 to row 0, so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 0. - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 8 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 8 Note that other rows may be displaced accordingly. Note also that when moving items within the same parent you should not attempt invalid or no-op moves. In @@ -2662,7 +2663,7 @@ bool QAbstractItemModelPrivate::allowMove(const QModelIndex &srcParent, int star For example, as shown in the diagram, we move one item from row 2 to row 4, so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 4. - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 9 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 9 Note that other rows may be displaced accordingly. \endtable @@ -2745,7 +2746,7 @@ void QAbstractItemModel::endMoveRows() For example, as shown in the diagram, we insert three columns before column 4, so \a first is 4 and \a last is 6: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 3 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 3 This inserts the three new columns as columns 4, 5, and 6. \row @@ -2756,7 +2757,7 @@ void QAbstractItemModel::endMoveRows() collection of six existing columns (ending in column 5), so \a first is 6 and \a last is 8: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 4 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 4 This appends the two new columns as columns 6, 7, and 8. \endtable @@ -2813,7 +2814,7 @@ void QAbstractItemModel::endInsertColumns() For example, as shown in the diagram, we remove the three columns from column 4 to column 6, so \a first is 4 and \a last is 6: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 5 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 5 \endtable \note This function emits the columnsAboutToBeRemoved() signal which @@ -2945,6 +2946,7 @@ void QAbstractItemModel::endMoveColumns() } /*! + \fn void QAbstractItemModel::reset() \obsolete Resets the model to its original state in any attached views. @@ -2958,11 +2960,11 @@ void QAbstractItemModel::endMoveColumns() For example, in this code both signals modelAboutToBeReset() and modelReset() are emitted \e after the data changes: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 10 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 10 Instead you should use: - \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 11 + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 11 */ /*! @@ -3208,7 +3210,7 @@ QModelIndex QAbstractTableModel::index(int row, int column, const QModelIndex &p Returns the parent of the model item with the given \a index. - \sa index() hasChildren() + \sa index(), hasChildren() */ QModelIndex QAbstractTableModel::parent(const QModelIndex &) const @@ -3334,7 +3336,7 @@ QModelIndex QAbstractListModel::index(int row, int column, const QModelIndex &pa /*! Returns the parent of the model item with the given \a index. - \sa index() hasChildren() + \sa index(), hasChildren() */ QModelIndex QAbstractListModel::parent(const QModelIndex & /* index */) const diff --git a/src/corelib/itemmodels/qidentityproxymodel.cpp b/src/corelib/itemmodels/qidentityproxymodel.cpp index 9cac40469a..c7a5200933 100644 --- a/src/corelib/itemmodels/qidentityproxymodel.cpp +++ b/src/corelib/itemmodels/qidentityproxymodel.cpp @@ -102,7 +102,7 @@ class QIdentityProxyModelPrivate : public QAbstractProxyModelPrivate This also provides a way to change the data in the case where a source model is supplied by a third party which can not be modified. - \snippet doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp 0 + \snippet code/src_gui_itemviews_qidentityproxymodel.cpp 0 \sa QAbstractProxyModel, {Model/View Programming}, QAbstractItemModel diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index fa34acdd18..9cc9502577 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -347,13 +347,13 @@ QModelIndexList QItemSelectionRange::indexes() const a selection that contains a range of items from the given \c model, beginning at the \c topLeft, and ending at the \c bottomRight. - \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 0 + \snippet code/src_gui_itemviews_qitemselectionmodel.cpp 0 An empty item selection can be constructed, and later populated as required. So, if the model is going to be unavailable when we construct the item selection, we can rewrite the above code in the following way: - \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 1 + \snippet code/src_gui_itemviews_qitemselectionmodel.cpp 1 QItemSelection saves memory, and avoids unnecessary work, by working with selection ranges rather than recording the model item index for each @@ -1005,7 +1005,7 @@ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel:: Note that this signal will not be emitted when the item model is reset. - \sa currentIndex() setCurrentIndex() selectionChanged() + \sa currentIndex(), setCurrentIndex(), selectionChanged() */ /*! @@ -1016,7 +1016,7 @@ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel:: Note that this signal will not be emitted when the item model is reset. - \sa currentChanged() currentRowChanged() currentIndex() setCurrentIndex() + \sa currentChanged(), currentRowChanged(), currentIndex(), setCurrentIndex() */ /*! @@ -1027,7 +1027,7 @@ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel:: Note that this signal will not be emitted when the item model is reset. - \sa currentChanged() currentColumnChanged() currentIndex() setCurrentIndex() + \sa currentChanged(), currentColumnChanged(), currentIndex(), setCurrentIndex() */ /*! @@ -1040,7 +1040,7 @@ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel:: Note the that the current index changes independently from the selection. Also note that this signal will not be emitted when the item model is reset. - \sa select() currentChanged() + \sa select(), currentChanged() */ /*! diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index ae9affb862..68e5e89db3 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -1511,14 +1511,14 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsMoved( model. The code to set up the model and the view, \e without sorting and filtering, would look like this: - \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 1 + \snippet qsortfilterproxymodel-details/main.cpp 1 To add sorting and filtering support to \c MyItemModel, we need to create a QSortFilterProxyModel, call setSourceModel() with the \c MyItemModel as argument, and install the QSortFilterProxyModel on the view: - \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 0 - \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 2 + \snippet qsortfilterproxymodel-details/main.cpp 0 + \snippet qsortfilterproxymodel-details/main.cpp 2 At this point, neither sorting nor filtering is enabled; the original data is displayed in the view. Any changes made through the @@ -1546,7 +1546,7 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsMoved( whether the user can sort the view by clicking the view's horizontal header. For example: - \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 3 + \snippet qsortfilterproxymodel-details/main.cpp 3 When this feature is on (the default is off), clicking on a header section sorts the items according to that column. By clicking repeatedly, the user @@ -1569,7 +1569,7 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsMoved( QSortFilterProxyModel and reimplementing lessThan(), which is used to compare items. For example: - \snippet examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 5 + \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 5 (This code snippet comes from the \l{itemviews/customsortfiltermodel}{Custom Sort/Filter Model} @@ -1581,7 +1581,7 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsMoved( QSortFilterProxyModel (or on the original model if it implements sort()). For example: - \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 4 + \snippet qsortfilterproxymodel-details/main.cpp 4 QSortFilterProxyModel can be sorted by column -1, in which case it returns to the sort order of the underlying source model. @@ -1594,7 +1594,7 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsMoved( each item, for a given column. The QRegExp object can be used to match a regular expression, a wildcard pattern, or a fixed string. For example: - \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 5 + \snippet qsortfilterproxymodel-details/main.cpp 5 For hierarchical models, the filter is applied recursively to all children. If a parent item doesn't match the filter, none of its children will be @@ -1612,7 +1612,7 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsMoved( the \l{QSortFilterProxyModel::filterKeyColumn}{filterKeyColumn} property and performs filtering on columns 0, 1, and 2: - \snippet examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 3 + \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 3 (This code snippet comes from the \l{itemviews/customsortfiltermodel}{Custom Sort/Filter Model} diff --git a/src/corelib/itemmodels/qstringlistmodel.cpp b/src/corelib/itemmodels/qstringlistmodel.cpp index b13e825c05..e7f219f471 100644 --- a/src/corelib/itemmodels/qstringlistmodel.cpp +++ b/src/corelib/itemmodels/qstringlistmodel.cpp @@ -83,7 +83,7 @@ QT_BEGIN_NAMESPACE An example usage of QStringListModel: - \snippet doc/src/snippets/qstringlistmodel/main.cpp 0 + \snippet qstringlistmodel/main.cpp 0 \sa QAbstractListModel, QAbstractItemModel, {Model Classes} */ diff --git a/src/corelib/json/qjsonarray.cpp b/src/corelib/json/qjsonarray.cpp index 0884f10354..e1ed53a840 100644 --- a/src/corelib/json/qjsonarray.cpp +++ b/src/corelib/json/qjsonarray.cpp @@ -500,13 +500,13 @@ bool QJsonArray::operator!=(const QJsonArray &other) const \sa constBegin(), end() */ -/*! \fn void QJsonArray::push_back(const T &value) +/*! \fn void QJsonArray::push_back(const QJsonValue &value) This function is provided for STL compatibility. It is equivalent to \l{QJsonArray::append()}{append(\a value)}. */ -/*! \fn void QJsonArray::push_front(const T &value) +/*! \fn void QJsonArray::push_front(const QJsonValue &value) This function is provided for STL compatibility. It is equivalent to \l{QJsonArray::prepend()}{prepend(\a value)}. @@ -589,12 +589,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QJsonArray::begin() QJsonArray::end() -*/ - -/*! \fn QJsonArray::iterator::iterator(const iterator &other) - - Constructs a copy of \a other. + \sa QJsonArray::begin(), QJsonArray::end() */ /*! \fn QJsonValueRef QJsonArray::iterator::operator*() const @@ -791,7 +786,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QJsonArray::constBegin() QJsonArray::constEnd() + \sa QJsonArray::constBegin(), QJsonArray::constEnd() */ /*! \typedef QJsonArray::const_iterator::iterator_category diff --git a/src/corelib/json/qjsondocument.cpp b/src/corelib/json/qjsondocument.cpp index be241bc3fc..ae59847dc6 100644 --- a/src/corelib/json/qjsondocument.cpp +++ b/src/corelib/json/qjsondocument.cpp @@ -176,7 +176,7 @@ QJsonDocument &QJsonDocument::operator =(const QJsonDocument &other) Returns a QJsonDocument representing the data. - \sa rawData fromBinaryData isNull DataValidation + \sa rawData, fromBinaryData, isNull, DataValidation */ QJsonDocument QJsonDocument::fromRawData(const char *data, int size, DataValidation validation) { @@ -220,7 +220,7 @@ const char *QJsonDocument::rawData(int *size) const By default the data is validated. If the \a data is not valid, the method returns a null document. - \sa toBinaryData fromRawData isNull DataValidation + \sa toBinaryData, fromRawData, isNull, DataValidation */ QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidation validation) { @@ -361,7 +361,7 @@ QByteArray QJsonDocument::toBinaryData() const /*! Returns true if the document contains an array. - \sa array() isObject() + \sa array(), isObject() */ bool QJsonDocument::isArray() const { @@ -375,7 +375,7 @@ bool QJsonDocument::isArray() const /*! Returns true if the document contains an object. - \sa object() isArray() + \sa object(), isArray() */ bool QJsonDocument::isObject() const { @@ -392,7 +392,7 @@ bool QJsonDocument::isObject() const Returns an empty object if the document contains an array. - \sa isObject array setObject + \sa isObject, array, setObject */ QJsonObject QJsonDocument::object() const { @@ -410,7 +410,7 @@ QJsonObject QJsonDocument::object() const Returns an empty array if the document contains an object. - \sa isArray object setArray + \sa isArray, object, setArray */ QJsonArray QJsonDocument::array() const { @@ -425,7 +425,7 @@ QJsonArray QJsonDocument::array() const /*! Sets \a object as the main object of this document. - \sa setArray object + \sa setArray, object */ void QJsonDocument::setObject(const QJsonObject &object) { @@ -452,7 +452,7 @@ void QJsonDocument::setObject(const QJsonObject &object) /*! Sets \a array as the main object of this document. - \sa setObject array + \sa setObject, array */ void QJsonDocument::setArray(const QJsonArray &array) { diff --git a/src/corelib/json/qjsonobject.cpp b/src/corelib/json/qjsonobject.cpp index e880078195..5439855b90 100644 --- a/src/corelib/json/qjsonobject.cpp +++ b/src/corelib/json/qjsonobject.cpp @@ -74,7 +74,7 @@ QT_BEGIN_NAMESPACE /*! Constructs an empty JSON object - \sa isEmpty + \sa isEmpty() */ QJsonObject::QJsonObject() : d(0), o(0) @@ -139,7 +139,7 @@ QJsonObject &QJsonObject::operator =(const QJsonObject &other) The keys in \a map will be used as the keys in the JSON object, and the QVariant values will be converted to JSON values. - \sa toVariantMap, QJsonValue::fromVariant + \sa toVariantMap(), QJsonValue::fromVariant() */ QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map) { @@ -200,7 +200,7 @@ int QJsonObject::size() const /*! Returns \c true if the object is empty. This is the same as size() == 0. - \sa size + \sa size() */ bool QJsonObject::isEmpty() const { @@ -215,7 +215,7 @@ bool QJsonObject::isEmpty() const The returned QJsonValue is \c Undefined, if the key does not exist. - \sa setValue, QJsonValue, QJsonValue::isUndefined + \sa QJsonValue, QJsonValue::isUndefined() */ QJsonValue QJsonObject::value(const QString &key) const { @@ -236,7 +236,7 @@ QJsonValue QJsonObject::value(const QString &key) const The returned QJsonValue is \c Undefined, if the key does not exist. - \sa value, setValue, QJsonValue, QJsonValue::isUndefined + \sa value(), QJsonValue, QJsonValue::isUndefined() */ QJsonValue QJsonObject::operator [](const QString &key) const { @@ -252,7 +252,7 @@ QJsonValue QJsonObject::operator [](const QString &key) const the assignment will apply to the character in the QJsonArray of QJsonObject from which you got the reference. - \sa setValue, value + \sa value() */ QJsonValueRef QJsonObject::operator [](const QString &key) { @@ -277,7 +277,7 @@ QJsonValueRef QJsonObject::operator [](const QString &key) If the value is QJsonValue::Undefined, it will cause the key to get removed from the object. The returned iterator will then point to end() - \sa remove, take, QJsonObject::iterator, end + \sa remove(), take(), QJsonObject::iterator, end() */ QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &value) { @@ -320,7 +320,7 @@ QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue & /*! Removes \a key from the object. - \sa insert, take + \sa insert(), take() */ void QJsonObject::remove(const QString &key) { @@ -346,7 +346,7 @@ void QJsonObject::remove(const QString &key) If \a key was not contained in the object, the returned QJsonValue is Undefined. - \sa insert, remove, QJsonValue + \sa insert(), remove(), QJsonValue */ QJsonValue QJsonObject::take(const QString &key) { @@ -370,7 +370,7 @@ QJsonValue QJsonObject::take(const QString &key) /*! Returns \c true if the object contains key \a key. - \sa insert, remove, take + \sa insert(), remove(), take() */ bool QJsonObject::contains(const QString &key) const { @@ -455,7 +455,7 @@ QJsonObject::iterator QJsonObject::find(const QString &key) return iterator(this, index); } -/*! \fn QJsonObject::const_iterator QJsonObject::find(const Key &key) const +/*! \fn QJsonObject::const_iterator QJsonObject::find(const QString &key) const \overload */ @@ -541,6 +541,10 @@ QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const */ /*! \class QJsonObject::iterator + \ingroup json + \reentrant + \since 5.0 + \brief The QJsonObject::iterator class provides an STL-style non-const iterator for QJsonObject. QJsonObject::iterator allows you to iterate over a QJsonObject @@ -591,7 +595,7 @@ QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const called on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QJsonObject::begin() QJsonObject::end() + \sa QJsonObject::begin(), QJsonObject::end() */ /*! \fn QString QJsonObject::iterator::key() const @@ -729,7 +733,8 @@ QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const \sa operator+=(), operator-() */ -/*! \class QJsonObject::const_iterator +/*! + \class QJsonObject::const_iterator \brief The QJsonObject::const_iterator class provides an STL-style const iterator for QJsonObject. QJsonObject::const_iterator allows you to iterate over a QJsonObject. @@ -780,7 +785,7 @@ QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const called on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QJsonObject::constBegin() QJsonObject::constEnd() + \sa QJsonObject::constBegin(), QJsonObject::constEnd() */ /*! \fn QJsonObject::const_iterator::const_iterator(const iterator &other) @@ -987,17 +992,6 @@ void QJsonObject::setValueAt(int i, const QJsonValue &val) Qt-style synonym for QJsonObject::const_iterator. */ - -/*! \class QJsonObject::iterator - \ingroup json - \reentrant - \since 5.0 - - \brief The QJsonDocument::iterator class provides a way to iterate over q QJsonObject - - - */ - #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QJsonObject &o) { diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index cf9b0cea4f..2ef98dba0f 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -374,7 +374,7 @@ void QAbstractEventDispatcher::closingDown() Typedef for a function with the signature - \snippet doc/src/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp 0 + \snippet code/src_corelib_kernel_qabstracteventdispatcher.cpp 0 Note that the type of the \a message is platform dependent. The following table shows the \a {message}'s type on Windows, Mac, and @@ -460,7 +460,7 @@ bool QAbstractEventDispatcher::filterEvent(void *message) This signal is emitted after the event loop returns from a function that could block. - \sa wakeUp() aboutToBlock() + \sa wakeUp(), aboutToBlock() */ /*! \fn void QAbstractEventDispatcher::aboutToBlock() diff --git a/src/corelib/kernel/qbasictimer.cpp b/src/corelib/kernel/qbasictimer.cpp index 621223eb88..76db945c45 100644 --- a/src/corelib/kernel/qbasictimer.cpp +++ b/src/corelib/kernel/qbasictimer.cpp @@ -92,7 +92,7 @@ QT_BEGIN_NAMESPACE Returns true if the timer is running and has not been stopped; otherwise returns false. - \sa start() stop() + \sa start(), stop() */ /*! @@ -112,7 +112,7 @@ QT_BEGIN_NAMESPACE The given \a object will receive timer events. - \sa stop() isActive() QObject::timerEvent() Qt::CoarseTimer + \sa stop(), isActive(), QObject::timerEvent(), Qt::CoarseTimer */ void QBasicTimer::start(int msec, QObject *obj) { @@ -139,7 +139,7 @@ void QBasicTimer::start(int msec, QObject *obj) The given \a object will receive timer events. - \sa stop() isActive() QObject::timerEvent() Qt::TimerType + \sa stop(), isActive(), QObject::timerEvent(), Qt::TimerType */ void QBasicTimer::start(int msec, Qt::TimerType timerType, QObject *obj) { @@ -160,7 +160,7 @@ void QBasicTimer::start(int msec, Qt::TimerType timerType, QObject *obj) /*! Stops the timer. - \sa start() isActive() + \sa start(), isActive() */ void QBasicTimer::stop() { diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 7b26a01cbf..d188ccbc9a 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1000,7 +1000,7 @@ void QCoreApplication::exit(int returnCode) The event is \e not deleted when the event has been sent. The normal approach is to create the event on the stack, for example: - \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 0 + \snippet code/src_corelib_kernel_qcoreapplication.cpp 0 \sa postEvent(), notify() */ @@ -1467,7 +1467,7 @@ void QCoreApplicationPrivate::maybeQuit() Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 1 + \snippet code/src_corelib_kernel_qcoreapplication.cpp 1 \sa exit(), aboutToQuit(), QApplication::lastWindowClosed() */ @@ -1515,7 +1515,7 @@ void QCoreApplication::quit() The function returns true on success and false on failure. - \sa removeTranslator() translate() QTranslator::load() {Dynamic Translation} + \sa removeTranslator(), translate(), QTranslator::load(), {Dynamic Translation} */ bool QCoreApplication::installTranslator(QTranslator *translationFile) @@ -1628,7 +1628,7 @@ static void replacePercentN(QString *result, int n) so will most likely result in crashes or other undesirable behavior. - \sa QObject::tr() installTranslator() + \sa QObject::tr(), installTranslator() */ @@ -1904,7 +1904,7 @@ QStringList QCoreApplication::arguments() organizationName(). On all other platforms, QSettings uses organizationName() as the organization. - \sa organizationDomain applicationName + \sa organizationDomain, applicationName */ void QCoreApplication::setOrganizationName(const QString &orgName) @@ -1930,7 +1930,7 @@ QString QCoreApplication::organizationName() On all other platforms, QSettings uses organizationName() as the organization. - \sa organizationName applicationName applicationVersion + \sa organizationName, applicationName, applicationVersion */ void QCoreApplication::setOrganizationDomain(const QString &orgDomain) { @@ -1952,7 +1952,7 @@ QString QCoreApplication::organizationDomain() If not set, the application name defaults to the executable name (since 5.0). - \sa organizationName organizationDomain applicationVersion applicationFilePath + \sa organizationName, organizationDomain, applicationVersion, applicationFilePath */ void QCoreApplication::setApplicationName(const QString &application) { @@ -1978,7 +1978,7 @@ Q_CORE_EXPORT QString qt_applicationName_noFallback() \since 4.4 \brief the version of this application - \sa applicationName organizationName organizationDomain + \sa applicationName, organizationName, organizationDomain */ void QCoreApplication::setApplicationVersion(const QString &version) { @@ -2012,7 +2012,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QMutex, libraryPathMutex, (QMutex::Recursive)) If you want to iterate over the list, you can use the \l foreach pseudo-keyword: - \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 2 + \snippet code/src_corelib_kernel_qcoreapplication.cpp 2 \sa setLibraryPaths(), addLibraryPath(), removeLibraryPath(), QLibrary, {How to Create Qt Plugins} @@ -2134,7 +2134,7 @@ void QCoreApplication::removeLibraryPath(const QString &path) A function with the following signature that can be used as an event filter: - \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 3 + \snippet code/src_corelib_kernel_qcoreapplication.cpp 3 \sa setEventFilter() */ @@ -2269,7 +2269,7 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc The function specified by \a ptr should take no arguments and should return nothing. For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 4 + \snippet code/src_corelib_kernel_qcoreapplication.cpp 4 Note that for an application- or module-wide cleanup, qAddPostRoutine() is often not suitable. For example, if the @@ -2283,7 +2283,7 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc parent-child mechanism to call a cleanup function at the right time: - \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 5 + \snippet code/src_corelib_kernel_qcoreapplication.cpp 5 By selecting the right parent object, this can often be made to clean up the module's data at the right moment. @@ -2297,7 +2297,7 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc translation functions, \c tr() and \c trUtf8(), with these signatures: - \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 6 + \snippet code/src_corelib_kernel_qcoreapplication.cpp 6 This macro is useful if you want to use QObject::tr() or QObject::trUtf8() in classes that don't inherit from QObject. @@ -2306,7 +2306,7 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc class definition (before the first \c{public:} or \c{protected:}). For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp 7 + \snippet code/src_corelib_kernel_qcoreapplication.cpp 7 The \a context parameter is normally the class name, but it can be any string. diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index d3a64aae04..deea463061 100644 --- a/src/corelib/kernel/qeventloop.cpp +++ b/src/corelib/kernel/qeventloop.cpp @@ -275,7 +275,7 @@ void QEventLoop::exit(int returnCode) false. The event loop is considered running from the time when exec() is called until exit() is called. - \sa exec() exit() + \sa exec(), exit() */ bool QEventLoop::isRunning() const { diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index e3b0b15e26..8a415c9944 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -492,7 +492,7 @@ int QMetaObject::constructorCount() const Use code like the following to obtain a QStringList containing the methods specific to a given class: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp methodCount + \snippet code/src_corelib_kernel_qmetaobject.cpp methodCount \sa method(), methodOffset(), indexOfMethod() */ @@ -530,7 +530,7 @@ int QMetaObject::enumeratorCount() const Use code like the following to obtain a QStringList containing the properties specific to a given class: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp propertyCount + \snippet code/src_corelib_kernel_qmetaobject.cpp propertyCount \sa property(), propertyOffset(), indexOfProperty() */ @@ -1102,7 +1102,7 @@ QMetaProperty QMetaObject::userProperty() const Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 0 + \snippet code/src_corelib_kernel_qmetaobject.cpp 0 \sa classInfoCount(), classInfoOffset(), indexOfClassInfo() */ @@ -1207,7 +1207,7 @@ static char *qNormalizeType(char *d, int &templdepth, QByteArray &result) Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 1 + \snippet code/src_corelib_kernel_qmetaobject.cpp 1 \sa normalizedSignature() */ @@ -1312,7 +1312,7 @@ enum { MaximumParamCount = 11 }; // up to 10 arguments + 1 return value the \l{QPushButton::animateClick()}{animateClick()} slot on a QPushButton, use the following code: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 2 + \snippet code/src_corelib_kernel_qmetaobject.cpp 2 With asynchronous method invocations, the parameters must be of types that are known to Qt's meta-object system, because Qt needs @@ -1320,7 +1320,7 @@ enum { MaximumParamCount = 11 }; // up to 10 arguments + 1 return value scenes. If you try to use a queued connection and get the error message - \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 3 + \snippet code/src_corelib_kernel_qmetaobject.cpp 3 call qRegisterMetaType() to register the data type before you call invokeMethod(). @@ -1328,7 +1328,7 @@ enum { MaximumParamCount = 11 }; // up to 10 arguments + 1 return value To synchronously invoke the \c compute(QString, int, double) slot on some arbitrary object \c obj retrieve its return value: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 4 + \snippet code/src_corelib_kernel_qmetaobject.cpp 4 If the "compute" slot does not take exactly one QString, one int and one double in the specified order, the call will fail. @@ -1883,7 +1883,7 @@ QMetaMethod::MethodType QMetaMethod::methodType() const \l{QPushButton::animateClick()}{animateClick()} slot on a QPushButton: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 6 + \snippet code/src_corelib_kernel_qmetaobject.cpp 6 With asynchronous method invocations, the parameters must be of types that are known to Qt's meta-object system, because Qt needs @@ -1891,7 +1891,7 @@ QMetaMethod::MethodType QMetaMethod::methodType() const scenes. If you try to use a queued connection and get the error message - \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 7 + \snippet code/src_corelib_kernel_qmetaobject.cpp 7 call qRegisterMetaType() to register the data type before you call QMetaMethod::invoke(). @@ -1899,7 +1899,7 @@ QMetaMethod::MethodType QMetaMethod::methodType() const To synchronously invoke the \c compute(QString, int, double) slot on some arbitrary object \c obj retrieve its return value: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 8 + \snippet code/src_corelib_kernel_qmetaobject.cpp 8 QMetaObject::normalizedSignature() is used here to ensure that the format of the signature is what invoke() expects. E.g. extra whitespace is @@ -3058,7 +3058,7 @@ bool QMetaProperty::isEditable(const QObject *object) const are specified using Q_CLASSINFO() in the source code. The information can be retrieved using name() and value(). For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 5 + \snippet code/src_corelib_kernel_qmetaobject.cpp 5 This mechanism is free for you to use in your Qt applications. Qt doesn't use it for any of its classes. diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index d262d6a61b..1dda9f2f05 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -609,7 +609,7 @@ QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QMetaProperty& protot \a name. Returns an object that can be used to adjust the other attributes of the enumerator. - \sa enumerator(), enumeratorCount(), removeEnumerator(), + \sa enumerator(), enumeratorCount(), removeEnumerator() \sa indexOfEnumerator() */ QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QByteArray& name) @@ -625,7 +625,7 @@ QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QByteArray& name) QMetaObject. Returns an object that can be used to adjust the attributes of the enumerator. - \sa enumerator(), enumeratorCount(), removeEnumerator(), + \sa enumerator(), enumeratorCount(), removeEnumerator() \sa indexOfEnumerator() */ QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QMetaEnum& prototype) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index fba1aaf9b6..e7f68fd596 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -125,16 +125,16 @@ struct DefinedTypesFilter { This example shows a typical use case of Q_DECLARE_METATYPE(): - \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 0 + \snippet code/src_corelib_kernel_qmetatype.cpp 0 If \c MyStruct is in a namespace, the Q_DECLARE_METATYPE() macro has to be outside the namespace: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 1 + \snippet code/src_corelib_kernel_qmetatype.cpp 1 Since \c{MyStruct} is now known to QMetaType, it can be used in QVariant: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 2 + \snippet code/src_corelib_kernel_qmetatype.cpp 2 \sa qRegisterMetaType() */ @@ -220,21 +220,13 @@ struct DefinedTypesFilter { \value User Base value for user types \value UnknownType This is an invalid type id. It is returned from QMetaType for types that are not registered - \omitvalue FirstGuiType - \omitvalue FirstWidgetsType - \omitvalue LastCoreType - \omitvalue LastGuiType - \omitvalue LastWidgetsType - \omitvalue QReal - \omitvalue HighestInternalId - Additional types can be registered using Q_DECLARE_METATYPE(). \sa type(), typeName() */ /*! - \enum QMetaType::TypeFlags + \enum QMetaType::TypeFlag The enum describes attributes of a type supported by QMetaType. @@ -265,7 +257,7 @@ struct DefinedTypesFilter { The following code allocates and destructs an instance of \c{MyClass}: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 3 + \snippet code/src_corelib_kernel_qmetatype.cpp 3 If we want the stream operators \c operator<<() and \c operator>>() to work on QVariant objects that store custom types, @@ -1486,12 +1478,12 @@ QMetaType::TypeFlags QMetaType::typeFlags(int type) This example registers the class \c{MyClass}: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 4 + \snippet code/src_corelib_kernel_qmetatype.cpp 4 This function is useful to register typedefs so they can be used by QMetaProperty, or in QueuedConnections - \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 9 + \snippet code/src_corelib_kernel_qmetatype.cpp 9 \sa qRegisterMetaTypeStreamOperators(), QMetaType::isRegistered(), Q_DECLARE_METATYPE() @@ -1509,11 +1501,11 @@ QMetaType::TypeFlags QMetaType::typeFlags(int type) QMetaType::save(). These functions are used when streaming a QVariant. - \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 5 + \snippet code/src_corelib_kernel_qmetatype.cpp 5 The stream operators should have the following signatures: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 6 + \snippet code/src_corelib_kernel_qmetatype.cpp 6 \sa qRegisterMetaType(), QMetaType::isRegistered(), Q_DECLARE_METATYPE() */ @@ -1548,7 +1540,7 @@ QMetaType::TypeFlags QMetaType::typeFlags(int type) Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 7 + \snippet code/src_corelib_kernel_qmetatype.cpp 7 To use the type \c T in QVariant, using Q_DECLARE_METATYPE() is sufficient. To use the type \c T in queued signal and slot connections, @@ -1574,7 +1566,7 @@ QMetaType::TypeFlags QMetaType::typeFlags(int type) Typical usage: - \snippet doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp 8 + \snippet code/src_corelib_kernel_qmetatype.cpp 8 QMetaType::type() returns the same ID as qMetaTypeId(), but does a lookup at runtime based on the name of the type. diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 21f4bc7afe..14f349083d 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -195,6 +195,8 @@ class Q_CORE_EXPORT QMetaType { FlagsEx = 0x100 }; public: +#ifndef Q_QDOC + // The code that actually gets compiled. enum Type { // these are merged with QVariant QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID) @@ -212,6 +214,29 @@ public: UnknownType = 0, User = 1024 }; +#else + // If we are using QDoc it fakes the Type enum looks like this. + enum Type { + Void = 0, Bool = 1, Int = 2, UInt = 3, LongLong = 4, ULongLong = 5, + Double = 6, Long = 32, Short = 33, Char = 34, ULong = 35, UShort = 36, + UChar = 37, Float = 38, + VoidStar = 31, + QChar = 7, QString = 10, QStringList = 11, QByteArray = 12, + QBitArray = 13, QDate = 14, QTime = 15, QDateTime = 16, QUrl = 17, + QLocale = 18, QRect = 19, QRectF = 20, QSize = 21, QSizeF = 22, + QLine = 23, QLineF = 24, QPoint = 25, QPointF = 26, QRegExp = 27, + QEasingCurve = 29, QUuid = 30, QVariant = 41, QModelIndex = 42, + QObjectStar = 39, QWidgetStar = 40, + QVariantMap = 8, QVariantList = 9, QVariantHash = 28, + QFont = 64, QPixmap = 65, QBrush = 66, QColor = 67, QPalette = 68, + QImage = 69, QPolygon = 70, QRegion = 71, QBitmap = 72, QCursor = 73, + QKeySequence = 74, QPen = 75, QTextLength = 76, QTextFormat = 77, + QMatrix = 78, QTransform = 79, QMatrix4x4 = 80, QVector2D = 81, + QVector3D = 82, QVector4D = 83, QQuaternion = 84, QPolygonF = 85, + QIcon = 120, QSizePolicy = 121, + User = 256 + }; +#endif enum TypeFlag { NeedsConstruction = 0x1, diff --git a/src/corelib/kernel/qmimedata.cpp b/src/corelib/kernel/qmimedata.cpp index 3a3464e43e..c18ce22247 100644 --- a/src/corelib/kernel/qmimedata.cpp +++ b/src/corelib/kernel/qmimedata.cpp @@ -257,7 +257,7 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Ty For example, if your write a widget that accepts URL drags, you would end up writing code like this: - \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 0 + \snippet code/src_corelib_kernel_qmimedata.cpp 0 There are three approaches for storing custom data in a QMimeData object: @@ -266,7 +266,7 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Ty \li Custom data can be stored directly in a QMimeData object as a QByteArray using setData(). For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 1 + \snippet code/src_corelib_kernel_qmimedata.cpp 1 \li We can subclass QMimeData and reimplement hasFormat(), formats(), and retrieveData(). @@ -276,7 +276,7 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Ty it, and use a qobject_cast() in the receiver's drop event handler. For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 2 + \snippet code/src_corelib_kernel_qmimedata.cpp 2 \endlist \section1 Platform-Specific MIME Types @@ -286,11 +286,11 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Ty indicate that they represent data in non-standard formats. The formats will take the following form: - \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 3 + \snippet code/src_corelib_kernel_qmimedata.cpp 3 The following are examples of custom MIME types: - \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 4 + \snippet code/src_corelib_kernel_qmimedata.cpp 4 The \c value declaration of each format describes the way in which the data is encoded. @@ -458,7 +458,7 @@ bool QMimeData::hasHtml() const library, whereas QImage belongs to \l QtGui. To convert the QVariant to a QImage, simply use qvariant_cast(). For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 5 + \snippet code/src_corelib_kernel_qmimedata.cpp 5 \sa hasImage() */ @@ -475,7 +475,7 @@ QVariant QMimeData::imageData() const library, whereas QImage belongs to \l QtGui. The conversion from QImage to QVariant is implicit. For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 6 + \snippet code/src_corelib_kernel_qmimedata.cpp 6 \sa hasImage(), setData() */ @@ -505,7 +505,7 @@ bool QMimeData::hasImage() const library, whereas QColor belongs to \l QtGui. To convert the QVariant to a QColor, simply use qvariant_cast(). For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp 7 + \snippet code/src_corelib_kernel_qmimedata.cpp 7 \sa hasColor(), setColorData(), data() */ diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index fb3e4e396b..5ccbad4667 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -568,9 +568,9 @@ void QMetaCallEvent::placeMetaCall(QObject *object) \l uic generates code that invokes this function to enable auto-connection to be performed between widgets on forms created - with \QD. More information about using auto-connection with \QD is + with \e{Qt Designer}. More information about using auto-connection with \e{Qt Designer} is given in the \l{Using a Designer UI File in Your Application} section of - the \QD manual. + the \e{Qt Designer} manual. \section1 Dynamic Properties @@ -606,7 +606,7 @@ void QMetaCallEvent::placeMetaCall(QObject *object) Returns 0 if there is no such child. - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 0 + \snippet code/src_corelib_kernel_qobject.cpp 0 */ void *qt_find_obj_child(QObject *parent, const char *type, const QString &name) @@ -651,8 +651,8 @@ static bool check_parent_thread(QObject *parent, Constructs an object with parent object \a parent. The parent of an object may be viewed as the object's owner. For - instance, a \l{QDialog}{dialog box} is the parent of the \gui OK - and \gui Cancel buttons it contains. + instance, a \l{QDialog}{dialog box} is the parent of the \uicontrol{OK} + and \uicontrol{Cancel} buttons it contains. The destructor of a parent object destroys all child objects. @@ -881,7 +881,7 @@ QObjectPrivate::Connection::~Connection() Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 1 + \snippet code/src_corelib_kernel_qobject.cpp 1 \sa staticMetaObject */ @@ -905,7 +905,7 @@ QObjectPrivate::Connection::~Connection() Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 2 + \snippet code/src_corelib_kernel_qobject.cpp 2 \sa metaObject() */ @@ -924,7 +924,7 @@ QObjectPrivate::Connection::~Connection() Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 3 + \snippet code/src_corelib_kernel_qobject.cpp 3 The qobject_cast() function behaves similarly to the standard C++ \c dynamic_cast(), with the advantages that it doesn't require @@ -950,7 +950,7 @@ QObjectPrivate::Connection::~Connection() Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 4 + \snippet code/src_corelib_kernel_qobject.cpp 4 If you need to determine whether an object is an instance of a particular class for the purpose of casting it, consider using qobject_cast(object) @@ -967,7 +967,7 @@ QObjectPrivate::Connection::~Connection() You can find an object by name (and type) using findChild(). You can find a set of objects with findChildren(). - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 5 + \snippet code/src_corelib_kernel_qobject.cpp 5 By default, this property contains an empty string. @@ -1155,7 +1155,7 @@ void QObject::customEvent(QEvent * /* event */) true; otherwise return false. Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 6 + \snippet code/src_corelib_kernel_qobject.cpp 6 Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class @@ -1225,7 +1225,7 @@ QThread *QObject::thread() const QApplication::thread() to retrieve the thread in which the application lives. For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 7 + \snippet code/src_corelib_kernel_qobject.cpp 7 If \a targetThread is zero, all event processing for this object and its children stops. @@ -1390,7 +1390,7 @@ void QObjectPrivate::_q_reregisterTimers(void *pointer) Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 8 + \snippet code/src_corelib_kernel_qobject.cpp 8 Note that QTimer's accuracy depends on the underlying operating system and hardware. The \a timerType argument allows you to customize the accuracy of @@ -1472,7 +1472,7 @@ void QObject::killTimer(int id) The QObjectList class is defined in the \c{} header file as the following: - \quotefromfile src/corelib/kernel/qobject.h + \quotefromfile kernel/qobject.h \skipto /typedef .*QObjectList/ \printuntil QObjectList @@ -1507,21 +1507,21 @@ void QObject::killTimer(int id) named \c{"button1"}, even if the button isn't a direct child of the parent: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 10 + \snippet code/src_corelib_kernel_qobject.cpp 10 This example returns a \l{QListWidget} child of \c{parentWidget}: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 11 + \snippet code/src_corelib_kernel_qobject.cpp 11 This example returns a child \l{QPushButton} of \c{parentWidget} (its direct parent) named \c{"button1"}: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 41 + \snippet code/src_corelib_kernel_qobject.cpp 41 This example returns a \l{QListWidget} child of \c{parentWidget}, its direct parent: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 42 + \snippet code/src_corelib_kernel_qobject.cpp 42 \sa findChildren() */ @@ -1538,15 +1538,15 @@ void QObject::killTimer(int id) The following example shows how to find a list of child \l{QWidget}s of the specified \c{parentWidget} named \c{widgetname}: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 12 + \snippet code/src_corelib_kernel_qobject.cpp 12 This example returns all \c{QPushButton}s that are children of \c{parentWidget}: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 13 + \snippet code/src_corelib_kernel_qobject.cpp 13 This example returns all \c{QPushButton}s that are immediate children of \c{parentWidget}: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 43 + \snippet code/src_corelib_kernel_qobject.cpp 43 \sa findChild() */ @@ -1791,7 +1791,7 @@ void QObjectPrivate::setParent_helper(QObject *o) \fn void QObject::installEventFilter(QObject *filterObj) Installs an event filter \a filterObj on this object. For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 14 + \snippet code/src_corelib_kernel_qobject.cpp 14 An event filter is an object that receives all events that are sent to this object. The filter can either stop the event or @@ -1806,11 +1806,11 @@ void QObjectPrivate::setParent_helper(QObject *o) Here's a \c KeyPressEater class that eats the key presses of its monitored objects: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 15 + \snippet code/src_corelib_kernel_qobject.cpp 15 And here's how to install it on two widgets: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 16 + \snippet code/src_corelib_kernel_qobject.cpp 16 The QShortcut class, for example, uses this technique to intercept shortcut key presses. @@ -1925,7 +1925,7 @@ void QObject::deleteLater() Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 17 + \snippet code/src_corelib_kernel_qobject.cpp 17 \dots See \l{Writing Source Code for Translation} for a detailed description of @@ -1959,7 +1959,7 @@ void QObject::deleteLater() escape sequences for specifying non-ASCII characters in string literals to trUtf8(). For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 20 + \snippet code/src_corelib_kernel_qobject.cpp 20 \sa tr(), QApplication::translate(), {Internationalization with Qt} */ @@ -2153,7 +2153,7 @@ int QObject::senderSignalIndex() const When calling this function, you can use the \c SIGNAL() macro to pass a specific signal: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 21 + \snippet code/src_corelib_kernel_qobject.cpp 21 As the code snippet above illustrates, you can use this function to avoid emitting a signal that nobody listens to. @@ -2278,18 +2278,18 @@ static inline void check_and_warn_compat(const QMetaObject *sender, const QMetaM You must use the \c SIGNAL() and \c SLOT() macros when specifying the \a signal and the \a method, for example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 22 + \snippet code/src_corelib_kernel_qobject.cpp 22 This example ensures that the label always displays the current scroll bar value. Note that the signal and slots parameters must not contain any variable names, only the type. E.g. the following would not work and return false: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 23 + \snippet code/src_corelib_kernel_qobject.cpp 23 A signal can also be connected to another signal: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 24 + \snippet code/src_corelib_kernel_qobject.cpp 24 In this example, the \c MyWidget constructor relays a signal from a private member variable, and makes it available under a name @@ -2326,7 +2326,7 @@ static inline void check_and_warn_compat(const QMetaObject *sender, const QMetaM scenes. If you try to use a queued connection and get the error message - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 25 + \snippet code/src_corelib_kernel_qobject.cpp 25 call qRegisterMetaType() to register the data type before you establish the connection. @@ -2575,27 +2575,27 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho \list 1 \li Disconnect everything connected to an object's signals: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 26 + \snippet code/src_corelib_kernel_qobject.cpp 26 equivalent to the non-static overloaded function - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 27 + \snippet code/src_corelib_kernel_qobject.cpp 27 \li Disconnect everything connected to a specific signal: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 28 + \snippet code/src_corelib_kernel_qobject.cpp 28 equivalent to the non-static overloaded function - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 29 + \snippet code/src_corelib_kernel_qobject.cpp 29 \li Disconnect a specific receiver: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 30 + \snippet code/src_corelib_kernel_qobject.cpp 30 equivalent to the non-static overloaded function - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 31 + \snippet code/src_corelib_kernel_qobject.cpp 31 \endlist @@ -2847,7 +2847,7 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal, If you want to compare \a signal with a specific signal, use QLatin1String and the \c SIGNAL() macro as follows: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 32 + \snippet code/src_corelib_kernel_qobject.cpp 32 If the signal contains multiple parameters or parameters that contain spaces, call QMetaObject::normalizedSignature() on @@ -3101,13 +3101,13 @@ bool QMetaObjectPrivate::disconnect(const QObject *sender, int signal_index, Searches recursively for all child objects of the given \a object, and connects matching signals from them to slots of \a object that follow the following form: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 33 + \snippet code/src_corelib_kernel_qobject.cpp 33 Let's assume our object has a child object of type QPushButton with the \l{QObject::objectName}{object name} \c{button1}. The slot to catch the button's \c{clicked()} signal would be: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 34 + \snippet code/src_corelib_kernel_qobject.cpp 34 \sa QObject::setObjectName() */ @@ -3722,7 +3722,7 @@ QDebug operator<<(QDebug dbg, const QObject *o) { Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 35 + \snippet code/src_corelib_kernel_qobject.cpp 35 \sa QMetaObject::classInfo() */ @@ -3736,9 +3736,9 @@ QDebug operator<<(QDebug dbg, const QObject *o) { Example: - \snippet examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h 1 + \snippet tools/plugandpaintplugins/basictools/basictoolsplugin.h 1 \dots - \snippet examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h 3 + \snippet tools/plugandpaintplugins/basictools/basictoolsplugin.h 3 See the \l{tools/plugandpaintplugins/basictools}{Plug & Paint Basic Tools} example for details. @@ -3755,7 +3755,7 @@ QDebug operator<<(QDebug dbg, const QObject *o) { they have additional features accessible through the \l {Meta-Object System}. - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 36 + \snippet code/src_corelib_kernel_qobject.cpp 36 The property name and type and the \c READ function are required. The type can be any type supported by QVariant, or it can be a @@ -3765,7 +3765,7 @@ QDebug operator<<(QDebug dbg, const QObject *o) { For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 37 + \snippet code/src_corelib_kernel_qobject.cpp 37 For more details about how to use this macro, and a more detailed example of its use, see the discussion on \l {Qt's Property System}. @@ -3782,7 +3782,7 @@ QDebug operator<<(QDebug dbg, const QObject *o) { For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 38 + \snippet code/src_corelib_kernel_qobject.cpp 38 If you want to register an enum that is declared in another class, the enum must be fully qualified with the name of the class @@ -3804,12 +3804,12 @@ QDebug operator<<(QDebug dbg, const QObject *o) { For example, in QLibrary, the \l{QLibrary::LoadHints}{LoadHints} flag is declared in the following way: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 39a + \snippet code/src_corelib_kernel_qobject.cpp 39a The declaration of the flags themselves is performed in the public section of the QLibrary class itself, using the \l Q_DECLARE_FLAGS() macro: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 39b + \snippet code/src_corelib_kernel_qobject.cpp 39b \note This macro takes care of registering individual flag values with the meta-object system, so it is unnecessary to use Q_ENUMS() @@ -3828,10 +3828,10 @@ QDebug operator<<(QDebug dbg, const QObject *o) { For example: - \snippet doc/src/snippets/signalsandslots/signalsandslots.h 1 + \snippet signalsandslots/signalsandslots.h 1 \codeline - \snippet doc/src/snippets/signalsandslots/signalsandslots.h 2 - \snippet doc/src/snippets/signalsandslots/signalsandslots.h 3 + \snippet signalsandslots/signalsandslots.h 2 + \snippet signalsandslots/signalsandslots.h 3 \note This macro requires the class to be a subclass of QObject. Use Q_GADGET instead of Q_OBJECT to enable the meta object system's support @@ -3927,7 +3927,7 @@ QDebug operator<<(QDebug dbg, const QObject *o) { be invoked via the meta-object system. The macro is written before the return type, as shown in the following example: - \snippet snippets/qmetaobject-invokable/window.h Window class with invokable method + \snippet qmetaobject-invokable/window.h Window class with invokable method The \c invokableMethod() function is marked up using Q_INVOKABLE, causing it to be registered with the meta-object system and enabling it to be @@ -3968,7 +3968,7 @@ void qDeleteInEventHandler(QObject *o) Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 44 + \snippet code/src_corelib_kernel_qobject.cpp 44 This example ensures that the label always displays the current line edit text. @@ -4003,7 +4003,7 @@ void qDeleteInEventHandler(QObject *o) scenes. If you try to use a queued connection and get the error message - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 25 + \snippet code/src_corelib_kernel_qobject.cpp 25 make sure to declare the argument type with Q_DECLARE_METATYPE */ @@ -4029,11 +4029,11 @@ void qDeleteInEventHandler(QObject *o) Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 45 + \snippet code/src_corelib_kernel_qobject.cpp 45 If your compiler support C++11 lambda expressions, you can use them: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 46 + \snippet code/src_corelib_kernel_qobject.cpp 46 The connection will automatically disconnect if the sender is destroyed. */ @@ -4178,19 +4178,19 @@ bool QObject::disconnect(const QMetaObject::Connection &connection) \list 1 \li Disconnect everything connected to an object's signals: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 26 + \snippet code/src_corelib_kernel_qobject.cpp 26 \li Disconnect everything connected to a specific signal: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 47 + \snippet code/src_corelib_kernel_qobject.cpp 47 \li Disconnect a specific receiver: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 30 + \snippet code/src_corelib_kernel_qobject.cpp 30 \li Disconnect a connection from one specific signal to a specific slot: - \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 48 + \snippet code/src_corelib_kernel_qobject.cpp 48 \endlist diff --git a/src/corelib/kernel/qobjectcleanuphandler.cpp b/src/corelib/kernel/qobjectcleanuphandler.cpp index 166a90a74f..f165ec96ca 100644 --- a/src/corelib/kernel/qobjectcleanuphandler.cpp +++ b/src/corelib/kernel/qobjectcleanuphandler.cpp @@ -121,7 +121,7 @@ void QObjectCleanupHandler::remove(QObject *object) Returns true if this cleanup handler is empty or if all objects in this cleanup handler have been destroyed; otherwise return false. - \sa add() remove() clear() + \sa add(), remove(), clear() */ bool QObjectCleanupHandler::isEmpty() const { diff --git a/src/corelib/kernel/qpointer.cpp b/src/corelib/kernel/qpointer.cpp index e0e14e5b79..cd88baf9bf 100644 --- a/src/corelib/kernel/qpointer.cpp +++ b/src/corelib/kernel/qpointer.cpp @@ -74,10 +74,10 @@ Example: - \snippet doc/src/snippets/pointer/pointer.cpp 0 + \snippet pointer/pointer.cpp 0 \dots - \snippet doc/src/snippets/pointer/pointer.cpp 1 - \snippet doc/src/snippets/pointer/pointer.cpp 2 + \snippet pointer/pointer.cpp 1 + \snippet pointer/pointer.cpp 2 If the QLabel is deleted in the meantime, the \c label variable will hold 0 instead of an invalid address, and the last line will diff --git a/src/corelib/kernel/qsharedmemory.cpp b/src/corelib/kernel/qsharedmemory.cpp index d8578a8059..50c24ba169 100644 --- a/src/corelib/kernel/qsharedmemory.cpp +++ b/src/corelib/kernel/qsharedmemory.cpp @@ -174,7 +174,7 @@ QSharedMemory::QSharedMemory(const QString &key, QObject *parent) the shared memory segment, the detach() operation destroys the shared memory segment. - \sa detach() isAttached() + \sa detach(), isAttached() */ QSharedMemory::~QSharedMemory() { @@ -193,7 +193,7 @@ QSharedMemory::~QSharedMemory() segment, it will \l {detach()} {detach} from it before setting the new key. This function does not do an attach(). - \sa key() nativeKey() isAttached() + \sa key(), nativeKey(), isAttached() */ void QSharedMemory::setKey(const QString &key) { @@ -225,7 +225,7 @@ void QSharedMemory::setKey(const QString &key) The application will not be portable if you set a native key. - \sa nativeKey() key() isAttached() + \sa nativeKey(), key(), isAttached() */ void QSharedMemory::setNativeKey(const QString &key) { @@ -288,7 +288,7 @@ bool QSharedMemoryPrivate::initKey() You can find the native, platform specific, key used by the operating system by calling nativeKey(). - \sa setKey() setNativeKey() + \sa setKey(), setNativeKey() */ QString QSharedMemory::key() const { @@ -306,7 +306,7 @@ QString QSharedMemory::key() const You can use the native key to access shared memory segments that have not been created by Qt, or to grant shared memory access to non-Qt applications. - \sa setKey() setNativeKey() + \sa setKey(), setNativeKey() */ QString QSharedMemory::nativeKey() const { @@ -363,7 +363,7 @@ bool QSharedMemory::create(int size, AccessMode mode) Returns the size of the attached shared memory segment. If no shared memory segment is attached, 0 is returned. - \sa create() attach() + \sa create(), attach() */ int QSharedMemory::size() const { @@ -472,7 +472,7 @@ void *QSharedMemory::data() the shared memory, and remember to release the lock with unlock() after you are done. - \sa attach() create() + \sa attach(), create() */ const void* QSharedMemory::constData() const { diff --git a/src/corelib/kernel/qsignalmapper.cpp b/src/corelib/kernel/qsignalmapper.cpp index 27340020d8..c668047bd2 100644 --- a/src/corelib/kernel/qsignalmapper.cpp +++ b/src/corelib/kernel/qsignalmapper.cpp @@ -91,14 +91,14 @@ public: signal, \c clicked(), which is emitted with the text of the button that was clicked: - \snippet doc/src/snippets/qsignalmapper/buttonwidget.h 0 - \snippet doc/src/snippets/qsignalmapper/buttonwidget.h 1 + \snippet qsignalmapper/buttonwidget.h 0 + \snippet qsignalmapper/buttonwidget.h 1 The only function that we need to implement is the constructor: - \snippet doc/src/snippets/qsignalmapper/buttonwidget.cpp 0 - \snippet doc/src/snippets/qsignalmapper/buttonwidget.cpp 1 - \snippet doc/src/snippets/qsignalmapper/buttonwidget.cpp 2 + \snippet qsignalmapper/buttonwidget.cpp 0 + \snippet qsignalmapper/buttonwidget.cpp 1 + \snippet qsignalmapper/buttonwidget.cpp 2 A list of texts is passed to the constructor. A signal mapper is constructed and for each text in the list a QPushButton is diff --git a/src/corelib/kernel/qsystemsemaphore.cpp b/src/corelib/kernel/qsystemsemaphore.cpp index 0558f3cb59..70e75b54b9 100644 --- a/src/corelib/kernel/qsystemsemaphore.cpp +++ b/src/corelib/kernel/qsystemsemaphore.cpp @@ -79,7 +79,7 @@ QT_BEGIN_NAMESPACE can use to use the same semaphore. Example: Create a system semaphore - \snippet doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp 0 + \snippet code/src_corelib_kernel_qsystemsemaphore.cpp 0 A typical application of system semaphores is for controlling access to a circular buffer shared by a producer process and a consumer @@ -283,13 +283,13 @@ bool QSystemSemaphore::acquire() Example: Create a system semaphore having five resources; acquire them all and then release them all. - \snippet doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp 1 + \snippet code/src_corelib_kernel_qsystemsemaphore.cpp 1 This function can also "create" resources. For example, immediately following the sequence of statements above, suppose we add the statement: - \snippet doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp 2 + \snippet code/src_corelib_kernel_qsystemsemaphore.cpp 2 Ten new resources are now guarded by the semaphore, in addition to the five that already existed. You would not normally use this diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp index 2131188439..048388d3c7 100644 --- a/src/corelib/kernel/qtimer.cpp +++ b/src/corelib/kernel/qtimer.cpp @@ -61,9 +61,9 @@ QT_BEGIN_NAMESPACE Example for a one second (1000 millisecond) timer (from the \l{widgets/analogclock}{Analog Clock} example): - \snippet examples/widgets/analogclock/analogclock.cpp 4 - \snippet examples/widgets/analogclock/analogclock.cpp 5 - \snippet examples/widgets/analogclock/analogclock.cpp 6 + \snippet widgets/analogclock/analogclock.cpp 4 + \snippet widgets/analogclock/analogclock.cpp 5 + \snippet widgets/analogclock/analogclock.cpp 6 From then on, the \c update() slot is called every second. @@ -72,7 +72,7 @@ QT_BEGIN_NAMESPACE QTimer::singleShot() function to call a slot after a specified interval: - \snippet doc/src/snippets/timers/timers.cpp 3 + \snippet timers/timers.cpp 3 In multithreaded applications, you can use QTimer in any thread that has an event loop. To start an event loop from a non-GUI @@ -87,9 +87,9 @@ QT_BEGIN_NAMESPACE been processed. This can be used to do heavy work while providing a snappy user interface: - \snippet doc/src/snippets/timers/timers.cpp 4 - \snippet doc/src/snippets/timers/timers.cpp 5 - \snippet doc/src/snippets/timers/timers.cpp 6 + \snippet timers/timers.cpp 4 + \snippet timers/timers.cpp 5 + \snippet timers/timers.cpp 6 \c processOneThing() will from then on be called repeatedly. It should be written in such a way that it always returns quickly @@ -304,7 +304,7 @@ QT_END_INCLUDE_NAMESPACE create a local QTimer object. Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qtimer.cpp 0 + \snippet code/src_corelib_kernel_qtimer.cpp 0 This sample program automatically terminates after 10 minutes (600,000 milliseconds). diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp index 892883bacd..c34a3acb70 100644 --- a/src/corelib/kernel/qtranslator.cpp +++ b/src/corelib/kernel/qtranslator.cpp @@ -338,7 +338,7 @@ public: it via QObject::tr(). Here's the \c main() function from the \l{linguist/hellotr}{Hello tr()} example: - \snippet examples/linguist/hellotr/main.cpp 2 + \snippet linguist/hellotr/main.cpp 2 Note that the translator must be created \e before the application's widgets. diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 296b845469..c363be86c8 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -913,7 +913,7 @@ Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names Here is some example code to demonstrate the use of QVariant: - \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 0 + \snippet code/src_corelib_kernel_qvariant.cpp 0 You can even store QList and QMap values in a variant, so you can easily construct arbitrarily @@ -925,7 +925,7 @@ Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names have a defined type with no value set. However, note that QVariant types can only be cast when they have had a value set. - \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 1 + \snippet code/src_corelib_kernel_qvariant.cpp 1 QVariant can be extended to support other types than those mentioned in the \l Type enum. See the \l QMetaType documentation @@ -939,13 +939,13 @@ Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names toColor() function. Instead, you can use the QVariant::value() or the qvariant_cast() template function. For example: - \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 2 + \snippet code/src_corelib_kernel_qvariant.cpp 2 The inverse conversion (e.g., from QColor to QVariant) is automatic for all data types supported by QVariant, including GUI-related types: - \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 3 + \snippet code/src_corelib_kernel_qvariant.cpp 3 \section1 Using canConvert() and convert() Consecutively @@ -2551,7 +2551,7 @@ bool QVariant::convert(int targetTypeId) } /*! - \fn convert(const int type, void *ptr) const + \fn bool QVariant::convert(const int type, void *ptr) const \internal Created for qvariant_cast() usage */ @@ -2695,7 +2695,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 4 + \snippet code/src_corelib_kernel_qvariant.cpp 4 \sa value(), fromValue(), canConvert() */ @@ -2712,7 +2712,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 5 + \snippet code/src_corelib_kernel_qvariant.cpp 5 \sa setValue(), fromValue(), canConvert() */ @@ -2724,7 +2724,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 6 + \snippet code/src_corelib_kernel_qvariant.cpp 6 \sa convert() */ @@ -2736,7 +2736,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) Example: - \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 7 + \snippet code/src_corelib_kernel_qvariant.cpp 7 \note If you are working with custom types, you should use the Q_DECLARE_METATYPE() macro to register your custom type. @@ -2761,7 +2761,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) For example, a QObject pointer can be stored in a variant with the following code: - \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 8 + \snippet code/src_corelib_kernel_qvariant.cpp 8 \sa QVariant::fromValue() */ diff --git a/src/corelib/mimetypes/qmimedatabase.cpp b/src/corelib/mimetypes/qmimedatabase.cpp index 2c84a937d5..2ac1978c2a 100644 --- a/src/corelib/mimetypes/qmimedatabase.cpp +++ b/src/corelib/mimetypes/qmimedatabase.cpp @@ -289,7 +289,7 @@ bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent) \threadsafe - \snippet doc/src/snippets/code/src_corelib_mimetype_qmimedatabase.cpp 0 + \snippet code/src_corelib_mimetype_qmimedatabase.cpp 0 \sa QMimeType */ diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 216e6e1e7c..7bb1ef1263 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -127,7 +127,7 @@ static QBasicMutex qt_library_mutex; symbol is not defined, the function pointer will be 0 and won't be called. - \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 0 + \snippet code/src_corelib_plugin_qlibrary.cpp 0 The symbol must be exported as a C function from the library for resolve() to work. This means that the function must be wrapped in @@ -138,7 +138,7 @@ static QBasicMutex qt_library_mutex; use if you just want to call a function in a library without explicitly loading the library first: - \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 1 + \snippet code/src_corelib_plugin_qlibrary.cpp 1 \sa QPluginLoader */ @@ -1118,7 +1118,7 @@ void QLibrary::setFileNameAndVersion(const QString &fileName, const QString &ver not be resolved or if the library could not be loaded. Example: - \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 2 + \snippet code/src_corelib_plugin_qlibrary.cpp 2 The symbol must be exported as a C function from the library. This means that the function must be wrapped in an \c{extern "C"} if @@ -1126,11 +1126,11 @@ void QLibrary::setFileNameAndVersion(const QString &fileName, const QString &ver also explicitly export the function from the DLL using the \c{__declspec(dllexport)} compiler directive, for example: - \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 3 + \snippet code/src_corelib_plugin_qlibrary.cpp 3 with \c MY_EXPORT defined as - \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 4 + \snippet code/src_corelib_plugin_qlibrary.cpp 4 */ QFunctionPointer QLibrary::resolve(const char *symbol) { diff --git a/src/corelib/plugin/qplugin.qdoc b/src/corelib/plugin/qplugin.qdoc index 77069e6dfd..001b0d5932 100644 --- a/src/corelib/plugin/qplugin.qdoc +++ b/src/corelib/plugin/qplugin.qdoc @@ -42,7 +42,7 @@ to the interface class called \a ClassName. The \a Identifier must be unique. For example: - \snippet examples/tools/plugandpaint/interfaces.h 3 + \snippet tools/plugandpaint/interfaces.h 3 This macro is normally used right after the class definition for \a ClassName, in a header file. See the @@ -51,7 +51,7 @@ If you want to use Q_DECLARE_INTERFACE with interface classes declared in a namespace then you have to make sure the Q_DECLARE_INTERFACE is not inside a namespace though. For example: - \snippet doc/src/snippets/code/doc_src_qplugin.cpp 0 + \snippet code/doc_src_qplugin.cpp 0 \sa Q_INTERFACES(), Q_EXPORT_PLUGIN2(), {How to Create Qt Plugins} */ @@ -82,7 +82,7 @@ Example: - \snippet doc/src/snippets/code/doc_src_qplugin.cpp 1 + \snippet code/doc_src_qplugin.cpp 1 See the \l{tools/plugandpaint}{Plug & Paint} example for details. @@ -102,14 +102,14 @@ Example: - \snippet doc/src/snippets/code/doc_src_qplugin.cpp 2 + \snippet code/doc_src_qplugin.cpp 2 Static plugins must also be included by the linker when your application is built. For Qt's predefined plugins, you can use the \c QTPLUGIN to add the required plugins to your build. For example: - \snippet doc/src/snippets/code/doc_src_qplugin.pro 3 + \snippet code/doc_src_qplugin.pro 3 \sa {Static Plugins}, {How to Create Qt Plugins}, {Using qmake} */ diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index 26032323e0..b1805afd53 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -337,7 +337,7 @@ static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCrypto b8. Example: - \snippet doc/src/snippets/code/src_corelib_plugin_quuid.cpp 0 + \snippet code/src_corelib_plugin_quuid.cpp 0 */ #ifndef QT_NO_QUUID_STRING @@ -425,7 +425,7 @@ QUuid::QUuid(const QByteArray &text) /*! \since 5.0 - \fn QUuid::createUuidV3() + \fn QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData); This functions returns a new UUID with variant QUuid::DCE and version QUuid::MD5. \a ns is the namespace and \a name is the name as described by RFC 4122. @@ -435,7 +435,7 @@ QUuid::QUuid(const QByteArray &text) /*! \since 5.0 - \fn QUuid::createUuidV5() + \fn QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData); This functions returns a new UUID with variant QUuid::DCE and version QUuid::SHA1. \a ns is the namespace and \a name is the name as described by RFC 4122. diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index ad2cb02213..4bb000a646 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -126,7 +126,7 @@ QT_BEGIN_NAMESPACE The following snippet shows a state machine that will finish when a button is clicked: - \snippet doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp simple state machine + \snippet code/src_corelib_statemachine_qstatemachine.cpp simple state machine This code example uses QState, which inherits QAbstractState. The QState class provides a state that you can use to set properties @@ -1747,7 +1747,7 @@ QStateMachine::~QStateMachine() \value RestoreProperties The state machine should save the initial values of properties and restore them later. - \sa QStateMachine::globalRestorePolicy QState::assignProperty() + \sa QStateMachine::globalRestorePolicy, QState::assignProperty() */ diff --git a/src/corelib/thread/qatomic.cpp b/src/corelib/thread/qatomic.cpp index 2e3029f3fa..abd2cc1c93 100644 --- a/src/corelib/thread/qatomic.cpp +++ b/src/corelib/thread/qatomic.cpp @@ -68,7 +68,7 @@ functions allow you to implement your own implicitly shared classes. - \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 0 + \snippet code/src_corelib_thread_qatomic.cpp 0 \section2 Memory ordering @@ -104,7 +104,7 @@ nothing and return false. This operation equates to the following code: - \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 1 + \snippet code/src_corelib_thread_qatomic.cpp 1 There are 4 test-and-set functions: testAndSetRelaxed(), testAndSetAcquire(), testAndSetRelease(), and @@ -117,7 +117,7 @@ QAtomicInt and then assign a new value, returning the original value. This operation equates to the following code: - \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 2 + \snippet code/src_corelib_thread_qatomic.cpp 2 There are 4 fetch-and-store functions: fetchAndStoreRelaxed(), fetchAndStoreAcquire(), fetchAndStoreRelease(), and @@ -131,7 +131,7 @@ returning the original value. This operation equates to the following code: - \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 3 + \snippet code/src_corelib_thread_qatomic.cpp 3 There are 4 fetch-and-add functions: fetchAndAddRelaxed(), fetchAndAddAcquire(), fetchAndAddRelease(), and @@ -215,41 +215,12 @@ Constructs a copy of \a other. */ -/*! \fn QAtomicInt &QAtomicInt::operator=(int value) - - Assigns the \a value to this QAtomicInt and returns a reference to - this QAtomicInt. -*/ - /*! \fn QAtomicInt &QAtomicInt::operator=(const QAtomicInt &other) Assigns \a other to this QAtomicInt and returns a reference to this QAtomicInt. */ -/*! \fn bool QAtomicInt::operator==(int value) const - - Returns true if the \a value is equal to the value in this - QAtomicInt; otherwise returns false. -*/ - -/*! \fn bool QAtomicInt::operator!=(int value) const - - Returns true if the value of this QAtomicInt is not equal to \a - value; otherwise returns false. -*/ - -/*! \fn bool QAtomicInt::operator!() const - - Returns true is the value of this QAtomicInt is zero; otherwise - returns false. -*/ - -/*! \fn QAtomicInt::operator int() const - - Returns the value stored by the QAtomicInt object as an integer. -*/ - /*! \fn bool QAtomicInt::isReferenceCountingNative() Returns true if reference counting is implemented using atomic @@ -679,7 +650,7 @@ these functions do nothing and return false. This operation equates to the following code: - \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 4 + \snippet code/src_corelib_thread_qatomic.cpp 4 There are 4 test-and-set functions: testAndSetRelaxed(), testAndSetAcquire(), testAndSetRelease(), and @@ -692,7 +663,7 @@ QAtomicPointer and then assign a new value, returning the original value. This operation equates to the following code: - \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 5 + \snippet code/src_corelib_thread_qatomic.cpp 5 There are 4 fetch-and-store functions: fetchAndStoreRelaxed(), fetchAndStoreAcquire(), fetchAndStoreRelease(), and @@ -706,7 +677,7 @@ returning the original value. This operation equates to the following code: - \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 6 + \snippet code/src_corelib_thread_qatomic.cpp 6 There are 4 fetch-and-add functions: fetchAndAddRelaxed(), fetchAndAddAcquire(), fetchAndAddRelease(), and @@ -783,46 +754,12 @@ Constructs a copy of \a other. */ -/*! \fn QAtomicPointer &QAtomicPointer::operator=(T *value) - - Assigns the \a value to this QAtomicPointer and returns a - reference to this QAtomicPointer. -*/ - /*! \fn QAtomicPointer &QAtomicPointer::operator=(const QAtomicPointer &other) Assigns \a other to this QAtomicPointer and returns a reference to this QAtomicPointer. */ -/*! \fn bool QAtomicPointer::operator==(T *value) const - - Returns true if the \a value is equal to the value in this - QAtomicPointer; otherwise returns false. -*/ - -/*! \fn bool QAtomicPointer::operator!=(T *value) const - - Returns true if the value of this QAtomicPointer is not equal to - \a value; otherwise returns false. -*/ - -/*! \fn bool QAtomicPointer::operator!() const - - Returns true is the current value of this QAtomicPointer is zero; - otherwise returns false. -*/ - -/*! \fn QAtomicPointer::operator T *() const - - Returns the current pointer value stored by this QAtomicPointer - object. -*/ - -/*! \fn T *QAtomicPointer::operator->() const - -*/ - /*! \fn bool QAtomicPointer::isTestAndSetNative() Returns true if test-and-set is implemented using atomic processor diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h index a8e321b46a..5cd9a6a5c4 100644 --- a/src/corelib/thread/qatomic.h +++ b/src/corelib/thread/qatomic.h @@ -165,7 +165,7 @@ public: This is a helper for the assignment operators of implicitly shared classes. Your assignment operator should look like this: - \snippet doc/src/snippets/code/src.corelib.thread.qatomic.h 0 + \snippet code/src.corelib.thread.qatomic.h 0 */ template inline void qAtomicAssign(T *&d, T *x) @@ -184,7 +184,7 @@ inline void qAtomicAssign(T *&d, T *x) the members and sets the refcount to 1. After that, your detach function should look like this: - \snippet doc/src/snippets/code/src.corelib.thread.qatomic.h 1 + \snippet code/src.corelib.thread.qatomic.h 1 */ template inline void qAtomicDetach(T *&d) diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 049230f7a4..145916d750 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE -/*! +/* \class QBasicMutex \brief QMutex POD \internal @@ -86,20 +86,20 @@ QT_BEGIN_NAMESPACE For example, say there is a method that prints a message to the user on two lines: - \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 0 + \snippet code/src_corelib_thread_qmutex.cpp 0 If these two methods are called in succession, the following happens: - \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 1 + \snippet code/src_corelib_thread_qmutex.cpp 1 If these two methods are called simultaneously from two threads then the following sequence could result: - \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 2 + \snippet code/src_corelib_thread_qmutex.cpp 2 If we add a mutex, we should get the result we want: - \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 3 + \snippet code/src_corelib_thread_qmutex.cpp 3 Then only one thread can modify \c number at any given time and the result is correct. This is a trivial example, of course, but @@ -178,26 +178,7 @@ QMutex::~QMutex() \sa unlock() */ -/*!\fn bool QMutex::trylock() - Attempts to lock the mutex. If the lock was obtained, this function - returns true. If another thread has locked the mutex, this - function returns false immediately. - - If the lock was obtained, the mutex must be unlocked with unlock() - before another thread can successfully lock it. - - Calling this function multiple times on the same mutex from the - same thread is allowed if this mutex is a - \l{QMutex::Recursive}{recursive mutex}. If this mutex is a - \l{QMutex::NonRecursive}{non-recursive mutex}, this function will - \e always return false when attempting to lock the mutex - recursively. - - \sa lock(), unlock() -*/ - /*! \fn bool QMutex::tryLock(int timeout) - \overload Attempts to lock the mutex. This function returns true if the lock was obtained; otherwise it returns false. If another thread has @@ -268,7 +249,7 @@ bool QBasicMutex::isRecursive() { For example, this complex function locks a QMutex upon entering the function and unlocks the mutex at all the exit points: - \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 4 + \snippet code/src_corelib_thread_qmutex.cpp 4 This example function will get more complicated as it is developed, which increases the likelihood that errors will occur. @@ -276,7 +257,7 @@ bool QBasicMutex::isRecursive() { Using QMutexLocker greatly simplifies the code, and makes it more readable: - \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 5 + \snippet code/src_corelib_thread_qmutex.cpp 5 Now, the mutex will always be unlocked when the QMutexLocker object is destroyed (when the function returns since \c locker is @@ -292,7 +273,7 @@ bool QBasicMutex::isRecursive() { for code that needs access to the mutex, such as QWaitCondition::wait(). For example: - \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 6 + \snippet code/src_corelib_thread_qmutex.cpp 6 \sa QReadLocker, QWriteLocker, QMutex */ @@ -316,13 +297,6 @@ bool QBasicMutex::isRecursive() { \sa QMutex::unlock() */ -/*! - \fn QMutex *QMutexLocker::mutex() const - - Returns a pointer to the mutex that was locked in the - constructor. -*/ - /*! \fn void QMutexLocker::unlock() diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index 9a81b3d4bd..0743c36457 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -158,7 +158,6 @@ private: #else // QT_NO_THREAD or qdoc - class Q_CORE_EXPORT QMutex { public: diff --git a/src/corelib/thread/qmutexpool.cpp b/src/corelib/thread/qmutexpool.cpp index 6b6674ccdf..4d24f8c7c7 100644 --- a/src/corelib/thread/qmutexpool.cpp +++ b/src/corelib/thread/qmutexpool.cpp @@ -66,7 +66,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (QMutex::Recursive)) For example, consider this simple class: - \snippet doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp 0 + \snippet code/src_corelib_thread_qmutexpool.cpp 0 Adding a QMutex member to the Number class does not make sense, because it is so small. However, in order to ensure that access to @@ -76,7 +76,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (QMutex::Recursive)) Code to calculate the square of a number would then look something like this: - \snippet doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp 1 + \snippet code/src_corelib_thread_qmutexpool.cpp 1 This function will safely calculate the square of a number, since it uses a mutex from a QMutexPool. The mutex is locked and diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index 519bae9fa6..1aba2f537e 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 0 + \snippet code/src_corelib_thread_qreadwritelock.cpp 0 To ensure that writers aren't blocked forever by readers, readers attempting to obtain a lock will not succeed if there is a blocked @@ -135,7 +135,7 @@ QReadWriteLock::~QReadWriteLock() thread if any thread (including the current) has locked for writing. - \sa unlock() lockForWrite() tryLockForRead() + \sa unlock(), lockForWrite(), tryLockForRead() */ void QReadWriteLock::lockForRead() { @@ -178,7 +178,7 @@ void QReadWriteLock::lockForRead() If the lock was obtained, the lock must be unlocked with unlock() before another thread can successfully lock it. - \sa unlock() lockForRead() + \sa unlock(), lockForRead() */ bool QReadWriteLock::tryLockForRead() { @@ -223,7 +223,7 @@ bool QReadWriteLock::tryLockForRead() If the lock was obtained, the lock must be unlocked with unlock() before another thread can successfully lock it. - \sa unlock() lockForRead() + \sa unlock(), lockForRead() */ bool QReadWriteLock::tryLockForRead(int timeout) { @@ -263,7 +263,7 @@ bool QReadWriteLock::tryLockForRead(int timeout) Locks the lock for writing. This function will block the current thread if another thread has locked for reading or writing. - \sa unlock() lockForRead() tryLockForWrite() + \sa unlock(), lockForRead(), tryLockForWrite() */ void QReadWriteLock::lockForWrite() { @@ -303,7 +303,7 @@ void QReadWriteLock::lockForWrite() If the lock was obtained, the lock must be unlocked with unlock() before another thread can successfully lock it. - \sa unlock() lockForWrite() + \sa unlock(), lockForWrite() */ bool QReadWriteLock::tryLockForWrite() { @@ -347,7 +347,7 @@ bool QReadWriteLock::tryLockForWrite() If the lock was obtained, the lock must be unlocked with unlock() before another thread can successfully lock it. - \sa unlock() lockForWrite() + \sa unlock(), lockForWrite() */ bool QReadWriteLock::tryLockForWrite(int timeout) { @@ -389,7 +389,7 @@ bool QReadWriteLock::tryLockForWrite(int timeout) Attempting to unlock a lock that is not locked is an error, and will result in program termination. - \sa lockForRead() lockForWrite() tryLockForRead() tryLockForWrite() + \sa lockForRead(), lockForWrite(), tryLockForRead(), tryLockForWrite() */ void QReadWriteLock::unlock() { @@ -443,11 +443,11 @@ void QReadWriteLock::unlock() Here's an example that uses QReadLocker to lock and unlock a read-write lock for reading: - \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 1 + \snippet code/src_corelib_thread_qreadwritelock.cpp 1 It is equivalent to the following code: - \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 2 + \snippet code/src_corelib_thread_qreadwritelock.cpp 2 The QMutexLocker documentation shows examples where the use of a locker object greatly simplifies programming. @@ -515,11 +515,11 @@ void QReadWriteLock::unlock() Here's an example that uses QWriteLocker to lock and unlock a read-write lock for writing: - \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 3 + \snippet code/src_corelib_thread_qreadwritelock.cpp 3 It is equivalent to the following code: - \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 4 + \snippet code/src_corelib_thread_qreadwritelock.cpp 4 The QMutexLocker documentation shows examples where the use of a locker object greatly simplifies programming. diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp index 08952eeaa3..e5b460b725 100644 --- a/src/corelib/thread/qsemaphore.cpp +++ b/src/corelib/thread/qsemaphore.cpp @@ -78,7 +78,7 @@ QT_BEGIN_NAMESPACE Example: - \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 0 + \snippet code/src_corelib_thread_qsemaphore.cpp 0 A typical application of semaphores is for controlling access to a circular buffer shared by a producer thread and a consumer @@ -151,7 +151,7 @@ void QSemaphore::acquire(int n) This function can be used to "create" resources as well. For example: - \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 1 + \snippet code/src_corelib_thread_qsemaphore.cpp 1 \sa acquire(), available() */ @@ -182,7 +182,7 @@ int QSemaphore::available() const Example: - \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 2 + \snippet code/src_corelib_thread_qsemaphore.cpp 2 \sa acquire() */ @@ -208,7 +208,7 @@ bool QSemaphore::tryAcquire(int n) Example: - \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 3 + \snippet code/src_corelib_thread_qsemaphore.cpp 3 \sa acquire() */ diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index ea6760a1b9..f93f383d3c 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -184,7 +184,7 @@ QThreadPrivate::~QThreadPrivate() below). To create your own threads, subclass QThread and reimplement run(). For example: - \snippet doc/src/snippets/code/src_corelib_thread_qthread.cpp 0 + \snippet code/src_corelib_thread_qthread.cpp 0 This will create a QTcpSocket in the thread and then execute the thread's event loop. Use the start() method to begin execution. @@ -493,7 +493,7 @@ int QThread::exec() is not running then the next call to QThread::exec() will also return immediately. - \sa quit() QEventLoop + \sa quit(), QEventLoop */ void QThread::exit(int returnCode) { @@ -515,7 +515,7 @@ void QThread::exit(int returnCode) This function does nothing if the thread does not have an event loop. - \sa exit() QEventLoop + \sa exit(), QEventLoop */ void QThread::quit() { exit(); } @@ -529,7 +529,7 @@ void QThread::quit() work. Returning from this method will end the execution of the thread. - \sa start() wait() + \sa start(), wait() */ void QThread::run() { @@ -553,7 +553,7 @@ void QThread::run() (such as on Linux, see http://linux.die.net/man/2/sched_setscheduler for more details). - \sa Priority priority() start() + \sa Priority, priority(), start() */ /*! @@ -562,7 +562,7 @@ void QThread::run() Returns the priority for a running thread. If the thread is not running, this function returns \c InheritPriority. - \sa Priority setPriority() start() + \sa Priority, setPriority(), start() */ QThread::Priority QThread::priority() const { diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 1cde07e330..433c561f1f 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -182,7 +182,7 @@ void qt_watch_adopted_thread(const HANDLE adoptedThreadHandle, QThread *qthread) } } -/*! \internal +/* This function loops and waits for native adopted threads to finish. When this happens it derefs the QThreadData for the adopted thread to make sure it gets cleaned up properly. diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index 7f26dfe326..c913146122 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -360,7 +360,7 @@ void QThreadPoolPrivate::stealRunnable(QRunnable *runnable) the run() virtual function. Then create an object of that class and pass it to QThreadPool::start(). - \snippet doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp 0 + \snippet code/src_corelib_concurrent_qthreadpool.cpp 0 QThreadPool deletes the QRunnable automatically by default. Use QRunnable::setAutoDelete() to change the auto-deletion flag. diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp index 68db8fe261..caa2ac907f 100644 --- a/src/corelib/thread/qthreadstorage.cpp +++ b/src/corelib/thread/qthreadstorage.cpp @@ -238,9 +238,9 @@ void QThreadStorageData::finish(void **p) removeFromCache() functions. The cache is automatically deleted when the calling thread exits. - \snippet doc/src/snippets/threads/threads.cpp 7 - \snippet doc/src/snippets/threads/threads.cpp 8 - \snippet doc/src/snippets/threads/threads.cpp 9 + \snippet threads/threads.cpp 7 + \snippet threads/threads.cpp 8 + \snippet threads/threads.cpp 9 \section1 Caveats diff --git a/src/corelib/thread/qwaitcondition.qdoc b/src/corelib/thread/qwaitcondition.qdoc index 81c095f394..58679c4543 100644 --- a/src/corelib/thread/qwaitcondition.qdoc +++ b/src/corelib/thread/qwaitcondition.qdoc @@ -45,7 +45,7 @@ split into a thread, each of which would have a \l{QThread::run()}{run()} body like this: - \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 0 + \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 0 Here, the \c keyPressed variable is a global variable of type QWaitCondition. @@ -53,7 +53,7 @@ A fourth thread would read key presses and wake the other three threads up every time it receives one, like this: - \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 1 + \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 1 The order in which the three threads are woken up is undefined. Also, if some of the threads are still in \c do_something() when @@ -63,11 +63,11 @@ counter and a QMutex to guard it. For example, here's the new code for the worker threads: - \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 2 + \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 2 Here's the code for the fourth thread: - \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 3 + \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 3 The mutex is necessary because the results of two threads attempting to change the value of the same variable diff --git a/src/corelib/tools/qalgorithms.qdoc b/src/corelib/tools/qalgorithms.qdoc index 5a4a278ad0..28fd9881d6 100644 --- a/src/corelib/tools/qalgorithms.qdoc +++ b/src/corelib/tools/qalgorithms.qdoc @@ -60,14 +60,14 @@ a particular value. If you need that functionality, you can use qFill(): - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 0 + \snippet code/doc_src_qalgorithms.cpp 0 qFill() takes a begin iterator, an end iterator, and a value. In the example above, we pass \c list.begin() and \c list.end() as the begin and end iterators, but this doesn't have to be the case: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 1 + \snippet code/doc_src_qalgorithms.cpp 1 Different algorithms can have different requirements for the iterators they accept. For example, qFill() accepts two @@ -98,13 +98,13 @@ name_table array and return the corresponding Unicode value from the \c value_table if the entity is recognized: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 2 + \snippet code/doc_src_qalgorithms.cpp 2 This kind of code is for advanced users only; for most applications, a QMap- or QHash-based approach would work just as well: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 3 + \snippet code/doc_src_qalgorithms.cpp 3 \section1 Types of Iterators @@ -185,7 +185,7 @@ position \a begin2 + 1; and so on. Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 4 + \snippet code/doc_src_qalgorithms.cpp 4 \sa qCopyBackward(), {input iterators}, {output iterators} */ @@ -201,7 +201,7 @@ at position \a end2 - 2; and so on. Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 5 + \snippet code/doc_src_qalgorithms.cpp 5 \sa qCopy(), {bidirectional iterators} */ @@ -214,7 +214,7 @@ items compare equal; otherwise returns false. Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 6 + \snippet code/doc_src_qalgorithms.cpp 6 This function requires the item type (in the example above, QString) to implement \c operator==(). @@ -228,7 +228,7 @@ Fills the range [\a begin, \a end) with \a value. Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 7 + \snippet code/doc_src_qalgorithms.cpp 7 \sa qCopy(), {forward iterators} */ @@ -249,7 +249,7 @@ value isn't found. Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 8 + \snippet code/doc_src_qalgorithms.cpp 8 This function requires the item type (in the example above, QString) to implement \c operator==(). @@ -278,7 +278,7 @@ Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 9 + \snippet code/doc_src_qalgorithms.cpp 9 This function requires the item type (in the example above, \c int) to implement \c operator==(). @@ -302,7 +302,7 @@ of \a value in the variable passed as a reference in argument \a n. Exchanges the values of variables \a var1 and \a var2. Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 10 + \snippet code/doc_src_qalgorithms.cpp 10 */ /*! \fn void qSort(RandomAccessIterator begin, RandomAccessIterator end) @@ -312,7 +312,7 @@ of \a value in the variable passed as a reference in argument \a n. using the quicksort algorithm. Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 11 + \snippet code/doc_src_qalgorithms.cpp 11 The sort algorithm is efficient on large data sets. It operates in \l {linear-logarithmic time}, O(\e{n} log \e{n}). @@ -338,13 +338,13 @@ of \a value in the variable passed as a reference in argument \a n. For example, here's how to sort the strings in a QStringList in case-insensitive alphabetical order: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 12 + \snippet code/doc_src_qalgorithms.cpp 12 To sort values in reverse order, pass \l{qGreater()}{qGreater()} as the \a lessThan parameter. For example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 13 + \snippet code/doc_src_qalgorithms.cpp 13 If neither of the two items is "less than" the other, the items are taken to be equal. It is then undefined which one of the two @@ -356,7 +356,7 @@ of \a value in the variable passed as a reference in argument \a n. following code shows how to sort a list of strings case insensitively using QMap: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 14 + \snippet code/doc_src_qalgorithms.cpp 14 \sa QMap */ @@ -382,7 +382,7 @@ of \a value in the variable passed as a reference in argument \a n. property is often useful when sorting user-visible data. Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 15 + \snippet code/doc_src_qalgorithms.cpp 15 The sort algorithm is efficient on large data sets. It operates in \l {linear-logarithmic time}, O(\e{n} log \e{n}). @@ -405,7 +405,7 @@ of \a value in the variable passed as a reference in argument \a n. For example, here's how to sort the strings in a QStringList in case-insensitive alphabetical order: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 16 + \snippet code/doc_src_qalgorithms.cpp 16 Note that earlier versions of Qt allowed using a lessThan function that took its arguments by non-const reference. From 4.3 and on this is no longer possible, @@ -415,7 +415,7 @@ of \a value in the variable passed as a reference in argument \a n. \l{qGreater()}{qGreater()} as the \a lessThan parameter. For example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 17 + \snippet code/doc_src_qalgorithms.cpp 17 If neither of the two items is "less than" the other, the items are taken to be equal. The item that appeared before the other in the @@ -444,7 +444,7 @@ of \a value in the variable passed as a reference in argument \a n. ascending order; see qSort(). Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 18 + \snippet code/doc_src_qalgorithms.cpp 18 This function requires the item type (in the example above, \c{int}) to implement \c operator<(). @@ -452,7 +452,7 @@ of \a value in the variable passed as a reference in argument \a n. qLowerBound() can be used in conjunction with qUpperBound() to iterate over all occurrences of the same value: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 19 + \snippet code/doc_src_qalgorithms.cpp 19 \sa qUpperBound(), qBinaryFind() */ @@ -494,7 +494,7 @@ of \a value in the variable passed as a reference in argument \a n. ascending order; see qSort(). Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 20 + \snippet code/doc_src_qalgorithms.cpp 20 This function requires the item type (in the example above, \c{int}) to implement \c operator<(). @@ -502,7 +502,7 @@ of \a value in the variable passed as a reference in argument \a n. qUpperBound() can be used in conjunction with qLowerBound() to iterate over all occurrences of the same value: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 21 + \snippet code/doc_src_qalgorithms.cpp 21 \sa qLowerBound(), qBinaryFind() */ @@ -545,7 +545,7 @@ of \a value in the variable passed as a reference in argument \a n. finer control. Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 22 + \snippet code/doc_src_qalgorithms.cpp 22 This function requires the item type (in the example above, QString) to implement \c operator<(). @@ -587,7 +587,7 @@ of \a value in the variable passed as a reference in argument \a n. example, \c{QWidget *}). Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 23 + \snippet code/doc_src_qalgorithms.cpp 23 Notice that qDeleteAll() doesn't remove the items from the container; it merely calls \c delete on them. In the example @@ -618,7 +618,7 @@ of \a value in the variable passed as a reference in argument \a n. Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 24 + \snippet code/doc_src_qalgorithms.cpp 24 \sa {qGreater()}{qGreater()} */ @@ -631,7 +631,7 @@ of \a value in the variable passed as a reference in argument \a n. Example: - \snippet doc/src/snippets/code/doc_src_qalgorithms.cpp 25 + \snippet code/doc_src_qalgorithms.cpp 25 \sa {qLess()}{qLess()} */ diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp index 4cb08a7310..0e74e15a27 100644 --- a/src/corelib/tools/qbitarray.cpp +++ b/src/corelib/tools/qbitarray.cpp @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE The following code constructs a QBitArray containing 200 bits initialized to false (0): - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 0 + \snippet code/src_corelib_tools_qbitarray.cpp 0 To initialize the bits to true, either pass \c true as second argument to the constructor, or call fill() later on. @@ -75,13 +75,13 @@ QT_BEGIN_NAMESPACE bit that can be used on the left side of an assignment. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 1 + \snippet code/src_corelib_tools_qbitarray.cpp 1 For technical reasons, it is more efficient to use testBit() and setBit() to access bits in the array than operator[](). For example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 2 + \snippet code/src_corelib_tools_qbitarray.cpp 2 QBitArray supports \c{&} (\link operator&() AND\endlink), \c{|} (\link operator|() OR\endlink), \c{^} (\link operator^() @@ -90,7 +90,7 @@ QT_BEGIN_NAMESPACE as the built-in C++ bitwise operators of the same name. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 3 + \snippet code/src_corelib_tools_qbitarray.cpp 3 For historical reasons, QBitArray distinguishes between a null bit array and an empty bit array. A \e null bit array is a bit @@ -99,7 +99,7 @@ QT_BEGIN_NAMESPACE array is always empty, but an empty bit array isn't necessarily null: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 4 + \snippet code/src_corelib_tools_qbitarray.cpp 4 All functions except isNull() treat null bit arrays the same as empty bit arrays; for example, QBitArray() compares equal to @@ -228,7 +228,7 @@ void QBitArray::resize(int size) Returns true if this bit array is null; otherwise returns false. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 5 + \snippet code/src_corelib_tools_qbitarray.cpp 5 Qt makes a distinction between null bit arrays and empty bit arrays for historical reasons. For most applications, what @@ -245,7 +245,7 @@ void QBitArray::resize(int size) the bit array is resized to \a size beforehand. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 6 + \snippet code/src_corelib_tools_qbitarray.cpp 6 \sa resize() */ @@ -372,7 +372,7 @@ void QBitArray::fill(bool value, int begin, int end) \a i < size()). Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 7 + \snippet code/src_corelib_tools_qbitarray.cpp 7 The return value is of type QBitRef, a helper class for QBitArray. When you get an object of type QBitRef, you can assign to @@ -451,7 +451,7 @@ void QBitArray::fill(bool value, int begin, int end) taken to be 0. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 8 + \snippet code/src_corelib_tools_qbitarray.cpp 8 \sa operator&(), operator|=(), operator^=(), operator~() */ @@ -480,7 +480,7 @@ QBitArray &QBitArray::operator&=(const QBitArray &other) taken to be 0. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 9 + \snippet code/src_corelib_tools_qbitarray.cpp 9 \sa operator|(), operator&=(), operator^=(), operator~() */ @@ -506,7 +506,7 @@ QBitArray &QBitArray::operator|=(const QBitArray &other) taken to be 0. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 10 + \snippet code/src_corelib_tools_qbitarray.cpp 10 \sa operator^(), operator&=(), operator|=(), operator~() */ @@ -527,7 +527,7 @@ QBitArray &QBitArray::operator^=(const QBitArray &other) array. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 11 + \snippet code/src_corelib_tools_qbitarray.cpp 11 \sa operator&(), operator|(), operator^() */ @@ -559,7 +559,7 @@ QBitArray QBitArray::operator~() const taken to be 0. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 12 + \snippet code/src_corelib_tools_qbitarray.cpp 12 \sa QBitArray::operator&=(), operator|(), operator^() */ @@ -582,7 +582,7 @@ QBitArray operator&(const QBitArray &a1, const QBitArray &a2) taken to be 0. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 13 + \snippet code/src_corelib_tools_qbitarray.cpp 13 \sa QBitArray::operator|=(), operator&(), operator^() */ @@ -605,7 +605,7 @@ QBitArray operator|(const QBitArray &a1, const QBitArray &a2) taken to be 0. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbitarray.cpp 14 + \snippet code/src_corelib_tools_qbitarray.cpp 14 \sa QBitArray::operator^=(), operator&(), operator|() */ @@ -668,7 +668,7 @@ QBitArray operator^(const QBitArray &a1, const QBitArray &a2) Writes bit array \a ba to stream \a out. - \sa \link datastreamformat.html Format of the QDataStream operators \endlink + \sa {Serializing Qt Data Types}{Format of the QDataStream operators} */ QDataStream &operator<<(QDataStream &out, const QBitArray &ba) @@ -685,7 +685,7 @@ QDataStream &operator<<(QDataStream &out, const QBitArray &ba) Reads a bit array into \a ba from stream \a in. - \sa \link datastreamformat.html Format of the QDataStream operators \endlink + \sa {Serializing Qt Data Types}{Format of the QDataStream operators} */ QDataStream &operator>>(QDataStream &in, QBitArray &ba) diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 31cf65b78d..42150efd63 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -648,7 +648,7 @@ static inline char qToLower(char c) char *} to its constructor. For example, the following code creates a byte array of size 5 containing the data "Hello": - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 0 + \snippet code/src_corelib_tools_qbytearray.cpp 0 Although the size() is 5, the byte array also maintains an extra '\\0' character at the end so that if a function is used that @@ -668,11 +668,11 @@ static inline char qToLower(char c) arrays, operator[]() returns a reference to a byte that can be used on the left side of an assignment. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 1 + \snippet code/src_corelib_tools_qbytearray.cpp 1 For read-only access, an alternative syntax is to use at(): - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 2 + \snippet code/src_corelib_tools_qbytearray.cpp 2 at() can be faster than operator[](), because it never causes a \l{deep copy} to occur. @@ -700,7 +700,7 @@ static inline char qToLower(char c) the byte data: append(), prepend(), insert(), replace(), and remove(). For example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 3 + \snippet code/src_corelib_tools_qbytearray.cpp 3 The replace() and remove() functions' first two arguments are the position from which to start erasing and the number of bytes that @@ -728,7 +728,7 @@ static inline char qToLower(char c) For example, here's a typical loop that finds all occurrences of a particular substring: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 4 + \snippet code/src_corelib_tools_qbytearray.cpp 4 If you simply want to check whether a QByteArray contains a particular character or substring, use contains(). If you want to @@ -752,7 +752,7 @@ static inline char qToLower(char c) array is always empty, but an empty byte array isn't necessarily null: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 5 + \snippet code/src_corelib_tools_qbytearray.cpp 5 All functions except isNull() treat null byte arrays the same as empty byte arrays. For example, data() returns a pointer to a @@ -949,7 +949,7 @@ QByteArray &QByteArray::operator=(const char *str) automaticall unless the \l{deep copy} is created. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 6 + \snippet code/src_corelib_tools_qbytearray.cpp 6 \sa isEmpty(), resize() */ @@ -959,7 +959,7 @@ QByteArray &QByteArray::operator=(const char *str) Returns true if the byte array has size 0; otherwise returns false. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 7 + \snippet code/src_corelib_tools_qbytearray.cpp 7 \sa size() */ @@ -1046,7 +1046,7 @@ QByteArray &QByteArray::operator=(const char *str) '\\0' terminator. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 8 + \snippet code/src_corelib_tools_qbytearray.cpp 8 The pointer remains valid as long as the byte array isn't reallocated or destroyed. For read-only access, constData() is @@ -1059,11 +1059,11 @@ QByteArray &QByteArray::operator=(const char *str) data(), but it will corrupt the heap and cause a crash because it does not allocate a byte for the '\\0' at the end: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 46 + \snippet code/src_corelib_tools_qbytearray.cpp 46 This one allocates the correct amount of space: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 47 + \snippet code/src_corelib_tools_qbytearray.cpp 47 Note: A QByteArray can store any byte values including '\\0's, but most functions that take \c{char *} arguments assume that the @@ -1129,7 +1129,7 @@ QByteArray &QByteArray::operator=(const char *str) place. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 9 + \snippet code/src_corelib_tools_qbytearray.cpp 9 The return value is of type QByteRef, a helper class for QByteArray. When you get an object of type QByteRef, you can use @@ -1188,7 +1188,7 @@ QByteArray &QByteArray::operator=(const char *str) If \a pos is beyond the end of the array, nothing happens. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 10 + \snippet code/src_corelib_tools_qbytearray.cpp 10 \sa chop(), resize(), left() */ @@ -1206,7 +1206,7 @@ void QByteArray::truncate(int pos) array. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 11 + \snippet code/src_corelib_tools_qbytearray.cpp 11 \sa truncate(), resize(), left() */ @@ -1224,7 +1224,7 @@ void QByteArray::chop(int n) returns a reference to this byte array. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 12 + \snippet code/src_corelib_tools_qbytearray.cpp 12 Note: QByteArray is an \l{implicitly shared} class. Consequently, if \e this is an empty QByteArray, then \e this will just share @@ -1284,7 +1284,7 @@ void QByteArray::chop(int n) Returns true if this byte array is null; otherwise returns false. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 13 + \snippet code/src_corelib_tools_qbytearray.cpp 13 Qt makes a distinction between null byte arrays and empty byte arrays for historical reasons. For most applications, what @@ -1428,7 +1428,7 @@ void QByteArray::resize(int size) size \a size beforehand. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 14 + \snippet code/src_corelib_tools_qbytearray.cpp 14 \sa resize() */ @@ -1493,7 +1493,7 @@ QByteArray QByteArray::nulTerminated() const reference to this byte array. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 15 + \snippet code/src_corelib_tools_qbytearray.cpp 15 This is the same as insert(0, \a ba). @@ -1573,7 +1573,7 @@ QByteArray &QByteArray::prepend(char ch) Appends the byte array \a ba onto the end of this byte array. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 16 + \snippet code/src_corelib_tools_qbytearray.cpp 16 This is the same as insert(size(), \a ba). @@ -1710,7 +1710,7 @@ static inline QByteArray &qbytearray_insert(QByteArray *ba, reference to this byte array. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 17 + \snippet code/src_corelib_tools_qbytearray.cpp 17 \sa append(), prepend(), replace(), remove() */ @@ -1793,7 +1793,7 @@ QByteArray &QByteArray::insert(int i, char ch) array is truncated at position \a pos. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 18 + \snippet code/src_corelib_tools_qbytearray.cpp 18 \sa insert(), replace() */ @@ -1817,7 +1817,7 @@ QByteArray &QByteArray::remove(int pos, int len) array \a after, and returns a reference to this byte array. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 19 + \snippet code/src_corelib_tools_qbytearray.cpp 19 \sa insert(), remove() */ @@ -1855,7 +1855,7 @@ QByteArray &QByteArray::replace(int pos, int len, const char *after) \overload Replaces \a len bytes from index position \a pos with \a alen bytes - from the string \a after. \a after is allowed to have '\0' characters. + from the string \a after. \a after is allowed to have '\\0' characters. \since 4.7 */ @@ -1881,7 +1881,7 @@ QByteArray &QByteArray::replace(int pos, int len, const char *after, int alen) byte array \a after. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 20 + \snippet code/src_corelib_tools_qbytearray.cpp 20 */ QByteArray &QByteArray::replace(const QByteArray &before, const QByteArray &after) @@ -2214,7 +2214,7 @@ QByteArray QByteArray::repeated(int times) const position \a from. Returns -1 if \a ba could not be found. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 21 + \snippet code/src_corelib_tools_qbytearray.cpp 21 \sa lastIndexOf(), contains(), count() */ @@ -2284,7 +2284,7 @@ int QByteArray::indexOf(const char *c, int from) const position \a from. Returns -1 if \a ch could not be found. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 22 + \snippet code/src_corelib_tools_qbytearray.cpp 22 \sa lastIndexOf(), contains() */ @@ -2346,7 +2346,7 @@ static int lastIndexOfHelper(const char *haystack, int l, const char *needle, in starts at the last byte. Returns -1 if \a ba could not be found. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 23 + \snippet code/src_corelib_tools_qbytearray.cpp 23 \sa indexOf(), contains(), count() */ @@ -2406,7 +2406,7 @@ int QByteArray::lastIndexOf(const char *str, int from) const last (size() - 1) byte. Returns -1 if \a ch could not be found. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 24 + \snippet code/src_corelib_tools_qbytearray.cpp 24 \sa indexOf(), contains() */ @@ -2493,7 +2493,7 @@ int QByteArray::count(char ch) const otherwise returns false. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 25 + \snippet code/src_corelib_tools_qbytearray.cpp 25 \sa endsWith(), left() */ @@ -2538,7 +2538,7 @@ bool QByteArray::startsWith(char ch) const otherwise returns false. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 26 + \snippet code/src_corelib_tools_qbytearray.cpp 26 \sa startsWith(), right() */ @@ -2586,7 +2586,7 @@ bool QByteArray::endsWith(char ch) const size(). Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 27 + \snippet code/src_corelib_tools_qbytearray.cpp 27 \sa right(), mid(), startsWith(), truncate() */ @@ -2608,7 +2608,7 @@ QByteArray QByteArray::left(int len) const size(). Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 28 + \snippet code/src_corelib_tools_qbytearray.cpp 28 \sa endsWith(), left(), mid() */ @@ -2631,7 +2631,7 @@ QByteArray QByteArray::right(int len) const pos until the end of the byte array. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 29 + \snippet code/src_corelib_tools_qbytearray.cpp 29 \sa left(), right() */ @@ -2658,7 +2658,7 @@ QByteArray QByteArray::mid(int pos, int len) const interpreted as a Latin-1 encoded string. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 30 + \snippet code/src_corelib_tools_qbytearray.cpp 30 \sa toUpper(), {8-bit Character Comparisons} */ @@ -2680,7 +2680,7 @@ QByteArray QByteArray::toLower() const interpreted as a Latin-1 encoded string. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 31 + \snippet code/src_corelib_tools_qbytearray.cpp 31 \sa toLower(), {8-bit Character Comparisons} */ @@ -3090,7 +3090,7 @@ QDataStream &operator>>(QDataStream &in, QByteArray &ba) characters '\\t', '\\n', '\\v', '\\f', '\\r', and ' '. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 32 + \snippet code/src_corelib_tools_qbytearray.cpp 32 \sa trimmed() */ @@ -3128,7 +3128,7 @@ QByteArray QByteArray::simplified() const characters '\\t', '\\n', '\\v', '\\f', '\\r', and ' '. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 33 + \snippet code/src_corelib_tools_qbytearray.cpp 33 Unlike simplified(), trimmed() leaves internal whitespace alone. @@ -3170,7 +3170,7 @@ QByteArray QByteArray::trimmed() const after position \a width are removed, and the copy is returned. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 34 + \snippet code/src_corelib_tools_qbytearray.cpp 34 \sa rightJustified() */ @@ -3207,7 +3207,7 @@ QByteArray QByteArray::leftJustified(int width, char fill, bool truncate) const position \a width. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 35 + \snippet code/src_corelib_tools_qbytearray.cpp 35 \sa leftJustified() */ @@ -3314,7 +3314,7 @@ qulonglong QByteArray::toULongLong(bool *ok, int base) const If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to false; otherwise *\a{ok} is set to true. - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 36 + \snippet code/src_corelib_tools_qbytearray.cpp 36 \note The conversion of the number is performed in the default C locale, irrespective of the user's locale. @@ -3380,7 +3380,7 @@ uint QByteArray::toUInt(bool *ok, int base) const If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to false; otherwise *\a{ok} is set to true. - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 37 + \snippet code/src_corelib_tools_qbytearray.cpp 37 \note The conversion of the number is performed in the default C locale, irrespective of the user's locale. @@ -3501,7 +3501,7 @@ ushort QByteArray::toUShort(bool *ok, int base) const If \a ok is not 0: if a conversion error occurs, *\a{ok} is set to false; otherwise *\a{ok} is set to true. - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 38 + \snippet code/src_corelib_tools_qbytearray.cpp 38 \note The conversion of the number is performed in the default C locale, irrespective of the user's locale. @@ -3536,7 +3536,7 @@ float QByteArray::toFloat(bool *ok) const /*! Returns a copy of the byte array, encoded as Base64. - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 39 + \snippet code/src_corelib_tools_qbytearray.cpp 39 The algorithm used to encode Base64-encoded data is defined in \l{RFC 2045}. @@ -3588,7 +3588,7 @@ QByteArray QByteArray::toBase64() const be any value between 2 and 36. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 40 + \snippet code/src_corelib_tools_qbytearray.cpp 40 \note The format of the number is not localized; the default C locale is used irrespective of the user's locale. @@ -3734,7 +3734,7 @@ QByteArray &QByteArray::setNum(double n, char f, int prec) any value between 2 and 36. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 41 + \snippet code/src_corelib_tools_qbytearray.cpp 41 \note The format of the number is not localized; the default C locale is used irrespective of the user's locale. @@ -3806,7 +3806,7 @@ QByteArray QByteArray::number(qulonglong n, int base) decimal point. With 'g' and 'G', \a prec is the maximum number of significant digits (trailing zeroes are omitted). - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 42 + \snippet code/src_corelib_tools_qbytearray.cpp 42 \note The format of the number is not localized; the default C locale is used irrespective of the user's locale. @@ -3843,7 +3843,7 @@ QByteArray QByteArray::number(double n, char f, int prec) Here is an example of how to read data using a QDataStream on raw data in memory without copying the raw data into a QByteArray: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 43 + \snippet code/src_corelib_tools_qbytearray.cpp 43 \warning A byte array created with fromRawData() is \e not null-terminated, unless the raw data contains a 0 character at @@ -3908,7 +3908,7 @@ QByteArray &QByteArray::setRawData(const char *data, uint size) For example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 44 + \snippet code/src_corelib_tools_qbytearray.cpp 44 The algorithm used to decode Base64-encoded data is defined in \l{RFC 2045}. @@ -3960,7 +3960,7 @@ QByteArray QByteArray::fromBase64(const QByteArray &base64) For example: - \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 45 + \snippet code/src_corelib_tools_qbytearray.cpp 45 \sa toHex() */ diff --git a/src/corelib/tools/qcache.qdoc b/src/corelib/tools/qcache.qdoc index 80d47ff703..86eec28e4b 100644 --- a/src/corelib/tools/qcache.qdoc +++ b/src/corelib/tools/qcache.qdoc @@ -39,11 +39,11 @@ definition of a cache that stores objects of type Employee associated with an integer key: - \snippet doc/src/snippets/code/doc_src_qcache.cpp 0 + \snippet code/doc_src_qcache.cpp 0 Here's how to insert an object in the cache: - \snippet doc/src/snippets/code/doc_src_qcache.cpp 1 + \snippet code/doc_src_qcache.cpp 1 The advantage of using QCache over some other key-based data structure (such as QMap or QHash) is that QCache automatically @@ -59,7 +59,7 @@ By default, QCache's maxCost() is 100. You can specify a different value in the QCache constructor: - \snippet doc/src/snippets/code/doc_src_qcache.cpp 2 + \snippet code/doc_src_qcache.cpp 2 Each time you call insert(), you can specify a cost as third argument (after the key and a pointer to the object to insert). diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index fa5eed4f86..630deccadd 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -824,7 +824,7 @@ QString QDate::toString(Qt::DateFormat f) const range 0 to 9999. This restriction may apply to locale-aware formats as well, depending on the locale settings. - \sa QDateTime::toString() QTime::toString() + \sa QDateTime::toString(), QTime::toString() */ QString QDate::toString(const QString& format) const @@ -836,7 +836,7 @@ QString QDate::toString(const QString& format) const #endif //QT_NO_DATESTRING /*! - \fn bool setYMD(int y, int m, int d) + \fn bool QDate::setYMD(int y, int m, int d) \deprecated in 5.0, use setDate() instead. @@ -906,7 +906,7 @@ void QDate::getDate(int *year, int *month, int *day) Returns a null date if the current date is invalid or the new date is out-of-range. - \sa addMonths() addYears() daysTo() + \sa addMonths(), addYears(), daysTo() */ QDate QDate::addDays(qint64 ndays) const @@ -938,7 +938,7 @@ QDate QDate::addDays(qint64 ndays) const resulting month/year, this function will return a date that is the latest valid date. - \sa addDays() addYears() + \sa addDays(), addYears() */ QDate QDate::addMonths(int nmonths) const @@ -1029,7 +1029,7 @@ QDate QDate::addYears(int nyears) const Returns 0 if either date is invalid. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 0 + \snippet code/src_corelib_tools_qdatetime.cpp 0 \sa addDays() */ @@ -1217,7 +1217,7 @@ QDate QDate::fromString(const QString& s, Qt::DateFormat f) of characters that are enclosed in single quotes will also be treated as text and will not be used as an expression. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 1 + \snippet code/src_corelib_tools_qdatetime.cpp 1 If the format is not satisfied, an invalid QDate is returned. The expressions that don't expect leading zeroes (d, M) will be @@ -1227,7 +1227,7 @@ QDate QDate::fromString(const QString& s, Qt::DateFormat f) string could have meant January 30 but the M will grab two digits, resulting in an invalid date: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 2 + \snippet code/src_corelib_tools_qdatetime.cpp 2 For any field that is not represented in the format the following defaults are used: @@ -1241,7 +1241,7 @@ QDate QDate::fromString(const QString& s, Qt::DateFormat f) The following examples demonstrate the default values: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 3 + \snippet code/src_corelib_tools_qdatetime.cpp 3 \sa QDateTime::fromString(), QTime::fromString(), QDate::toString(), QDateTime::toString(), QTime::toString() @@ -1269,7 +1269,7 @@ QDate QDate::fromString(const QString &string, const QString &format) day) is valid; otherwise returns false. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 4 + \snippet code/src_corelib_tools_qdatetime.cpp 4 \sa isNull(), setDate() */ @@ -1300,7 +1300,7 @@ bool QDate::isLeapYear(int y) return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0; } -/*! \fn static QDate QDate::fromJulianDay(int jd) +/*! \fn static QDate QDate::fromJulianDay(qint64 jd) Converts the Julian day \a jd to a QDate. @@ -1582,7 +1582,7 @@ QString QTime::toString(Qt::DateFormat format) const If the datetime is invalid, an empty string will be returned. If \a format is empty, the default format "hh:mm:ss" is used. - \sa QDate::toString() QDateTime::toString() + \sa QDate::toString(), QDateTime::toString() */ QString QTime::toString(const QString& format) const { @@ -1623,7 +1623,7 @@ bool QTime::setHMS(int h, int m, int s, int ms) Example: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 5 + \snippet code/src_corelib_tools_qdatetime.cpp 5 \sa addMSecs(), secsTo(), QDateTime::addSecs() */ @@ -1845,7 +1845,7 @@ QTime QTime::fromString(const QString& s, Qt::DateFormat f) of characters that are enclosed in single quotes will also be treated as text and not be used as an expression. - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 6 + \snippet code/src_corelib_tools_qdatetime.cpp 6 If the format is not satisfied an invalid QTime is returned. Expressions that do not expect leading zeroes to be given (h, m, s @@ -1855,15 +1855,15 @@ QTime QTime::fromString(const QString& s, Qt::DateFormat f) could have meant 00:07:10, but the m will grab two digits, resulting in an invalid time: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 7 + \snippet code/src_corelib_tools_qdatetime.cpp 7 Any field that is not represented in the format will be set to zero. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 8 + \snippet code/src_corelib_tools_qdatetime.cpp 8 - \sa QDateTime::fromString() QDate::fromString() QDate::toString() - QDateTime::toString() QTime::toString() + \sa QDateTime::fromString(), QDate::fromString(), QDate::toString(), + QDateTime::toString(), QTime::toString() */ QTime QTime::fromString(const QString &string, const QString &format) @@ -1894,7 +1894,7 @@ QTime QTime::fromString(const QString &string, const QString &format) Example: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 9 + \snippet code/src_corelib_tools_qdatetime.cpp 9 */ bool QTime::isValid(int h, int m, int s, int ms) @@ -1906,7 +1906,7 @@ bool QTime::isValid(int h, int m, int s, int ms) /*! Sets this time to the current time. This is practical for timing: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 10 + \snippet code/src_corelib_tools_qdatetime.cpp 10 \sa restart(), elapsed(), currentTime() */ @@ -2077,7 +2077,7 @@ int QTime::elapsed() const time zone before 1970, even if the system's time zone database supports that information. - \sa QDate QTime QDateTimeEdit + \sa QDate, QTime, QDateTimeEdit */ /*! @@ -2432,7 +2432,7 @@ void QDateTime::setTime_t(uint secsSince1Jan1970UTC) range 0 to 9999. This restriction may apply to locale-aware formats as well, depending on the locale settings. - \sa QDate::toString() QTime::toString() Qt::DateFormat + \sa QDate::toString(), QTime::toString(), Qt::DateFormat */ QString QDateTime::toString(Qt::DateFormat f) const @@ -2574,7 +2574,7 @@ QString QDateTime::toString(Qt::DateFormat f) const If the datetime is invalid, an empty string will be returned. - \sa QDate::toString() QTime::toString() + \sa QDate::toString(), QTime::toString() */ QString QDateTime::toString(const QString& format) const { @@ -2718,7 +2718,7 @@ qint64 QDateTime::daysTo(const QDateTime &other) const Returns 0 if either time is invalid. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 11 + \snippet code/src_corelib_tools_qdatetime.cpp 11 \sa addSecs(), daysTo(), QTime::secsTo() */ @@ -3420,7 +3420,7 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f) of characters that are enclosed in singlequotes will also be treated as text and not be used as an expression. - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 12 + \snippet code/src_corelib_tools_qdatetime.cpp 12 If the format is not satisfied an invalid QDateTime is returned. The expressions that don't have leading zeroes (d, M, h, m, s, z) will be @@ -3428,7 +3428,7 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f) put them outside the range and/or leave too few digits for other sections. - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 13 + \snippet code/src_corelib_tools_qdatetime.cpp 13 This could have meant 1 January 00:30.00 but the M will grab two digits. @@ -3448,10 +3448,10 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f) For example: - \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 14 + \snippet code/src_corelib_tools_qdatetime.cpp 14 - \sa QDate::fromString() QTime::fromString() QDate::toString() - QDateTime::toString() QTime::toString() + \sa QDate::fromString(), QTime::fromString(), QDate::toString(), + QDateTime::toString(), QTime::toString() */ QDateTime QDateTime::fromString(const QString &string, const QString &format) diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index 1d6514eb3d..e237b81cfa 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -55,7 +55,7 @@ \class QEasingCurve \since 4.6 \ingroup animation - \brief The QEasingCurve class provides easing curves for controlling animation. + \captionief The QEasingCurve class provides easing curves for controlling animation. Easing curves describe a function that controls how the speed of the interpolation between 0 and 1 should be. Easing curves allow transitions from @@ -112,183 +112,173 @@ The type of easing curve. - \value Linear \inlineimage qeasingcurve-linear.png - \br - Easing curve for a linear (t) function: + \value Linear \image qeasingcurve-linear.png + \caption Easing curve for a linear (t) function: velocity is constant. - \value InQuad \inlineimage qeasingcurve-inquad.png - \br - Easing curve for a quadratic (t^2) function: + \value InQuad \image qeasingcurve-inquad.png + \caption Easing curve for a quadratic (t^2) function: accelerating from zero velocity. - \value OutQuad \inlineimage qeasingcurve-outquad.png - \br - Easing curve for a quadratic (t^2) function: + \value OutQuad \image qeasingcurve-outquad.png + \caption Easing curve for a quadratic (t^2) function: decelerating to zero velocity. - \value InOutQuad \inlineimage qeasingcurve-inoutquad.png - \br - Easing curve for a quadratic (t^2) function: + \value InOutQuad \image qeasingcurve-inoutquad.png + \caption Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration. - \value OutInQuad \inlineimage qeasingcurve-outinquad.png - \br - Easing curve for a quadratic (t^2) function: + \value OutInQuad \image qeasingcurve-outinquad.png + \caption Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration. - \value InCubic \inlineimage qeasingcurve-incubic.png - \br - Easing curve for a cubic (t^3) function: + \value InCubic \image qeasingcurve-incubic.png + \caption Easing curve for a cubic (t^3) function: accelerating from zero velocity. - \value OutCubic \inlineimage qeasingcurve-outcubic.png - \br - Easing curve for a cubic (t^3) function: + \value OutCubic \image qeasingcurve-outcubic.png + \caption Easing curve for a cubic (t^3) function: decelerating to zero velocity. - \value InOutCubic \inlineimage qeasingcurve-inoutcubic.png - \br - Easing curve for a cubic (t^3) function: + \value InOutCubic \image qeasingcurve-inoutcubic.png + \caption Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration. - \value OutInCubic \inlineimage qeasingcurve-outincubic.png - \br - Easing curve for a cubic (t^3) function: + \value OutInCubic \image qeasingcurve-outincubic.png + \caption Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration. - \value InQuart \inlineimage qeasingcurve-inquart.png - \br - Easing curve for a quartic (t^4) function: + \value InQuart \image qeasingcurve-inquart.png + \caption Easing curve for a quartic (t^4) function: accelerating from zero velocity. - \value OutQuart \inlineimage qeasingcurve-outquart.png - \br + \value OutQuart \image qeasingcurve-outquart.png + \caption Easing curve for a quartic (t^4) function: decelerating to zero velocity. - \value InOutQuart \inlineimage qeasingcurve-inoutquart.png - \br + \value InOutQuart \image qeasingcurve-inoutquart.png + \caption Easing curve for a quartic (t^4) function: acceleration until halfway, then deceleration. - \value OutInQuart \inlineimage qeasingcurve-outinquart.png - \br + \value OutInQuart \image qeasingcurve-outinquart.png + \caption Easing curve for a quartic (t^4) function: deceleration until halfway, then acceleration. - \value InQuint \inlineimage qeasingcurve-inquint.png - \br + \value InQuint \image qeasingcurve-inquint.png + \caption Easing curve for a quintic (t^5) easing in: accelerating from zero velocity. - \value OutQuint \inlineimage qeasingcurve-outquint.png - \br + \value OutQuint \image qeasingcurve-outquint.png + \caption Easing curve for a quintic (t^5) function: decelerating to zero velocity. - \value InOutQuint \inlineimage qeasingcurve-inoutquint.png - \br + \value InOutQuint \image qeasingcurve-inoutquint.png + \caption Easing curve for a quintic (t^5) function: acceleration until halfway, then deceleration. - \value OutInQuint \inlineimage qeasingcurve-outinquint.png - \br + \value OutInQuint \image qeasingcurve-outinquint.png + \caption Easing curve for a quintic (t^5) function: deceleration until halfway, then acceleration. - \value InSine \inlineimage qeasingcurve-insine.png - \br + \value InSine \image qeasingcurve-insine.png + \caption Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity. - \value OutSine \inlineimage qeasingcurve-outsine.png - \br + \value OutSine \image qeasingcurve-outsine.png + \caption Easing curve for a sinusoidal (sin(t)) function: decelerating from zero velocity. - \value InOutSine \inlineimage qeasingcurve-inoutsine.png - \br + \value InOutSine \image qeasingcurve-inoutsine.png + \caption Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration. - \value OutInSine \inlineimage qeasingcurve-outinsine.png - \br + \value OutInSine \image qeasingcurve-outinsine.png + \caption Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration. - \value InExpo \inlineimage qeasingcurve-inexpo.png - \br + \value InExpo \image qeasingcurve-inexpo.png + \caption Easing curve for an exponential (2^t) function: accelerating from zero velocity. - \value OutExpo \inlineimage qeasingcurve-outexpo.png - \br + \value OutExpo \image qeasingcurve-outexpo.png + \caption Easing curve for an exponential (2^t) function: decelerating from zero velocity. - \value InOutExpo \inlineimage qeasingcurve-inoutexpo.png - \br + \value InOutExpo \image qeasingcurve-inoutexpo.png + \caption Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration. - \value OutInExpo \inlineimage qeasingcurve-outinexpo.png - \br + \value OutInExpo \image qeasingcurve-outinexpo.png + \caption Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration. - \value InCirc \inlineimage qeasingcurve-incirc.png - \br + \value InCirc \image qeasingcurve-incirc.png + \caption Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity. - \value OutCirc \inlineimage qeasingcurve-outcirc.png - \br + \value OutCirc \image qeasingcurve-outcirc.png + \caption Easing curve for a circular (sqrt(1-t^2)) function: decelerating from zero velocity. - \value InOutCirc \inlineimage qeasingcurve-inoutcirc.png - \br + \value InOutCirc \image qeasingcurve-inoutcirc.png + \caption Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration. - \value OutInCirc \inlineimage qeasingcurve-outincirc.png - \br + \value OutInCirc \image qeasingcurve-outincirc.png + \caption Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration. - \value InElastic \inlineimage qeasingcurve-inelastic.png - \br + \value InElastic \image qeasingcurve-inelastic.png + \caption Easing curve for an elastic (exponentially decaying sine wave) function: accelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. - \value OutElastic \inlineimage qeasingcurve-outelastic.png - \br + \value OutElastic \image qeasingcurve-outelastic.png + \caption Easing curve for an elastic (exponentially decaying sine wave) function: decelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. - \value InOutElastic \inlineimage qeasingcurve-inoutelastic.png - \br + \value InOutElastic \image qeasingcurve-inoutelastic.png + \caption Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration. - \value OutInElastic \inlineimage qeasingcurve-outinelastic.png - \br + \value OutInElastic \image qeasingcurve-outinelastic.png + \caption Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration. - \value InBack \inlineimage qeasingcurve-inback.png - \br + \value InBack \image qeasingcurve-inback.png + \caption Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. - \value OutBack \inlineimage qeasingcurve-outback.png - \br + \value OutBack \image qeasingcurve-outback.png + \caption Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity. - \value InOutBack \inlineimage qeasingcurve-inoutback.png - \br + \value InOutBack \image qeasingcurve-inoutback.png + \caption Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. - \value OutInBack \inlineimage qeasingcurve-outinback.png - \br + \value OutInBack \image qeasingcurve-outinback.png + \caption Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. - \value InBounce \inlineimage qeasingcurve-inbounce.png - \br + \value InBounce \image qeasingcurve-inbounce.png + \caption Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity. - \value OutBounce \inlineimage qeasingcurve-outbounce.png - \br + \value OutBounce \image qeasingcurve-outbounce.png + \caption Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity. - \value InOutBounce \inlineimage qeasingcurve-inoutbounce.png - \br + \value InOutBounce \image qeasingcurve-inoutbounce.png + \caption Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration. - \value OutInBounce \inlineimage qeasingcurve-outinbounce.png - \br + \value OutInBounce \image qeasingcurve-outinbounce.png + \caption Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration. @@ -312,7 +302,7 @@ This is a typedef for a pointer to a function with the following signature: - \snippet doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp 0 + \snippet code/src_corelib_tools_qeasingcurve.cpp 0 */ #include "qeasingcurve.h" @@ -1467,7 +1457,7 @@ QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing) /*! \fn QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing) - \relates QQuaternion + \relates QEasingCurve Reads an easing curve from the given \a stream into the given \a easing curve and returns a reference to the stream. diff --git a/src/corelib/tools/qelapsedtimer.cpp b/src/corelib/tools/qelapsedtimer.cpp index e8f2ce174e..76b0d796f0 100644 --- a/src/corelib/tools/qelapsedtimer.cpp +++ b/src/corelib/tools/qelapsedtimer.cpp @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE spent in a slow operation. The simplest example of such a case is for debugging purposes, as in the following example: - \snippet doc/src/snippets/qelapsedtimer/main.cpp 0 + \snippet qelapsedtimer/main.cpp 0 In this example, the timer is started by a call to start() and the elapsed timer is calculated by the elapsed() function. @@ -76,14 +76,14 @@ QT_BEGIN_NAMESPACE subclasses are good examples of such need. In that case, the code could be as follows: - \snippet doc/src/snippets/qelapsedtimer/main.cpp 1 + \snippet qelapsedtimer/main.cpp 1 Another use-case is to execute a certain operation for a specific timeslice. For this, QElapsedTimer provides the hasExpired() convenience function, which can be used to determine if a certain number of milliseconds has already elapsed: - \snippet doc/src/snippets/qelapsedtimer/main.cpp 2 + \snippet qelapsedtimer/main.cpp 2 \section1 Reference clocks diff --git a/src/corelib/tools/qelapsedtimer_generic.cpp b/src/corelib/tools/qelapsedtimer_generic.cpp index 05214f0698..a20b6b5662 100644 --- a/src/corelib/tools/qelapsedtimer_generic.cpp +++ b/src/corelib/tools/qelapsedtimer_generic.cpp @@ -70,7 +70,7 @@ bool QElapsedTimer::isMonotonic() Starts this timer. Once started, a timer value can be checked with elapsed() or msecsSinceReference(). Normally, a timer is started just before a lengthy operation, such as: - \snippet doc/src/snippets/qelapsedtimer/main.cpp 0 + \snippet qelapsedtimer/main.cpp 0 Also, starting a timer makes it valid again. @@ -91,7 +91,7 @@ void QElapsedTimer::start() parameter to a slow operation (for example, an iteration count) so that this operation takes at least 250 milliseconds: - \snippet doc/src/snippets/qelapsedtimer/main.cpp 3 + \snippet qelapsedtimer/main.cpp 3 \sa start(), invalidate(), elapsed() */ diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 20202a4896..a2851d15bd 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -694,21 +694,21 @@ void QHashData::checkSanity() \endlist Here's an example QHash with QString keys and \c int values: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 0 + \snippet code/src_corelib_tools_qhash.cpp 0 To insert a (key, value) pair into the hash, you can use operator[](): - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 1 + \snippet code/src_corelib_tools_qhash.cpp 1 This inserts the following three (key, value) pairs into the QHash: ("one", 1), ("three", 3), and ("seven", 7). Another way to insert items into the hash is to use insert(): - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 2 + \snippet code/src_corelib_tools_qhash.cpp 2 To look up a value, use operator[]() or value(): - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 3 + \snippet code/src_corelib_tools_qhash.cpp 3 If there is no item with the specified key in the hash, these functions return a \l{default-constructed value}. @@ -716,12 +716,12 @@ void QHashData::checkSanity() If you want to check whether the hash contains a particular key, use contains(): - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 4 + \snippet code/src_corelib_tools_qhash.cpp 4 There is also a value() overload that uses its second argument as a default value if there is no item with the specified key: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 5 + \snippet code/src_corelib_tools_qhash.cpp 5 In general, we recommend that you use contains() and value() rather than operator[]() for looking up a key in a hash. The @@ -730,7 +730,7 @@ void QHashData::checkSanity() const). For example, the following code snippet will create 1000 items in memory: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 6 + \snippet code/src_corelib_tools_qhash.cpp 6 To avoid this problem, replace \c hash[i] with \c hash.value(i) in the code above. @@ -751,11 +751,11 @@ void QHashData::checkSanity() QHash::iterator). Here's how to iterate over a QHash using a Java-style iterator: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 7 + \snippet code/src_corelib_tools_qhash.cpp 7 Here's the same code, but using an STL-style iterator: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 8 + \snippet code/src_corelib_tools_qhash.cpp 8 QHash is unordered, so an iterator's sequence cannot be assumed to be predictable. If ordering by key is required, use a QMap. @@ -764,7 +764,7 @@ void QHashData::checkSanity() insert() with a key that already exists in the QHash, the previous value is erased. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 9 + \snippet code/src_corelib_tools_qhash.cpp 9 However, you can store multiple values per key by using insertMulti() instead of insert() (or using the convenience @@ -772,19 +772,19 @@ void QHashData::checkSanity() the values for a single key, you can use values(const Key &key), which returns a QList: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 10 + \snippet code/src_corelib_tools_qhash.cpp 10 The items that share the same key are available from most recently to least recently inserted. A more efficient approach is to call find() to get the iterator for the first item with a key and iterate from there: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 11 + \snippet code/src_corelib_tools_qhash.cpp 11 If you only need to extract the values from a hash (not the keys), you can also use \l{foreach}: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 12 + \snippet code/src_corelib_tools_qhash.cpp 12 Items can be removed from the hash in several ways. One way is to call remove(); this will remove any item with the given key. @@ -975,7 +975,7 @@ void QHashData::checkSanity() This function is useful for code that needs to build a huge hash and wants to avoid repeated reallocation. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 14 + \snippet code/src_corelib_tools_qhash.cpp 14 Ideally, \a size should be slightly more than the maximum number of items expected in the hash. \a size doesn't have to be prime, @@ -1284,7 +1284,7 @@ void QHashData::checkSanity() be called while iterating, and won't affect the order of items in the hash. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 15 + \snippet code/src_corelib_tools_qhash.cpp 15 \sa remove(), take(), find() */ @@ -1303,7 +1303,7 @@ void QHashData::checkSanity() the iterator. For example, here's some code that iterates over all the items with the same key: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 16 + \snippet code/src_corelib_tools_qhash.cpp 16 \sa value(), values(), QMultiHash::find() */ @@ -1460,7 +1460,7 @@ void QHashData::checkSanity() start iterating. Here's a typical loop that prints all the (key, value) pairs stored in a hash: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 17 + \snippet code/src_corelib_tools_qhash.cpp 17 Unlike QMap, which orders its items by key, QHash stores its items in an arbitrary order. The only guarantee is that items that @@ -1473,22 +1473,22 @@ void QHashData::checkSanity() Here's an example that increments every value stored in the QHash by 2: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 18 + \snippet code/src_corelib_tools_qhash.cpp 18 Here's an example that removes all the items whose key is a string that starts with an underscore character: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 19 + \snippet code/src_corelib_tools_qhash.cpp 19 The call to QHash::erase() removes the item pointed to by the iterator from the hash, and returns an iterator to the next item. Here's another way of removing an item while iterating: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 20 + \snippet code/src_corelib_tools_qhash.cpp 20 It might be tempting to write code like this: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 21 + \snippet code/src_corelib_tools_qhash.cpp 21 However, this will potentially crash in \c{++i}, because \c i is a dangling iterator after the call to erase(). @@ -1514,7 +1514,7 @@ void QHashData::checkSanity() called on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QHash::begin() QHash::end() + \sa QHash::begin(), QHash::end() */ /*! \fn QHash::iterator::iterator(void *node) @@ -1540,7 +1540,7 @@ void QHashData::checkSanity() You can change the value of an item by using value() on the left side of an assignment, for example: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 22 + \snippet code/src_corelib_tools_qhash.cpp 22 \sa key(), operator*() */ @@ -1684,7 +1684,7 @@ void QHashData::checkSanity() QHash::find() before you can start iterating. Here's a typical loop that prints all the (key, value) pairs stored in a hash: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 23 + \snippet code/src_corelib_tools_qhash.cpp 23 Unlike QMap, which orders its items by key, QHash stores its items in an arbitrary order. The only guarantee is that items that @@ -1710,7 +1710,7 @@ void QHashData::checkSanity() called on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QHash::constBegin() QHash::constEnd() + \sa QHash::constBegin(), QHash::constEnd() */ /*! \fn QHash::const_iterator::const_iterator(void *node) @@ -1897,7 +1897,7 @@ void QHashData::checkSanity() operator+=(). Example: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 24 + \snippet code/src_corelib_tools_qhash.cpp 24 Unlike QHash, QMultiHash provides no operator[]. Use value() or replace() if you want to access the most recently inserted item @@ -1906,7 +1906,7 @@ void QHashData::checkSanity() If you want to retrieve all the values for a single key, you can use values(const Key &key), which returns a QList: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 25 + \snippet code/src_corelib_tools_qhash.cpp 25 The items that share the same key are available from most recently to least recently inserted. @@ -1915,7 +1915,7 @@ void QHashData::checkSanity() the STL-style iterator for the first item with a key and iterate from there: - \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 26 + \snippet code/src_corelib_tools_qhash.cpp 26 QMultiHash's key and value data types must be \l{assignable data types}. You cannot, for example, store a QWidget as a value; diff --git a/src/corelib/tools/qiterator.qdoc b/src/corelib/tools/qiterator.qdoc index e19a751755..508664ec45 100644 --- a/src/corelib/tools/qiterator.qdoc +++ b/src/corelib/tools/qiterator.qdoc @@ -50,7 +50,7 @@ the list (before the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 0 + \snippet code/doc_src_qiterator.cpp 0 The next() function returns the next item in the list and advances the iterator. Unlike STL-style iterators, Java-style @@ -61,11 +61,11 @@ position between the second and third item, and returns the second item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 1 + \snippet code/doc_src_qiterator.cpp 1 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. @@ -98,7 +98,7 @@ beginning of the list (before the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 2 + \snippet code/doc_src_qiterator.cpp 2 The next() function returns the next item in the list and advances the iterator. Unlike STL-style iterators, Java-style @@ -109,11 +109,11 @@ position between the second and third item, and returns the second item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 3 + \snippet code/doc_src_qiterator.cpp 3 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. @@ -150,7 +150,7 @@ of the vector (before the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 4 + \snippet code/doc_src_qiterator.cpp 4 The next() function returns the next item in the vector and advances the iterator. Unlike STL-style iterators, Java-style @@ -161,11 +161,11 @@ position between the second and third item, returning the second item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 5 + \snippet code/doc_src_qiterator.cpp 5 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. @@ -197,7 +197,7 @@ the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 6 + \snippet code/doc_src_qiterator.cpp 6 The next() function returns the next item in the set and advances the iterator. Unlike STL-style iterators, Java-style @@ -208,11 +208,11 @@ position between the second and third item, returning the second item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 7 + \snippet code/doc_src_qiterator.cpp 7 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. @@ -251,7 +251,7 @@ of the list (before the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 8 + \snippet code/doc_src_qiterator.cpp 8 The next() function returns the next item in the list and advances the iterator. Unlike STL-style iterators, Java-style @@ -262,11 +262,11 @@ position between the second and third item, returning the second item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 9 + \snippet code/doc_src_qiterator.cpp 9 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. @@ -277,7 +277,7 @@ insert(). Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 10 + \snippet code/doc_src_qiterator.cpp 10 The example traverses a list, replacing negative numbers with their absolute values, and eliminating zeroes. @@ -312,7 +312,7 @@ beginning of the list (before the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 11 + \snippet code/doc_src_qiterator.cpp 11 The next() function returns the next item in the list and advances the iterator. Unlike STL-style iterators, Java-style @@ -323,11 +323,11 @@ position between the second and third item, returning the second item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 12 + \snippet code/doc_src_qiterator.cpp 12 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. @@ -338,7 +338,7 @@ insert(). Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 13 + \snippet code/doc_src_qiterator.cpp 13 The example traverses a list, replacing negative numbers with their absolute values, and eliminating zeroes. @@ -378,7 +378,7 @@ beginning of the list (before the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 14 + \snippet code/doc_src_qiterator.cpp 14 The next() function returns the next item in the vector and advances the iterator. Unlike STL-style iterators, Java-style @@ -389,11 +389,11 @@ position between the second and third item, returning the second item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 15 + \snippet code/doc_src_qiterator.cpp 15 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. @@ -404,7 +404,7 @@ insert(). Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 16 + \snippet code/doc_src_qiterator.cpp 16 The example traverses a vector, replacing negative numbers with their absolute values, and eliminating zeroes. @@ -440,7 +440,7 @@ of the set (before the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 17 + \snippet code/doc_src_qiterator.cpp 17 The next() function returns the next item in the set and advances the iterator. Unlike STL-style iterators, Java-style @@ -451,11 +451,11 @@ position between the second and third item, returning the second item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 18 + \snippet code/doc_src_qiterator.cpp 18 If you want to remove items as you iterate over the set, use remove(). @@ -755,7 +755,7 @@ traversal functions (next(), previous(), findNext(), findPrevious()). Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 19 + \snippet code/doc_src_qiterator.cpp 19 \sa insert(), setValue() */ @@ -766,7 +766,7 @@ traversal functions (next(), previous(), findNext(), findPrevious()). Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 20 + \snippet code/doc_src_qiterator.cpp 20 \sa insert(), setValue() */ @@ -777,7 +777,7 @@ traversal functions (next(), previous(), findNext(), findPrevious()). Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 21 + \snippet code/doc_src_qiterator.cpp 21 \sa insert(), setValue() */ @@ -788,7 +788,7 @@ traversal functions (next(), previous(), findNext(), findPrevious()). Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 22 + \snippet code/doc_src_qiterator.cpp 22 \sa value() */ @@ -802,7 +802,7 @@ findPrevious(). Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 23 + \snippet code/doc_src_qiterator.cpp 23 \sa value(), remove(), insert() */ @@ -816,7 +816,7 @@ findPrevious(). Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 24 + \snippet code/doc_src_qiterator.cpp 24 \sa value(), remove(), insert() */ @@ -830,7 +830,7 @@ findPrevious(). Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 25 + \snippet code/doc_src_qiterator.cpp 25 \sa value(), remove(), insert() */ @@ -889,7 +889,7 @@ the map (before the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 26 + \snippet code/doc_src_qiterator.cpp 26 The next() function returns the next item in the map and advances the iterator. The key() and value() functions return the @@ -902,16 +902,16 @@ next() advances the iterator to the position between the second and third item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 27 + \snippet code/doc_src_qiterator.cpp 27 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. For example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 28 + \snippet code/doc_src_qiterator.cpp 28 Multiple iterators can be used on the same map. If the map is modified while a QMapIterator is active, the QMapIterator will @@ -941,7 +941,7 @@ the hash (before the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 29 + \snippet code/doc_src_qiterator.cpp 29 The next() function returns the next item in the hash and advances the iterator. The key() and value() functions return the @@ -954,16 +954,16 @@ next() advances the iterator to the position between the second and third item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 30 + \snippet code/doc_src_qiterator.cpp 30 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. For example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 31 + \snippet code/doc_src_qiterator.cpp 31 Multiple iterators can be used on the same hash. If the hash is modified while a QHashIterator is active, the QHashIterator will @@ -994,7 +994,7 @@ of the map (before the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 32 + \snippet code/doc_src_qiterator.cpp 32 The next() function returns the next item in the map and advances the iterator. The key() and value() functions return the @@ -1007,16 +1007,16 @@ next() advances the iterator to the position between the second and third item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 33 + \snippet code/doc_src_qiterator.cpp 33 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. For example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 34 + \snippet code/doc_src_qiterator.cpp 34 If you want to remove items as you iterate over the map, use remove(). If you want to modify the value of an item, use @@ -1024,7 +1024,7 @@ Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 35 + \snippet code/doc_src_qiterator.cpp 35 The example removes all (key, value) pairs where the key and the value are the same. @@ -1059,7 +1059,7 @@ of the hash (before the first item). Here's how to iterate over all the elements sequentially: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 36 + \snippet code/doc_src_qiterator.cpp 36 The next() function returns the next item in the hash and advances the iterator. The key() and value() functions return the @@ -1072,16 +1072,16 @@ next() advances the iterator to the position between the second and third item; and so on. - \img javaiterators1.png + \image javaiterators1.png Here's how to iterate over the elements in reverse order: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 37 + \snippet code/doc_src_qiterator.cpp 37 If you want to find all occurrences of a particular value, use findNext() or findPrevious() in a loop. For example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 38 + \snippet code/doc_src_qiterator.cpp 38 If you want to remove items as you iterate over the hash, use remove(). If you want to modify the value of an item, use @@ -1089,7 +1089,7 @@ Example: - \snippet doc/src/snippets/code/doc_src_qiterator.cpp 39 + \snippet code/doc_src_qiterator.cpp 39 The example removes all (key, value) pairs where the key and the value are the same. diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp index 1502f70d56..3682818099 100644 --- a/src/corelib/tools/qlinkedlist.cpp +++ b/src/corelib/tools/qlinkedlist.cpp @@ -81,13 +81,13 @@ const QLinkedListData QLinkedListData::shared_null = { Here's an example of a QLinkedList that stores integers and a QLinkedList that stores QTime values: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 0 + \snippet code/src_corelib_tools_qlinkedlist.cpp 0 QLinkedList stores a list of items. The default constructor creates an empty list. To insert items into the list, you can use operator<<(): - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 1 + \snippet code/src_corelib_tools_qlinkedlist.cpp 1 If you want to get the first or last item in a linked list, use first() or last(). If you want to remove an item from either end @@ -99,7 +99,7 @@ const QLinkedListData QLinkedListData::shared_null = { list and do something with it. For this, QLinkedList provides takeFirst() and takeLast(). Here's a loop that removes the items from a list one at a time and calls \c delete on them: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 2 + \snippet code/src_corelib_tools_qlinkedlist.cpp 2 QLinkedList's value type must be an \l {assignable data type}. This covers most data types that are commonly used, but the compiler @@ -230,7 +230,7 @@ const QLinkedListData QLinkedListData::shared_null = { Inserts \a value at the end of the list. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 3 + \snippet code/src_corelib_tools_qlinkedlist.cpp 3 This is the same as list.insert(end(), \a value). @@ -242,7 +242,7 @@ const QLinkedListData QLinkedListData::shared_null = { Inserts \a value at the beginning of the list. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 4 + \snippet code/src_corelib_tools_qlinkedlist.cpp 4 This is the same as list.insert(begin(), \a value). @@ -254,7 +254,7 @@ const QLinkedListData QLinkedListData::shared_null = { Removes all occurrences of \a value in the list. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 5 + \snippet code/src_corelib_tools_qlinkedlist.cpp 5 This function requires the value type to have an implementation of \c operator==(). @@ -270,7 +270,7 @@ const QLinkedListData QLinkedListData::shared_null = { success; otherwise returns false. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 6 + \snippet code/src_corelib_tools_qlinkedlist.cpp 6 This function requires the value type to have an implementation of \c operator==(). @@ -635,35 +635,35 @@ const QLinkedListData QLinkedListData::shared_null = { QLinkedList::insert() before you can start iterating. Here's a typical loop that prints all the items stored in a list: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 7 + \snippet code/src_corelib_tools_qlinkedlist.cpp 7 STL-style iterators can be used as arguments to \l{generic algorithms}. For example, here's how to find an item in the list using the qFind() algorithm: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 8 + \snippet code/src_corelib_tools_qlinkedlist.cpp 8 Let's see a few examples of things we can do with a QLinkedList::iterator that we cannot do with a QLinkedList::const_iterator. Here's an example that increments every value stored in a QLinkedList\ by 2: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 9 + \snippet code/src_corelib_tools_qlinkedlist.cpp 9 Here's an example that removes all the items that start with an underscore character in a QLinkedList\: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 10 + \snippet code/src_corelib_tools_qlinkedlist.cpp 10 The call to QLinkedList::erase() removes the item pointed to by the iterator from the list, and returns an iterator to the next item. Here's another way of removing an item while iterating: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 11 + \snippet code/src_corelib_tools_qlinkedlist.cpp 11 It might be tempting to write code like this: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 12 + \snippet code/src_corelib_tools_qlinkedlist.cpp 12 However, this will potentially crash in \c{++i}, because \c i is a dangling iterator after the call to erase(). @@ -686,7 +686,7 @@ const QLinkedListData QLinkedListData::shared_null = { on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QLinkedList::begin() QLinkedList::end() + \sa QLinkedList::begin(), QLinkedList::end() */ /*! \fn QLinkedList::iterator::iterator(Node *node) @@ -736,7 +736,7 @@ const QLinkedListData QLinkedListData::shared_null = { You can change the value of an item by using operator*() on the left side of an assignment, for example: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 13 + \snippet code/src_corelib_tools_qlinkedlist.cpp 13 \sa operator->() */ @@ -868,13 +868,13 @@ const QLinkedListData QLinkedListData::shared_null = { QLinkedList::insert() before you can start iterating. Here's a typical loop that prints all the items stored in a list: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 14 + \snippet code/src_corelib_tools_qlinkedlist.cpp 14 STL-style iterators can be used as arguments to \l{generic algorithms}. For example, here's how to find an item in the list using the qFind() algorithm: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 15 + \snippet code/src_corelib_tools_qlinkedlist.cpp 15 Multiple iterators can be used on the same list. If you add items to the list, existing iterators will remain valid. If you remove @@ -892,7 +892,7 @@ const QLinkedListData QLinkedListData::shared_null = { on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QLinkedList::constBegin() QLinkedList::constEnd() + \sa QLinkedList::constBegin(), QLinkedList::constEnd() */ /*! \fn QLinkedList::const_iterator::const_iterator(Node *node) @@ -1082,7 +1082,7 @@ const QLinkedListData QLinkedListData::shared_null = { Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 16 + \snippet code/src_corelib_tools_qlinkedlist.cpp 16 \sa toStdList() */ @@ -1094,7 +1094,7 @@ const QLinkedListData QLinkedListData::shared_null = { Returns a std::list object with the data contained in this QLinkedList. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp 17 + \snippet code/src_corelib_tools_qlinkedlist.cpp 17 \sa fromStdList() */ diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index c87b3e7d24..b3514d35ef 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -375,7 +375,7 @@ void **QListData::erase(void **xi) Here's an example of a QList that stores integers and a QList that stores QDate values: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 0 + \snippet code/src_corelib_tools_qlistdata.cpp 0 Qt includes a QStringList class that inherits QList\ and adds a few convenience functions, such as QStringList::join() @@ -386,7 +386,7 @@ void **QListData::erase(void **xi) empty list. To insert items into the list, you can use operator<<(): - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 1 + \snippet code/src_corelib_tools_qlistdata.cpp 1 QList provides these basic functions to add, move, and remove items: insert(), replace(), removeAt(), move(), and swap(). In @@ -398,13 +398,13 @@ void **QListData::erase(void **xi) non-const lists, operator[]() returns a reference to the item and can be used on the left side of an assignment: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 2 + \snippet code/src_corelib_tools_qlistdata.cpp 2 Because QList is implemented as an array of pointers, this operation is very fast (\l{constant time}). For read-only access, an alternative syntax is to use at(): - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 3 + \snippet code/src_corelib_tools_qlistdata.cpp 3 at() can be faster than operator[](), because it never causes a \l{deep copy} to occur. @@ -414,7 +414,7 @@ void **QListData::erase(void **xi) and takeLast(). Here's a loop that removes the items from a list one at a time and calls \c delete on them: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 4 + \snippet code/src_corelib_tools_qlistdata.cpp 4 Inserting and removing items at either ends of the list is very fast (\l{constant time} in most cases), because QList @@ -427,7 +427,7 @@ void **QListData::erase(void **xi) backward. Both return the index of a matching item if they find it; otherwise, they return -1. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 5 + \snippet code/src_corelib_tools_qlistdata.cpp 5 If you simply want to check whether a list contains a particular value, use contains(). If you want to find out how many times a @@ -652,7 +652,7 @@ void **QListData::erase(void **xi) Inserts \a value at the end of the list. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 6 + \snippet code/src_corelib_tools_qlistdata.cpp 6 This is the same as list.insert(size(), \a value). @@ -680,7 +680,7 @@ void **QListData::erase(void **xi) Inserts \a value at the beginning of the list. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 7 + \snippet code/src_corelib_tools_qlistdata.cpp 7 This is the same as list.insert(0, \a value). @@ -698,7 +698,7 @@ void **QListData::erase(void **xi) value is appended to the list. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 8 + \snippet code/src_corelib_tools_qlistdata.cpp 8 \sa append(), prepend(), replace(), removeAt() */ @@ -729,7 +729,7 @@ void **QListData::erase(void **xi) number of entries removed. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 9 + \snippet code/src_corelib_tools_qlistdata.cpp 9 This function requires the value type to have an implementation of \c operator==(). @@ -745,7 +745,7 @@ void **QListData::erase(void **xi) true on success; otherwise returns false. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 10 + \snippet code/src_corelib_tools_qlistdata.cpp 10 This function requires the value type to have an implementation of \c operator==(). @@ -805,7 +805,7 @@ void **QListData::erase(void **xi) Moves the item at index position \a from to index position \a to. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 11 + \snippet code/src_corelib_tools_qlistdata.cpp 11 This is the same as insert(\a{to}, takeAt(\a{from})).This function assumes that both \a from and \a to are at least 0 but less than @@ -823,7 +823,7 @@ void **QListData::erase(void **xi) \a i and \a j are at least 0 and less than size(). Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 12 + \snippet code/src_corelib_tools_qlistdata.cpp 12 \sa move() */ @@ -835,7 +835,7 @@ void **QListData::erase(void **xi) -1 if no item matched. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 13 + \snippet code/src_corelib_tools_qlistdata.cpp 13 This function requires the value type to have an implementation of \c operator==(). @@ -855,7 +855,7 @@ void **QListData::erase(void **xi) Returns -1 if no item matched. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 14 + \snippet code/src_corelib_tools_qlistdata.cpp 14 This function requires the value type to have an implementation of \c operator==(). @@ -1237,14 +1237,14 @@ void **QListData::erase(void **xi) start iterating. Here's a typical loop that prints all the items stored in a list: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 15 + \snippet code/src_corelib_tools_qlistdata.cpp 15 Let's see a few examples of things we can do with a QList::iterator that we cannot do with a QList::const_iterator. Here's an example that increments every value stored in a QList\ by 2: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 16 + \snippet code/src_corelib_tools_qlistdata.cpp 16 Most QList functions accept an integer index rather than an iterator. For that reason, iterators are rarely useful in @@ -1254,7 +1254,7 @@ void **QListData::erase(void **xi) For example, here's how to delete all the widgets stored in a QList\: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 17 + \snippet code/src_corelib_tools_qlistdata.cpp 17 Multiple iterators can be used on the same list. However, be aware that any non-const function call performed on the QList @@ -1299,7 +1299,7 @@ void **QListData::erase(void **xi) on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QList::begin() QList::end() + \sa QList::begin(), QList::end() */ /*! \fn QList::iterator::iterator(Node *node) @@ -1319,7 +1319,7 @@ void **QListData::erase(void **xi) You can change the value of an item by using operator*() on the left side of an assignment, for example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 18 + \snippet code/src_corelib_tools_qlistdata.cpp 18 \sa operator->() */ @@ -1493,7 +1493,7 @@ void **QListData::erase(void **xi) QList::insert() before you can start iterating. Here's a typical loop that prints all the items stored in a list: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 19 + \snippet code/src_corelib_tools_qlistdata.cpp 19 Most QList functions accept an integer index rather than an iterator. For that reason, iterators are rarely useful in @@ -1503,7 +1503,7 @@ void **QListData::erase(void **xi) For example, here's how to delete all the widgets stored in a QList\: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 20 + \snippet code/src_corelib_tools_qlistdata.cpp 20 Multiple iterators can be used on the same list. However, be aware that any non-const function call performed on the QList @@ -1522,7 +1522,7 @@ void **QListData::erase(void **xi) on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QList::constBegin() QList::constEnd() + \sa QList::constBegin(), QList::constEnd() */ /*! \typedef QList::const_iterator::iterator_category @@ -1738,7 +1738,7 @@ void **QListData::erase(void **xi) Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 21 + \snippet code/src_corelib_tools_qlistdata.cpp 21 \sa fromSet(), toVector(), QVector::toList() */ @@ -1749,7 +1749,7 @@ void **QListData::erase(void **xi) Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 22 + \snippet code/src_corelib_tools_qlistdata.cpp 22 \sa toSet(), fromVector(), QVector::fromList() */ @@ -1761,7 +1761,7 @@ void **QListData::erase(void **xi) Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 23 + \snippet code/src_corelib_tools_qlistdata.cpp 23 \sa fromVector(), toSet(), QSet::toList(), qSort() */ @@ -1774,7 +1774,7 @@ void **QListData::erase(void **xi) Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 24 + \snippet code/src_corelib_tools_qlistdata.cpp 24 \sa toVector(), fromSet(), QSet::fromList() */ @@ -1786,7 +1786,7 @@ void **QListData::erase(void **xi) Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 25 + \snippet code/src_corelib_tools_qlistdata.cpp 25 \sa toStdList(), QVector::fromStdVector() */ @@ -1796,7 +1796,7 @@ void **QListData::erase(void **xi) Returns a std::list object with the data contained in this QList. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlistdata.cpp 26 + \snippet code/src_corelib_tools_qlistdata.cpp 26 \sa fromStdList(), QVector::toStdVector() */ diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index b9f199e50e..791e8d0513 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -681,7 +681,7 @@ QLocale::QLocale() The language and country that are actually used can be queried using language() and country(). - \sa setDefault() language() country() + \sa setDefault(), language(), country() */ QLocale::QLocale(Language language, Country country) @@ -720,7 +720,7 @@ QLocale::QLocale(Language language, Country country) The language, script and country that are actually used can be queried using language(), script() and country(). - \sa setDefault() language() script() country() + \sa setDefault(), language(), script(), country() */ QLocale::QLocale(Language language, Script script, Country country) @@ -883,7 +883,7 @@ QString QLocale::createSeparatedList(const QStringList &list) const should be set at application startup, before any non-GUI threads are created. - \sa system() c() + \sa system(), c() */ void QLocale::setDefault(const QLocale &locale) @@ -1202,7 +1202,7 @@ float QLocale::toFloat(const QString &s, bool *ok) const the "C" locale if the string cannot be interpreted in this locale. - \snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 3 + \snippet code/src_corelib_tools_qlocale.cpp 3 Notice that the last conversion returns 1234.0, because '.' is the thousands group separator in the German locale. diff --git a/src/corelib/tools/qlocale.qdoc b/src/corelib/tools/qlocale.qdoc index 32822c2e6e..ed80984de3 100644 --- a/src/corelib/tools/qlocale.qdoc +++ b/src/corelib/tools/qlocale.qdoc @@ -42,7 +42,7 @@ Example: - \snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 0 + \snippet code/src_corelib_tools_qlocale.cpp 0 QLocale supports the concept of a default locale, which is determined from the system's locale settings at application @@ -63,7 +63,7 @@ The following example illustrates how to use QLocale directly: - \snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 1 + \snippet code/src_corelib_tools_qlocale.cpp 1 When a language/country pair is specified in the constructor, one of three things can happen: @@ -83,7 +83,7 @@ An alternative method for constructing a QLocale object is by specifying the locale name. - \snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 2 + \snippet code/src_corelib_tools_qlocale.cpp 2 This constructor converts the locale name to a language/country pair; it does not use the system locale database. @@ -662,7 +662,7 @@ will fail if they encounter group separators in their input. The default is to accept numbers containing correctly placed group separators. - \sa setNumberOptions() numberOptions() + \sa setNumberOptions(), numberOptions() */ /*! diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index 90521d343c..8002e7c1f0 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -388,21 +388,21 @@ void QMapDataBase::freeData(QMapDataBase *d) \endlist Here's an example QMap with QString keys and \c int values: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 0 + \snippet code/src_corelib_tools_qmap.cpp 0 To insert a (key, value) pair into the map, you can use operator[](): - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 1 + \snippet code/src_corelib_tools_qmap.cpp 1 This inserts the following three (key, value) pairs into the QMap: ("one", 1), ("three", 3), and ("seven", 7). Another way to insert items into the map is to use insert(): - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 2 + \snippet code/src_corelib_tools_qmap.cpp 2 To look up a value, use operator[]() or value(): - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 3 + \snippet code/src_corelib_tools_qmap.cpp 3 If there is no item with the specified key in the map, these functions return a \l{default-constructed value}. @@ -410,12 +410,12 @@ void QMapDataBase::freeData(QMapDataBase *d) If you want to check whether the map contains a certain key, use contains(): - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 4 + \snippet code/src_corelib_tools_qmap.cpp 4 There is also a value() overload that uses its second argument as a default value if there is no item with the specified key: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 5 + \snippet code/src_corelib_tools_qmap.cpp 5 In general, we recommend that you use contains() and value() rather than operator[]() for looking up a key in a map. The @@ -424,7 +424,7 @@ void QMapDataBase::freeData(QMapDataBase *d) const). For example, the following code snippet will create 1000 items in memory: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 6 + \snippet code/src_corelib_tools_qmap.cpp 6 To avoid this problem, replace \c map[i] with \c map.value(i) in the code above. @@ -436,11 +436,11 @@ void QMapDataBase::freeData(QMapDataBase *d) QMap::iterator). Here's how to iterate over a QMap using a Java-style iterator: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 7 + \snippet code/src_corelib_tools_qmap.cpp 7 Here's the same code, but using an STL-style iterator this time: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 8 + \snippet code/src_corelib_tools_qmap.cpp 8 The items are traversed in ascending key order. @@ -448,7 +448,7 @@ void QMapDataBase::freeData(QMapDataBase *d) insert() with a key that already exists in the QMap, the previous value will be erased. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 9 + \snippet code/src_corelib_tools_qmap.cpp 9 However, you can store multiple values per key by using insertMulti() instead of insert() (or using the convenience @@ -456,19 +456,19 @@ void QMapDataBase::freeData(QMapDataBase *d) single key, you can use values(const Key &key), which returns a QList: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 10 + \snippet code/src_corelib_tools_qmap.cpp 10 The items that share the same key are available from most recently to least recently inserted. Another approach is to call find() to get the STL-style iterator for the first item with a key and iterate from there: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 11 + \snippet code/src_corelib_tools_qmap.cpp 11 If you only need to extract the values from a map (not the keys), you can also use \l{foreach}: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 12 + \snippet code/src_corelib_tools_qmap.cpp 12 Items can be removed from the map in several ways. One way is to call remove(); this will remove any item with the given key. @@ -484,7 +484,7 @@ void QMapDataBase::freeData(QMapDataBase *d) < y} nor \c{y < x} is true. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 13 + \snippet code/src_corelib_tools_qmap.cpp 13 In the example, we start by comparing the employees' names. If they're equal, we compare their dates of birth to break the tie. @@ -881,7 +881,7 @@ void QMapDataBase::freeData(QMapDataBase *d) the iterator. For example, here's some code that iterates over all the items with the same key: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 14 + \snippet code/src_corelib_tools_qmap.cpp 14 \sa constFind(), value(), values(), lowerBound(), upperBound(), QMultiMap::find() */ @@ -911,7 +911,7 @@ void QMapDataBase::freeData(QMapDataBase *d) key. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 15 + \snippet code/src_corelib_tools_qmap.cpp 15 If the map contains multiple items with key \a key, this function returns an iterator that points to the most recently @@ -919,7 +919,7 @@ void QMapDataBase::freeData(QMapDataBase *d) the iterator. For example, here's some code that iterates over all the items with the same key: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 16 + \snippet code/src_corelib_tools_qmap.cpp 16 \sa qLowerBound(), upperBound(), find() */ @@ -937,7 +937,7 @@ void QMapDataBase::freeData(QMapDataBase *d) nearest item with a greater key. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 17 + \snippet code/src_corelib_tools_qmap.cpp 17 \sa qUpperBound(), lowerBound(), find() */ @@ -1042,7 +1042,7 @@ void QMapDataBase::freeData(QMapDataBase *d) start iterating. Here's a typical loop that prints all the (key, value) pairs stored in a map: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 18 + \snippet code/src_corelib_tools_qmap.cpp 18 Unlike QHash, which stores its items in an arbitrary order, QMap stores its items ordered by key. Items that share the same key @@ -1055,22 +1055,22 @@ void QMapDataBase::freeData(QMapDataBase *d) Here's an example that increments every value stored in the QMap by 2: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 19 + \snippet code/src_corelib_tools_qmap.cpp 19 Here's an example that removes all the items whose key is a string that starts with an underscore character: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 20 + \snippet code/src_corelib_tools_qmap.cpp 20 The call to QMap::erase() removes the item pointed to by the iterator from the map, and returns an iterator to the next item. Here's another way of removing an item while iterating: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 21 + \snippet code/src_corelib_tools_qmap.cpp 21 It might be tempting to write code like this: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 22 + \snippet code/src_corelib_tools_qmap.cpp 22 However, this will potentially crash in \c{++i}, because \c i is a dangling iterator after the call to erase(). @@ -1122,7 +1122,7 @@ void QMapDataBase::freeData(QMapDataBase *d) called on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QMap::begin() QMap::end() + \sa QMap::begin(), QMap::end() */ /*! \fn QMap::iterator::iterator(QMapData::Node *node) @@ -1148,7 +1148,7 @@ void QMapDataBase::freeData(QMapDataBase *d) You can change the value of an item by using value() on the left side of an assignment, for example: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 23 + \snippet code/src_corelib_tools_qmap.cpp 23 \sa key(), operator*() */ @@ -1289,7 +1289,7 @@ void QMapDataBase::freeData(QMapDataBase *d) QMap::find() before you can start iterating. Here's a typical loop that prints all the (key, value) pairs stored in a map: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 24 + \snippet code/src_corelib_tools_qmap.cpp 24 Unlike QHash, which stores its items in an arbitrary order, QMap stores its items ordered by key. Items that share the same key @@ -1344,7 +1344,7 @@ void QMapDataBase::freeData(QMapDataBase *d) called on an uninitialized iterator. Use operator=() to assign a value to it before using it. - \sa QMap::constBegin() QMap::constEnd() + \sa QMap::constBegin(), QMap::constEnd() */ /*! \fn QMap::const_iterator::const_iterator(QMapData::Node *node) @@ -1530,7 +1530,7 @@ void QMapDataBase::freeData(QMapDataBase *d) operator+=(). Example: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 25 + \snippet code/src_corelib_tools_qmap.cpp 25 Unlike QMap, QMultiMap provides no operator[]. Use value() or replace() if you want to access the most recently inserted item @@ -1539,7 +1539,7 @@ void QMapDataBase::freeData(QMapDataBase *d) If you want to retrieve all the values for a single key, you can use values(const Key &key), which returns a QList: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 26 + \snippet code/src_corelib_tools_qmap.cpp 26 The items that share the same key are available from most recently to least recently inserted. @@ -1548,7 +1548,7 @@ void QMapDataBase::freeData(QMapDataBase *d) the iterator for the first item with a key and iterate from there: - \snippet doc/src/snippets/code/src_corelib_tools_qmap.cpp 27 + \snippet code/src_corelib_tools_qmap.cpp 27 QMultiMap's key and value data types must be \l{assignable data types}. This covers most data types you are likely to encounter, diff --git a/src/corelib/tools/qpair.qdoc b/src/corelib/tools/qpair.qdoc index fdf1eafc23..ddaf82497e 100644 --- a/src/corelib/tools/qpair.qdoc +++ b/src/corelib/tools/qpair.qdoc @@ -40,12 +40,12 @@ Here's an example of a QPair that stores one QString and one \c double value: - \snippet doc/src/snippets/code/doc_src_qpair.cpp 0 + \snippet code/doc_src_qpair.cpp 0 The components are accessible as public data members called \l first and \l second. For example: - \snippet doc/src/snippets/code/doc_src_qpair.cpp 1 + \snippet code/doc_src_qpair.cpp 1 QPair's template data types (T1 and T2) must be \l{assignable data types}. You cannot, for example, store a QWidget as a value; @@ -95,12 +95,6 @@ \sa qMakePair() */ -/*! - \fn QPair &QPair::operator=(const QPair &other) - - Assigns \a other to this pair. -*/ - /*! \fn bool operator==(const QPair &p1, const QPair &p2) \relates QPair @@ -186,7 +180,7 @@ Returns a QPair\ that contains \a value1 and \a value2. Example: - \snippet doc/src/snippets/code/doc_src_qpair.cpp 2 + \snippet code/doc_src_qpair.cpp 2 This is equivalent to QPair(\a value1, \a value2), but usually requires less typing. diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp index ecbe9deb9f..edc103f0b2 100644 --- a/src/corelib/tools/qpoint.cpp +++ b/src/corelib/tools/qpoint.cpp @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE Given a point \e p, the following statements are all equivalent: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 0 + \snippet code/src_corelib_tools_qpoint.cpp 0 A QPoint object can also be used as a vector: Addition and subtraction are defined as for vectors (each component is added @@ -126,7 +126,7 @@ QT_BEGIN_NAMESPACE Sets the x coordinate of this point to the given \a x coordinate. - \sa x() setY() + \sa x(), setY() */ /*! @@ -134,7 +134,7 @@ QT_BEGIN_NAMESPACE Sets the y coordinate of this point to the given \a y coordinate. - \sa y() setX() + \sa y(), setX() */ @@ -145,9 +145,9 @@ QT_BEGIN_NAMESPACE Using a reference makes it possible to directly manipulate x. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 1 + \snippet code/src_corelib_tools_qpoint.cpp 1 - \sa x() setX() + \sa x(), setX() */ /*! @@ -158,7 +158,7 @@ QT_BEGIN_NAMESPACE Using a reference makes it possible to directly manipulate y. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 2 + \snippet code/src_corelib_tools_qpoint.cpp 2 \sa y(), setY() */ @@ -170,7 +170,7 @@ QT_BEGIN_NAMESPACE Adds the given \a point to this point and returns a reference to this point. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 3 + \snippet code/src_corelib_tools_qpoint.cpp 3 \sa operator-=() */ @@ -181,7 +181,7 @@ QT_BEGIN_NAMESPACE Subtracts the given \a point from this point and returns a reference to this point. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 4 + \snippet code/src_corelib_tools_qpoint.cpp 4 \sa operator+=() */ @@ -204,7 +204,7 @@ QT_BEGIN_NAMESPACE Multiplies this point's coordinates by the given \a factor, and returns a reference to this point. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 5 + \snippet code/src_corelib_tools_qpoint.cpp 5 Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy. @@ -331,7 +331,7 @@ QT_BEGIN_NAMESPACE Divides both x and y by the given \a divisor, and returns a reference to this point. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 6 + \snippet code/src_corelib_tools_qpoint.cpp 6 Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy. @@ -408,12 +408,12 @@ QDataStream &operator>>(QDataStream &s, QPoint &p) traditionally known as the "Manhattan length" of the vector from the origin to the point. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 7 + \snippet code/src_corelib_tools_qpoint.cpp 7 This is a useful, and quick to calculate, approximation to the true length: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 8 + \snippet code/src_corelib_tools_qpoint.cpp 8 The tradition of "Manhattan length" arises because such distances apply to travelers who can only travel on a rectangular grid, like @@ -451,7 +451,7 @@ QDebug operator<<(QDebug d, const QPointF &p) Given a point \e p, the following statements are all equivalent: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 9 + \snippet code/src_corelib_tools_qpoint.cpp 9 A QPointF object can also be used as a vector: Addition and subtraction are defined as for vectors (each component is added @@ -534,7 +534,7 @@ QDebug operator<<(QDebug d, const QPointF &p) Sets the x coordinate of this point to the given \a x coordinate. - \sa x() setY() + \sa x(), setY() */ /*! @@ -552,7 +552,7 @@ QDebug operator<<(QDebug d, const QPointF &p) Using a reference makes it possible to directly manipulate x. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 10 + \snippet code/src_corelib_tools_qpoint.cpp 10 \sa x(), setX() */ @@ -564,9 +564,9 @@ QDebug operator<<(QDebug d, const QPointF &p) Using a reference makes it possible to directly manipulate y. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 11 + \snippet code/src_corelib_tools_qpoint.cpp 11 - \sa y() setY() + \sa y(), setY() */ /*! @@ -575,7 +575,7 @@ QDebug operator<<(QDebug d, const QPointF &p) Adds the given \a point to this point and returns a reference to this point. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 12 + \snippet code/src_corelib_tools_qpoint.cpp 12 \sa operator-=() */ @@ -586,7 +586,7 @@ QDebug operator<<(QDebug d, const QPointF &p) Subtracts the given \a point from this point and returns a reference to this point. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 13 + \snippet code/src_corelib_tools_qpoint.cpp 13 \sa operator+=() */ @@ -597,7 +597,7 @@ QDebug operator<<(QDebug d, const QPointF &p) Multiplies this point's coordinates by the given \a factor, and returns a reference to this point. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 14 + \snippet code/src_corelib_tools_qpoint.cpp 14 \sa operator/=() */ @@ -608,7 +608,7 @@ QDebug operator<<(QDebug d, const QPointF &p) Divides both x and y by the given \a divisor, and returns a reference to this point. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qpoint.cpp 15 + \snippet code/src_corelib_tools_qpoint.cpp 15 \sa operator*=() */ diff --git a/src/corelib/tools/qqueue.cpp b/src/corelib/tools/qqueue.cpp index 06d996a542..c5aa4c6bad 100644 --- a/src/corelib/tools/qqueue.cpp +++ b/src/corelib/tools/qqueue.cpp @@ -57,7 +57,7 @@ the head item without removing it. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qqueue.cpp 0 + \snippet code/src_corelib_tools_qqueue.cpp 0 The example will output 1, 2, 3 in that order. diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp index aeab97803d..22bf39bc77 100644 --- a/src/corelib/tools/qrect.cpp +++ b/src/corelib/tools/qrect.cpp @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE height integers, or from a QPoint and a QSize. The following code creates two identical rectangles. - \snippet doc/src/snippets/code/src_corelib_tools_qrect.cpp 0 + \snippet code/src_corelib_tools_qrect.cpp 0 There is a third constructor that creates a QRect using the top-left and bottom-right coordinates, but we recommend that you @@ -1243,7 +1243,7 @@ QDebug operator<<(QDebug dbg, const QRect &r) { height integers, or from a QPoint and a QSize. The following code creates two identical rectangles. - \snippet doc/src/snippets/code/src_corelib_tools_qrect.cpp 1 + \snippet code/src_corelib_tools_qrect.cpp 1 There is also a third constructor creating a QRectF from a QRect, and a corresponding toRect() function that returns a QRect object @@ -1791,7 +1791,7 @@ QRectF QRectF::normalized() const \a y1), and the coordinates of its bottom-right corner to (\a x2, \a y2). - \sa getCoords() setRect() + \sa getCoords(), setRect() */ /*! diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index 1db0fcf44c..79ceba5ceb 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -437,7 +437,7 @@ int qFindString(const QChar *haystack, int haystackLen, int from, When the number of matches cannot be determined in advance, a common idiom is to use cap() in a loop. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 0 + \snippet code/src_corelib_tools_qregexp.cpp 0 \target assertions \section1 Assertions @@ -532,7 +532,7 @@ int qFindString(const QChar *haystack, int haystackLen, int from, To test a string against a wildcard expression, use exactMatch(). For example: - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 1 + \snippet code/src_corelib_tools_qregexp.cpp 1 \target perl-users \section1 Notes for Perl Users @@ -555,7 +555,7 @@ int qFindString(const QChar *haystack, int haystackLen, int from, applied to all the quantifiers in the pattern. For example, to match the Perl regexp \b{ro+?m} requires: - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 2 + \snippet code/src_corelib_tools_qregexp.cpp 2 The equivalent of Perl's \c{/i} option is setCaseSensitivity(Qt::CaseInsensitive). @@ -584,7 +584,7 @@ int qFindString(const QChar *haystack, int haystackLen, int from, the other hand, C++'s rules for literal strings can be used to achieve the same: - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 3 + \snippet code/src_corelib_tools_qregexp.cpp 3 Both zero-width positive and zero-width negative lookahead assertions (?=pattern) and (?!pattern) are supported with the same @@ -603,12 +603,12 @@ int qFindString(const QChar *haystack, int haystackLen, int from, \target code-examples \section1 Code Examples - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 4 + \snippet code/src_corelib_tools_qregexp.cpp 4 The third string matches '\underline{6}'. This is a simple validation regexp for integers in the range 0 to 99. - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 5 + \snippet code/src_corelib_tools_qregexp.cpp 5 The second string matches '\underline{This_is-OK}'. We've used the character set abbreviation '\\S' (non-whitespace) and the anchors @@ -618,25 +618,25 @@ int qFindString(const QChar *haystack, int haystackLen, int from, 'letter' or 'correspondence' but only match whole words i.e. not 'email' - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 6 + \snippet code/src_corelib_tools_qregexp.cpp 6 The second string matches "Please write the \underline{letter}". The word 'letter' is also captured (because of the parentheses). We can see what text we've captured like this: - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 7 + \snippet code/src_corelib_tools_qregexp.cpp 7 This will capture the text from the first set of capturing parentheses (counting capturing left parentheses from left to right). The parentheses are counted from 1 since cap(0) is the whole matched regexp (equivalent to '&' in most regexp engines). - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 8 + \snippet code/src_corelib_tools_qregexp.cpp 8 Here we've passed the QRegExp to QString's replace() function to replace the matched text with new text. - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 9 + \snippet code/src_corelib_tools_qregexp.cpp 9 We've used the indexIn() function to repeatedly match the regexp in the string. Note that instead of moving forward by one character @@ -650,7 +650,7 @@ int qFindString(const QChar *haystack, int haystackLen, int from, One common use of regexps is to split lines of delimited data into their component fields. - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 10 + \snippet code/src_corelib_tools_qregexp.cpp 10 In this example our input lines have the format company name, web address and country. Unfortunately the regexp is rather long and @@ -660,13 +660,13 @@ int qFindString(const QChar *haystack, int haystackLen, int from, QString::split() function can take a separator string or regexp as an argument and split a string accordingly. - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 11 + \snippet code/src_corelib_tools_qregexp.cpp 11 Here field[0] is the company, field[1] the web address and so on. To imitate the matching of a shell we can use wildcard mode. - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 12 + \snippet code/src_corelib_tools_qregexp.cpp 12 Wildcard matching can be convenient because of its simplicity, but any wildcard regexp can be defined using full regexps, e.g. @@ -4255,7 +4255,7 @@ bool QRegExp::exactMatch(const QString &str) const QString::replace(). Example: - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 13 + \snippet code/src_corelib_tools_qregexp.cpp 13 Although const, this function sets matchedLength(), capturedTexts() and pos(). @@ -4331,14 +4331,6 @@ int QRegExp::matchedLength() const #ifndef QT_NO_REGEXP_CAPTURE -/*! - \fn int QRegExp::numCaptures() const - \obsolete - Returns the number of captures contained in the regular expression. - - \sa captureCount() - */ - /*! \since 4.6 Returns the number of captures contained in the regular expression. @@ -4357,17 +4349,17 @@ int QRegExp::captureCount() const (capturing) subexpression of the regexp. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 14 + \snippet code/src_corelib_tools_qregexp.cpp 14 The above example also captures elements that may be present but which we have no interest in. This problem can be solved by using non-capturing parentheses: - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 15 + \snippet code/src_corelib_tools_qregexp.cpp 15 Note that if you want to iterate over the list, you should iterate over a copy, e.g. - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 16 + \snippet code/src_corelib_tools_qregexp.cpp 16 Some regexps can match an indeterminate number of times. For example if the input string is "Offsets: 12 14 99 231 7" and the @@ -4420,7 +4412,7 @@ QStringList QRegExp::capturedTexts() match has index 0 and the parenthesized subexpressions have indexes starting from 1 (excluding non-capturing parentheses). - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 17 + \snippet code/src_corelib_tools_qregexp.cpp 17 The order of elements matched by cap() is as follows. The first element, cap(0), is the entire matching string. Each subsequent @@ -4449,7 +4441,7 @@ QString QRegExp::cap(int nth) of the whole match. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 18 + \snippet code/src_corelib_tools_qregexp.cpp 18 For zero-length matches, pos() always returns -1. (For example, if cap(4) would return an empty string, pos(4) returns -1.) This is @@ -4504,11 +4496,11 @@ QString QRegExp::errorString() Example: - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 19 + \snippet code/src_corelib_tools_qregexp.cpp 19 This function is useful to construct regexp patterns dynamically: - \snippet doc/src/snippets/code/src_corelib_tools_qregexp.cpp 20 + \snippet code/src_corelib_tools_qregexp.cpp 20 \sa setPatternSyntax() */ diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp index 393b2bbb7d..ff423901e8 100644 --- a/src/corelib/tools/qregularexpression.cpp +++ b/src/corelib/tools/qregularexpression.cpp @@ -122,23 +122,23 @@ QT_BEGIN_NAMESPACE You can set the pattern string by passing a string to the QRegularExpression constructor: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 0 + \snippet code/src_corelib_tools_qregularexpression.cpp 0 This sets the pattern string to \c{a pattern}. You can also use the setPattern() function to set a pattern on an existing QRegularExpression object: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 1 + \snippet code/src_corelib_tools_qregularexpression.cpp 1 Note that due to C++ literal strings rules, you must escape all backslashes inside the pattern string with another backslash: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 2 + \snippet code/src_corelib_tools_qregularexpression.cpp 2 The pattern() function returns the pattern that is currently set for a QRegularExpression object: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 3 + \snippet code/src_corelib_tools_qregularexpression.cpp 3 \section1 Pattern options @@ -149,17 +149,17 @@ QT_BEGIN_NAMESPACE You can set the options by passing them to the QRegularExpression constructor, as in: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 4 + \snippet code/src_corelib_tools_qregularexpression.cpp 4 Alternatively, you can use the setPatternOptions() function on an existing QRegularExpressionObject: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 5 + \snippet code/src_corelib_tools_qregularexpression.cpp 5 It is possible to get the pattern options currently set on a QRegularExpression object by using the patternOptions() function: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 6 + \snippet code/src_corelib_tools_qregularexpression.cpp 6 Please refer to the QRegularExpression::PatternOption enum documentation for more information about each pattern option. @@ -187,20 +187,20 @@ QT_BEGIN_NAMESPACE QRegularExpressionMatch object that can be used to inspect the results of the match. For instance: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 7 + \snippet code/src_corelib_tools_qregularexpression.cpp 7 If a match is successful, the (implicit) capturing group number 0 can be used to retrieve the substring matched by the entire pattern (see also the section about \l{extracting captured substrings}): - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 8 + \snippet code/src_corelib_tools_qregularexpression.cpp 8 It's also possible to start a match at an arbitrary offset inside the subject string by passing the offset as an argument of the match() function. In the following example \c{"12 abc"} is not matched because the match is started at offset 1: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 9 + \snippet code/src_corelib_tools_qregularexpression.cpp 9 \target extracting captured substrings \section2 Extracting captured substrings @@ -210,7 +210,7 @@ QT_BEGIN_NAMESPACE \l{QRegularExpressionMatch::}{captured()} function will return the string captured by the n-th capturing group: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 10 + \snippet code/src_corelib_tools_qregularexpression.cpp 10 Capturing groups in the pattern are numbered starting from 1, and the implicit capturing group 0 is used to capture the substring that matched @@ -221,12 +221,12 @@ QT_BEGIN_NAMESPACE \l{QRegularExpressionMatch::}{capturedStart()} and the \l{QRegularExpressionMatch::}{capturedEnd()} functions: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 11 + \snippet code/src_corelib_tools_qregularexpression.cpp 11 All of these functions have an overload taking a QString as a parameter in order to extract \e{named} captured substrings. For instance: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 12 + \snippet code/src_corelib_tools_qregularexpression.cpp 12 \target global matching \section1 Global matching @@ -240,7 +240,7 @@ QT_BEGIN_NAMESPACE which is a Java-like forward iterator that can be used to iterate over the results. For instance: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 13 + \snippet code/src_corelib_tools_qregularexpression.cpp 13 Since it's a Java-like iterator, the QRegularExpressionMatchIterator will point immediately before the first result. Every result is returned as a @@ -250,7 +250,7 @@ QT_BEGIN_NAMESPACE \l{QRegularExpressionMatchIterator::}{next()} will return the next result and advance the iterator. Continuing from the previous example: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 14 + \snippet code/src_corelib_tools_qregularexpression.cpp 14 You can also use \l{QRegularExpressionMatchIterator::}{peekNext()} to get the next result without advancing the iterator. @@ -326,17 +326,17 @@ QT_BEGIN_NAMESPACE This behaviour is implemented by the PartialPreferCompleteMatch match type. For instance: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 15 + \snippet code/src_corelib_tools_qregularexpression.cpp 15 If matching the same regular expression against the subject string leads to a complete match, it is reported as usual: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 16 + \snippet code/src_corelib_tools_qregularexpression.cpp 16 Another example with a different pattern, showing the behaviour of preferring a complete match over a partial one: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 17 + \snippet code/src_corelib_tools_qregularexpression.cpp 17 In this case, the subpattern \c{abc\\w+X} partially matches the subject string; however, the subpattern \c{def} matches the subject string @@ -346,7 +346,7 @@ QT_BEGIN_NAMESPACE match), then the QRegularExpressionMatch object will report the first one that is found. For instance: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 18 + \snippet code/src_corelib_tools_qregularexpression.cpp 18 \section2 Incremental/multi-segment matching @@ -369,13 +369,13 @@ QT_BEGIN_NAMESPACE as soon as it is found, and other match alternatives are not tried (even if they could lead to a complete match). For instance: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 19 + \snippet code/src_corelib_tools_qregularexpression.cpp 19 This happens because when matching the first branch of the alternation operator a partial match is found, and therefore matching stops, without trying the second branch. Another example: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 20 + \snippet code/src_corelib_tools_qregularexpression.cpp 20 This shows what could seem a counterintuitve behaviour of quantifiers: since \c{?} is greedy, then the engine tries first to continue the match @@ -383,7 +383,7 @@ QT_BEGIN_NAMESPACE subject string, and therefore a partial match is reported. This is even more surprising in the following example: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 21 + \snippet code/src_corelib_tools_qregularexpression.cpp 21 It's easy to understand this behaviour if we remember that the engine expects the subject string to be only a substring of the whole text we're @@ -404,13 +404,13 @@ QT_BEGIN_NAMESPACE syntax errors in the pattern string. The isValid() function will return true if the regular expression is valid, or false otherwise: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 22 + \snippet code/src_corelib_tools_qregularexpression.cpp 22 You can get more information about the specific error by calling the errorString() function; moreover, the patternErrorOffset() function will return the offset inside the pattern string - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 23 + \snippet code/src_corelib_tools_qregularexpression.cpp 23 If a match is attempted with an invalid QRegularExpression, then the returned QRegularExpressionMatch object will be invalid as well (that is, @@ -455,19 +455,19 @@ QT_BEGIN_NAMESPACE putting the pattern between the \c{^} and the \c{$} anchors is enough in most cases: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 24 + \snippet code/src_corelib_tools_qregularexpression.cpp 24 However, remember that the \c{$} anchor not only matches at the end of the string, but also at a newline character right before the end of the string; that is, the previous pattern matches against the string "this pattern must - match exactly\n". Also, the behaviour of both the \c{^} and the \c{$} + match exactly\\n". Also, the behaviour of both the \c{^} and the \c{$} anchors changes if the MultiLineOption is set either explicitely (as a pattern option) or implicitly (as a directive inside the pattern string). Therefore, in the most general case, you should wrap the pattern between the \c{\A} and the \c{\z} anchors: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 25 + \snippet code/src_corelib_tools_qregularexpression.cpp 25 Note the usage of the non-capturing group in order to preserve the meaning of the branch operator inside the pattern. @@ -566,7 +566,7 @@ QT_BEGIN_NAMESPACE returns each substring captured, either by the capturing group's index or by its name: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 29 + \snippet code/src_corelib_tools_qregularexpression.cpp 29 For each captured substring it is possible to query its starting and ending offsets in the subject string by calling the capturedStart() and the @@ -616,7 +616,7 @@ QT_BEGIN_NAMESPACE For instance: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 30 + \snippet code/src_corelib_tools_qregularexpression.cpp 30 Moreover, QRegularExpressionMatchIterator offers a peekNext() function to get the next result \e{without} advancing the iterator. @@ -1590,11 +1590,11 @@ bool QRegularExpression::operator==(const QRegularExpression &re) const meaning when used as a regular expression pattern string, and returns the escaped string. For instance: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 26 + \snippet code/src_corelib_tools_qregularexpression.cpp 26 This is very convenient in order to build patterns from arbitrary strings: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 27 + \snippet code/src_corelib_tools_qregularexpression.cpp 27 \note This function implements Perl's quotemeta algorithm and escapes with a backslash all characters in \a str, except for the characters in the @@ -1721,7 +1721,7 @@ QRegularExpression::MatchOptions QRegularExpressionMatch::matchOptions() const including the implicit capturing group 0. This can be used to extract all the substrings that were captured: - \snippet doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp 28 + \snippet code/src_corelib_tools_qregularexpression.cpp 28 Note that some of the capturing groups with an index less than lastCapturedIndex() could have not matched, and therefore captured nothing. diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp index 5ecca89229..bf2cac453b 100644 --- a/src/corelib/tools/qscopedpointer.cpp +++ b/src/corelib/tools/qscopedpointer.cpp @@ -61,12 +61,12 @@ QT_BEGIN_NAMESPACE Consider this function which does heap allocations, and have various exit points: - \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 0 + \snippet code/src_corelib_tools_qscopedpointer.cpp 0 It's encumbered by the manual delete calls. With QScopedPointer, the code can be simplified to: - \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 1 + \snippet code/src_corelib_tools_qscopedpointer.cpp 1 The code the compiler generates for QScopedPointer is the same as when writing it manually. Code that makes use of \a delete are candidates for @@ -78,7 +78,7 @@ QT_BEGIN_NAMESPACE The const qualification on a regular C++ pointer can also be expressed with a QScopedPointer: - \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 2 + \snippet code/src_corelib_tools_qscopedpointer.cpp 2 \section1 Custom cleanup handlers @@ -99,7 +99,7 @@ QT_BEGIN_NAMESPACE You can pass your own classes as handlers, provided that they have a public static function \c{void cleanup(T *pointer)}. - \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 5 + \snippet code/src_corelib_tools_qscopedpointer.cpp 5 \section1 Forward Declared Pointers @@ -111,7 +111,7 @@ QT_BEGIN_NAMESPACE points to a forward declared class must have non-inline constructors, destructors and assignment operators: - \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 4 + \snippet code/src_corelib_tools_qscopedpointer.cpp 4 Otherwise, the compiler output a warning about not being able to destruct \c MyPrivateClass. @@ -168,7 +168,7 @@ QT_BEGIN_NAMESPACE Returns \c true if this object is not \c null. This function is suitable for use in \tt if-constructs, like: - \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 3 + \snippet code/src_corelib_tools_qscopedpointer.cpp 3 \sa isNull() */ diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc index b03cce884d..51d9caad70 100644 --- a/src/corelib/tools/qset.qdoc +++ b/src/corelib/tools/qset.qdoc @@ -40,19 +40,19 @@ Here's an example QSet with QString values: - \snippet doc/src/snippets/code/doc_src_qset.cpp 0 + \snippet code/doc_src_qset.cpp 0 To insert a value into the set, use insert(): - \snippet doc/src/snippets/code/doc_src_qset.cpp 1 + \snippet code/doc_src_qset.cpp 1 Another way to insert items into the set is to use operator<<(): - \snippet doc/src/snippets/code/doc_src_qset.cpp 2 + \snippet code/doc_src_qset.cpp 2 To test whether an item belongs to the set or not, use contains(): - \snippet doc/src/snippets/code/doc_src_qset.cpp 3 + \snippet code/doc_src_qset.cpp 3 If you want to navigate through all the values stored in a QSet, you can use an iterator. QSet supports both \l{Java-style @@ -60,18 +60,18 @@ iterators} (QSet::iterator and QSet::const_iterator). Here's how to iterate over a QSet using a Java-style iterator: - \snippet doc/src/snippets/code/doc_src_qset.cpp 4 + \snippet code/doc_src_qset.cpp 4 Here's the same code, but using an STL-style iterator: - \snippet doc/src/snippets/code/doc_src_qset.cpp 5 + \snippet code/doc_src_qset.cpp 5 QSet is unordered, so an iterator's sequence cannot be assumed to be predictable. If ordering by key is required, use a QMap. To navigate through a QSet, you can also use \l{foreach}: - \snippet doc/src/snippets/code/doc_src_qset.cpp 6 + \snippet code/doc_src_qset.cpp 6 Items can be removed from the set using remove(). There is also a clear() function that removes all items. @@ -194,7 +194,7 @@ This function is useful for code that needs to build a huge set and wants to avoid repeated reallocation. For example: - \snippet doc/src/snippets/code/doc_src_qset.cpp 7 + \snippet code/doc_src_qset.cpp 7 Ideally, \a size should be slightly more than the maximum number of elements expected in the set. \a size doesn't have to be prime, @@ -618,18 +618,18 @@ start iterating. Here's a typical loop that prints all the items stored in a set: - \snippet doc/src/snippets/code/doc_src_qset.cpp 8 + \snippet code/doc_src_qset.cpp 8 Here's a loop that removes certain items (all those that start with 'J') from a set while iterating: - \snippet doc/src/snippets/code/doc_src_qset.cpp 9 + \snippet code/doc_src_qset.cpp 9 STL-style iterators can be used as arguments to \l{generic algorithms}. For example, here's how to find an item in the set using the qFind() algorithm: - \snippet doc/src/snippets/code/doc_src_qset.cpp 10 + \snippet code/doc_src_qset.cpp 10 Multiple iterators can be used on the same set. However, you may not attempt to modify the container while iterating on it. @@ -661,13 +661,13 @@ start iterating. Here's a typical loop that prints all the items stored in a set: - \snippet doc/src/snippets/code/doc_src_qset.cpp 11 + \snippet code/doc_src_qset.cpp 11 STL-style iterators can be used as arguments to \l{generic algorithms}. For example, here's how to find an item in the set using the qFind() algorithm: - \snippet doc/src/snippets/code/doc_src_qset.cpp 12 + \snippet code/doc_src_qset.cpp 12 Multiple iterators can be used on the same set. However, you may not attempt to modify the container while iterating on it. @@ -901,7 +901,7 @@ Example: - \snippet doc/src/snippets/code/doc_src_qset.cpp 13 + \snippet code/doc_src_qset.cpp 13 \sa fromList(), QList::fromSet(), qSort() */ @@ -926,7 +926,7 @@ Example: - \snippet doc/src/snippets/code/doc_src_qset.cpp 14 + \snippet code/doc_src_qset.cpp 14 \sa toList(), QList::toSet() */ diff --git a/src/corelib/tools/qshareddata.cpp b/src/corelib/tools/qshareddata.cpp index ffc8ac601d..4c33bebd7b 100644 --- a/src/corelib/tools/qshareddata.cpp +++ b/src/corelib/tools/qshareddata.cpp @@ -99,7 +99,7 @@ QT_BEGIN_NAMESPACE implicitly shared \c Employee class. In the header file we define the two classes \c Employee and \c EmployeeData. - \snippet doc/src/snippets/sharedemployee/employee.h 0 + \snippet sharedemployee/employee.h 0 In class \c Employee, note the single data member, a \e {d pointer} of type \c {QSharedDataPointer}. All accesses of @@ -121,14 +121,14 @@ QT_BEGIN_NAMESPACE straightforward. Both create a new instance of \c EmployeeData and assign it to the \e{d pointer} . - \snippet doc/src/snippets/sharedemployee/employee.h 1 + \snippet sharedemployee/employee.h 1 \codeline - \snippet doc/src/snippets/sharedemployee/employee.h 2 + \snippet sharedemployee/employee.h 2 Note that class \c Employee also has a trivial copy constructor defined, which is not strictly required in this case. - \snippet doc/src/snippets/sharedemployee/employee.h 7 + \snippet sharedemployee/employee.h 7 The copy constructor is not strictly required here, because class \c EmployeeData is included in the same file as class \c Employee @@ -162,9 +162,9 @@ QT_BEGIN_NAMESPACE detach() to ensure that the function operates on its own copy of the data. - \snippet doc/src/snippets/sharedemployee/employee.h 3 + \snippet sharedemployee/employee.h 3 \codeline - \snippet doc/src/snippets/sharedemployee/employee.h 4 + \snippet sharedemployee/employee.h 4 Note that if detach() is called more than once in a member function due to multiple dereferences of the \e {d pointer}, detach() will @@ -180,9 +180,9 @@ QT_BEGIN_NAMESPACE In \c Employee's \e const member functions, dereferencing the \e {d pointer} does \e not cause detach() to be called. - \snippet doc/src/snippets/sharedemployee/employee.h 5 + \snippet sharedemployee/employee.h 5 \codeline - \snippet doc/src/snippets/sharedemployee/employee.h 6 + \snippet sharedemployee/employee.h 6 Notice that there is no need to implement a copy constructor or an assignment operator for the \c Employee class, because the copy @@ -199,7 +199,7 @@ QT_BEGIN_NAMESPACE Consider a simple example that creates two instances of the implicitly shared \c Employee class. - \snippet doc/src/snippets/sharedemployee/main.cpp 0 + \snippet sharedemployee/main.cpp 0 After the second employee e2 is created and e1 is assigned to it, both \c e1 and \c e2 refer to Albrecht Durer, employee 1001. Both \c diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp index b276d2d2e0..b4b99d26ff 100644 --- a/src/corelib/tools/qsize.cpp +++ b/src/corelib/tools/qsize.cpp @@ -194,7 +194,7 @@ void QSize::transpose() \endlist Example: - \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 0 + \snippet code/src_corelib_tools_qsize.cpp 0 \sa setWidth(), setHeight(), scaled() */ @@ -252,7 +252,7 @@ QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const Using a reference makes it possible to manipulate the width directly. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 1 + \snippet code/src_corelib_tools_qsize.cpp 1 \sa rheight(), setWidth() */ @@ -265,7 +265,7 @@ QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const Using a reference makes it possible to manipulate the height directly. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 2 + \snippet code/src_corelib_tools_qsize.cpp 2 \sa rwidth(), setHeight() */ @@ -276,7 +276,7 @@ QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const Adds the given \a size to \e this size, and returns a reference to this size. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 3 + \snippet code/src_corelib_tools_qsize.cpp 3 */ /*! @@ -285,7 +285,7 @@ QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const Subtracts the given \a size from \e this size, and returns a reference to this size. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 4 + \snippet code/src_corelib_tools_qsize.cpp 4 */ /*! @@ -622,7 +622,7 @@ void QSizeF::transpose() \endlist Example: - \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 5 + \snippet code/src_corelib_tools_qsize.cpp 5 \sa setWidth(), setHeight(), scaled() */ @@ -636,11 +636,11 @@ void QSizeF::transpose() */ /*! - \fn QSizeF QSizeF::scaled(int width, int height, Qt::AspectRatioMode mode) const + \fn QSizeF QSizeF::scaled(qreal width, qreal height, Qt::AspectRatioMode mode) const \since 5.0 Returns a size scaled to a rectangle with the given \a width and - \a height, according to the specified \mode. + \a height, according to the specified \a mode. \sa scale() */ @@ -679,7 +679,7 @@ QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Using a reference makes it possible to manipulate the width directly. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 6 + \snippet code/src_corelib_tools_qsize.cpp 6 \sa rheight(), setWidth() */ @@ -692,7 +692,7 @@ QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Using a reference makes it possible to manipulate the height directly. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 7 + \snippet code/src_corelib_tools_qsize.cpp 7 \sa rwidth(), setHeight() */ @@ -703,7 +703,7 @@ QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Adds the given \a size to this size and returns a reference to this size. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 8 + \snippet code/src_corelib_tools_qsize.cpp 8 */ /*! @@ -712,7 +712,7 @@ QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Subtracts the given \a size from this size and returns a reference to this size. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 9 + \snippet code/src_corelib_tools_qsize.cpp 9 */ /*! diff --git a/src/corelib/tools/qstack.cpp b/src/corelib/tools/qstack.cpp index 888fbfa0b4..359705887e 100644 --- a/src/corelib/tools/qstack.cpp +++ b/src/corelib/tools/qstack.cpp @@ -58,7 +58,7 @@ Example: - \snippet doc/src/snippets/qstack/main.cpp 0 + \snippet qstack/main.cpp 0 The example will output 3, 2, 1 in that order. diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index a536a091a1..a9373d79df 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -421,7 +421,7 @@ const QString::Null QString::null = { }; Most of the QChar member functions also exist in QCharRef. However, they are not explicitly documented here. - \sa QString::operator[]() QString::at() QChar + \sa QString::operator[](), QString::at(), QChar */ /*! @@ -467,7 +467,7 @@ const QString::Null QString::null = { }; *} to its constructor. For example, the following code creates a QString of size 5 containing the data "Hello": - \snippet doc/src/snippets/qstring/main.cpp 0 + \snippet qstring/main.cpp 0 QString converts the \c{const char *} data into Unicode using the fromAscii() function. fromAscii() treats ordinals above 128 as Latin-1 @@ -480,7 +480,7 @@ const QString::Null QString::null = { }; You can also provide string data as an array of \l{QChar}s: - \snippet doc/src/snippets/qstring/main.cpp 1 + \snippet qstring/main.cpp 1 QString makes a deep copy of the QChar data, so you can modify it later without experiencing side effects. (If for performance @@ -495,12 +495,12 @@ const QString::Null QString::null = { }; character that can be used on the left side of an assignment. For example: - \snippet doc/src/snippets/qstring/main.cpp 2 + \snippet qstring/main.cpp 2 For read-only access, an alternative syntax is to use the at() function: - \snippet doc/src/snippets/qstring/main.cpp 3 + \snippet qstring/main.cpp 3 The at() function can be faster than \l operator[](), because it never causes a \l{deep copy} to occur. Alternatively, use the @@ -519,7 +519,7 @@ const QString::Null QString::null = { }; usage. For example, if you want to compare a QString with a string literal, you can write code like this and it will work as expected: - \snippet doc/src/snippets/qstring/main.cpp 4 + \snippet qstring/main.cpp 4 You can also pass string literals to functions that take QStrings as arguments, invoking the QString(const char *) @@ -534,7 +534,7 @@ const QString::Null QString::null = { }; character data: append(), prepend(), insert(), replace(), and remove(). For example: - \snippet doc/src/snippets/qstring/main.cpp 5 + \snippet qstring/main.cpp 5 If you are building a QString gradually and know in advance approximately how many characters the QString will contain, you @@ -563,7 +563,7 @@ const QString::Null QString::null = { }; they return -1. For example, here's a typical loop that finds all occurrences of a particular substring: - \snippet doc/src/snippets/qstring/main.cpp 6 + \snippet qstring/main.cpp 6 QString provides many functions for converting numbers into strings and strings into numbers. See the arg() functions, the @@ -642,14 +642,14 @@ const QString::Null QString::null = { }; application is to add the following entry to your \l{qmake Project Files}{qmake project file}: - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 0 + \snippet code/src_corelib_tools_qstring.cpp 0 You then need to explicitly call fromAscii(), fromLatin1(), fromUtf8(), or fromLocal8Bit() to construct a QString from an 8-bit string, or use the lightweight QLatin1String class, for example: - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 1 + \snippet code/src_corelib_tools_qstring.cpp 1 Similarly, you must call toAscii(), toLatin1(), toUtf8(), or toLocal8Bit() explicitly to convert the QString to an 8-bit @@ -666,7 +666,7 @@ const QString::Null QString::null = { }; \l{implicitly shared}, QStrings may be treated like \c{int}s or other basic types. For example: - \snippet doc/src/snippets/qstring/main.cpp 7 + \snippet qstring/main.cpp 7 The \c result variable, is a normal variable allocated on the stack. When \c return is called, and because we're returning by @@ -685,7 +685,7 @@ const QString::Null QString::null = { }; string with size 0. A null string is always empty, but an empty string isn't necessarily null: - \snippet doc/src/snippets/qstring/main.cpp 8 + \snippet qstring/main.cpp 8 All functions except isNull() treat null strings the same as empty strings. For example, toAscii().constData() returns a pointer to a @@ -732,7 +732,7 @@ const QString::Null QString::null = { }; complex string from multiple substrings. You will often write code like this: - \snippet doc/src/snippets/qstring/stringbuilder.cpp 0 + \snippet qstring/stringbuilder.cpp 0 There is nothing wrong with either of these string constructions, but there are a few hidden inefficiencies. Beginning with Qt 4.6, @@ -770,13 +770,13 @@ const QString::Null QString::null = { }; \c{QStringBuilder} wherever you want to use it, and use the \c{'%'} operator instead of \c{'+'} when concatenating strings: - \snippet doc/src/snippets/qstring/stringbuilder.cpp 5 + \snippet qstring/stringbuilder.cpp 5 A more global approach which is the most convenient but not entirely source compatible, is to this define in your .pro file: - \snippet doc/src/snippets/qstring/stringbuilder.cpp 3 + \snippet qstring/stringbuilder.cpp 3 and the \c{'+'} will automatically be performed as the \c{QStringBuilder} \c{'%'} everywhere. @@ -1200,12 +1200,12 @@ void QString::free(Data *d) Example: - \snippet doc/src/snippets/qstring/main.cpp 45 + \snippet qstring/main.cpp 45 If you want to append a certain number of identical characters to the string, use \l operator+=() as follows rather than resize(): - \snippet doc/src/snippets/qstring/main.cpp 46 + \snippet qstring/main.cpp 46 If you want to expand the string so that it reaches a certain width and fill the new positions with a particular character, use @@ -1213,7 +1213,7 @@ void QString::free(Data *d) If \a size is negative, it is equivalent to passing zero. - \snippet doc/src/snippets/qstring/main.cpp 47 + \snippet qstring/main.cpp 47 \sa truncate(), reserve() */ @@ -1278,7 +1278,7 @@ void QString::resize(int size) we're fairly sure that size is large enough to make a call to reserve() worthwhile: - \snippet doc/src/snippets/qstring/main.cpp 44 + \snippet qstring/main.cpp 44 \sa squeeze(), capacity() */ @@ -1422,7 +1422,7 @@ QString &QString::operator=(QChar ch) Example: - \snippet doc/src/snippets/qstring/main.cpp 26 + \snippet qstring/main.cpp 26 If the given \a position is greater than size(), the array is first extended using resize(). @@ -1506,11 +1506,11 @@ QString& QString::insert(int i, QChar ch) Example: - \snippet doc/src/snippets/qstring/main.cpp 9 + \snippet qstring/main.cpp 9 This is the same as using the insert() function: - \snippet doc/src/snippets/qstring/main.cpp 10 + \snippet qstring/main.cpp 10 The append() function is typically very fast (\l{constant time}), because QString preallocates extra space at the end of the string @@ -1602,7 +1602,7 @@ QString &QString::append(QChar ch) Example: - \snippet doc/src/snippets/qstring/main.cpp 36 + \snippet qstring/main.cpp 36 \sa append(), insert() */ @@ -1657,7 +1657,7 @@ QString &QString::append(QChar ch) position + \a n is beyond the end of the string, the string is truncated at the specified \a position. - \snippet doc/src/snippets/qstring/main.cpp 37 + \snippet qstring/main.cpp 37 \sa insert(), replace() */ @@ -1708,7 +1708,7 @@ QString &QString::remove(const QString &str, Qt::CaseSensitivity cs) Example: - \snippet doc/src/snippets/qstring/main.cpp 38 + \snippet qstring/main.cpp 38 This is the same as \c replace(ch, "", cs). @@ -1741,7 +1741,7 @@ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) Removes every occurrence of the regular expression \a rx in the string, and returns a reference to the string. For example: - \snippet doc/src/snippets/qstring/main.cpp 39 + \snippet qstring/main.cpp 39 \sa indexOf(), lastIndexOf(), replace() */ @@ -1753,7 +1753,7 @@ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) Removes every occurrence of the regular expression \a re in the string, and returns a reference to the string. For example: - \snippet doc/src/snippets/qstring/main.cpp 96 + \snippet qstring/main.cpp 96 \sa indexOf(), lastIndexOf(), replace() */ @@ -1766,7 +1766,7 @@ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) Example: - \snippet doc/src/snippets/qstring/main.cpp 40 + \snippet qstring/main.cpp 40 \sa insert(), remove() */ @@ -1817,13 +1817,13 @@ QString &QString::replace(int pos, int len, QChar after) Example: - \snippet doc/src/snippets/qstring/main.cpp 41 + \snippet qstring/main.cpp 41 \note The replacement text is not rescanned after it is inserted. Example: - \snippet doc/src/snippets/qstring/main.cpp 86 + \snippet qstring/main.cpp 86 */ QString &QString::replace(const QString &before, const QString &after, Qt::CaseSensitivity cs) { @@ -2242,7 +2242,7 @@ bool QString::operator<(const QLatin1String &other) const \overload operator<() The \a other byte array is converted to a QString using the - fromAscii() function. If any NUL characters ('\0') are embedded + fromAscii() function. If any NUL characters ('\\0') are embedded in the byte array, they will be included in the transformation. You can disable this operator by defining \c @@ -2264,8 +2264,7 @@ bool QString::operator<(const QLatin1String &other) const go through QObject::tr(), for example. */ -/*! \fn bool operator<=(const QString &s1, const QString &s2) - \relates QString +/*! \fn bool QString::operator<=(const QString &s1, const QString &s2) Returns true if string \a s1 is lexically less than or equal to string \a s2; otherwise returns false. @@ -2286,7 +2285,7 @@ bool QString::operator<(const QLatin1String &other) const \overload operator<=() The \a other byte array is converted to a QString using the - fromAscii() function. If any NUL characters ('\0') are embedded + fromAscii() function. If any NUL characters ('\\0') are embedded in the byte array, they will be included in the transformation. You can disable this operator by defining \c @@ -2308,8 +2307,7 @@ bool QString::operator<(const QLatin1String &other) const go through QObject::tr(), for example. */ -/*! \fn bool operator>(const QString &s1, const QString &s2) - \relates QString +/*! \fn bool QString::operator>(const QString &s1, const QString &s2) Returns true if string \a s1 is lexically greater than string \a s2; otherwise returns false. @@ -2346,7 +2344,7 @@ bool QString::operator>(const QLatin1String &other) const \overload operator>() The \a other byte array is converted to a QString using the - fromAscii() function. If any NUL characters ('\0') are embedded + fromAscii() function. If any NUL characters ('\\0') are embedded in the byte array, they will be included in the transformation. You can disable this operator by defining \c @@ -2390,7 +2388,7 @@ bool QString::operator>(const QLatin1String &other) const \overload operator>=() The \a other byte array is converted to a QString using the - fromAscii() function. If any NUL characters ('\0') are embedded in + fromAscii() function. If any NUL characters ('\\0') are embedded in the byte array, they will be included in the transformation. You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII @@ -2434,7 +2432,7 @@ bool QString::operator>(const QLatin1String &other) const \overload operator!=() The \a other byte array is converted to a QString using the - fromAscii() function. If any NUL characters ('\0') are embedded + fromAscii() function. If any NUL characters ('\\0') are embedded in the byte array, they will be included in the transformation. You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII @@ -2466,7 +2464,7 @@ bool QString::operator>(const QLatin1String &other) const Example: - \snippet doc/src/snippets/qstring/main.cpp 24 + \snippet qstring/main.cpp 24 If \a from is -1, the search starts at the last character; if it is -2, at the next to last character and so on. @@ -2489,7 +2487,7 @@ int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const Example: - \snippet doc/src/snippets/qstring/main.cpp 24 + \snippet qstring/main.cpp 24 If \a from is -1, the search starts at the last character; if it is -2, at the next to last character and so on. @@ -2664,7 +2662,7 @@ static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *nee Example: - \snippet doc/src/snippets/qstring/main.cpp 29 + \snippet qstring/main.cpp 29 \sa indexOf(), contains(), count() */ @@ -2703,7 +2701,7 @@ int QString::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) c Example: - \snippet doc/src/snippets/qstring/main.cpp 29 + \snippet qstring/main.cpp 29 \sa indexOf(), contains(), count() */ @@ -2793,13 +2791,13 @@ struct QStringCapture string with \a after. Returns a reference to the string. For example: - \snippet doc/src/snippets/qstring/main.cpp 42 + \snippet qstring/main.cpp 42 For regular expressions containing \l{capturing parentheses}, occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced with \a{rx}.cap(1), cap(2), ... - \snippet doc/src/snippets/qstring/main.cpp 43 + \snippet qstring/main.cpp 43 \sa indexOf(), lastIndexOf(), remove(), QRegExp::cap() */ @@ -2951,13 +2949,13 @@ QString& QString::replace(const QRegExp &rx, const QString &after) string with \a after. Returns a reference to the string. For example: - \snippet doc/src/snippets/qstring/main.cpp 87 + \snippet qstring/main.cpp 87 For regular expressions containing capturing groups, - occurrences of \bold{\\1}, \bold{\\2}, ..., in \a after are replaced + occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced with the string captured by the corresponding capturing group. - \snippet doc/src/snippets/qstring/main.cpp 88 + \snippet qstring/main.cpp 88 \sa indexOf(), lastIndexOf(), remove(), QRegularExpression, QRegularExpressionMatch */ @@ -3125,7 +3123,7 @@ int QString::count(const QStringRef &str, Qt::CaseSensitivity cs) const case sensitive; otherwise the search is case insensitive. Example: - \snippet doc/src/snippets/qstring/main.cpp 17 + \snippet qstring/main.cpp 17 \sa indexOf(), count() */ @@ -3179,7 +3177,7 @@ int QString::count(const QStringRef &str, Qt::CaseSensitivity cs) const Example: - \snippet doc/src/snippets/qstring/main.cpp 25 + \snippet qstring/main.cpp 25 */ int QString::indexOf(const QRegExp& rx, int from) const { @@ -3200,7 +3198,7 @@ int QString::indexOf(const QRegExp& rx, int from) const Example: - \snippet doc/src/snippets/qstring/main.cpp 25 + \snippet qstring/main.cpp 25 */ int QString::indexOf(QRegExp& rx, int from) const { @@ -3216,7 +3214,7 @@ int QString::indexOf(QRegExp& rx, int from) const Example: - \snippet doc/src/snippets/qstring/main.cpp 30 + \snippet qstring/main.cpp 30 */ int QString::lastIndexOf(const QRegExp& rx, int from) const { @@ -3237,7 +3235,7 @@ int QString::lastIndexOf(const QRegExp& rx, int from) const Example: - \snippet doc/src/snippets/qstring/main.cpp 30 + \snippet qstring/main.cpp 30 */ int QString::lastIndexOf(QRegExp& rx, int from) const { @@ -3253,7 +3251,7 @@ int QString::lastIndexOf(QRegExp& rx, int from) const This function counts overlapping matches, so in the example below, there are four instances of "ana" or "ama": - \snippet doc/src/snippets/qstring/main.cpp 18 + \snippet qstring/main.cpp 18 */ int QString::count(const QRegExp& rx) const @@ -3284,7 +3282,7 @@ int QString::count(const QRegExp& rx) const Example: - \snippet doc/src/snippets/qstring/main.cpp 93 + \snippet qstring/main.cpp 93 */ int QString::indexOf(const QRegularExpression& re, int from) const { @@ -3310,7 +3308,7 @@ int QString::indexOf(const QRegularExpression& re, int from) const Example: - \snippet doc/src/snippets/qstring/main.cpp 94 + \snippet qstring/main.cpp 94 */ int QString::lastIndexOf(const QRegularExpression &re, int from) const { @@ -3361,7 +3359,7 @@ bool QString::contains(const QRegularExpression &re) const This function counts overlapping matches, so in the example below, there are four instances of "ana" or "ama": - \snippet doc/src/snippets/qstring/main.cpp 95 + \snippet qstring/main.cpp 95 */ int QString::count(const QRegularExpression &re) const { @@ -3436,13 +3434,13 @@ int QString::count(const QRegularExpression &re) const to skip empty fields and how to deal with leading and trailing separators; see \l{SectionFlags}. - \snippet doc/src/snippets/qstring/main.cpp 52 + \snippet qstring/main.cpp 52 If \a start or \a end is negative, we count fields from the right of the string, the right-most field being -1, the one from right-most field being -2, and so on. - \snippet doc/src/snippets/qstring/main.cpp 53 + \snippet qstring/main.cpp 53 \sa split() */ @@ -3450,8 +3448,8 @@ int QString::count(const QRegularExpression &re) const /*! \overload section() - \snippet doc/src/snippets/qstring/main.cpp 51 - \snippet doc/src/snippets/qstring/main.cpp 54 + \snippet qstring/main.cpp 51 + \snippet qstring/main.cpp 54 \sa split() */ @@ -3560,12 +3558,12 @@ static QString extractSections(const QList §ions, This string is treated as a sequence of fields separated by the regular expression, \a reg. - \snippet doc/src/snippets/qstring/main.cpp 55 + \snippet qstring/main.cpp 55 \warning Using this QRegExp version is much more expensive than the overloaded string and character versions. - \sa split() simplified() + \sa split(), simplified() */ QString QString::section(const QRegExp ®, int start, int end, SectionFlags flags) const { @@ -3600,12 +3598,12 @@ QString QString::section(const QRegExp ®, int start, int end, SectionFlags fl This string is treated as a sequence of fields separated by the regular expression, \a re. - \snippet doc/src/snippets/qstring/main.cpp 89 + \snippet qstring/main.cpp 89 \warning Using this QRegularExpression version is much more expensive than the overloaded string and character versions. - \sa split() simplified() + \sa split(), simplified() */ QString QString::section(const QRegularExpression &re, int start, int end, SectionFlags flags) const { @@ -3646,7 +3644,7 @@ QString QString::section(const QRegularExpression &re, int start, int end, Secti The entire string is returned if \a n is greater than size() or less than zero. - \snippet doc/src/snippets/qstring/main.cpp 31 + \snippet qstring/main.cpp 31 \sa right(), mid(), startsWith() */ @@ -3664,7 +3662,7 @@ QString QString::left(int n) const The entire string is returned if \a n is greater than size() or less than zero. - \snippet doc/src/snippets/qstring/main.cpp 48 + \snippet qstring/main.cpp 48 \sa left(), mid(), endsWith() */ @@ -3687,7 +3685,7 @@ QString QString::right(int n) const Example: - \snippet doc/src/snippets/qstring/main.cpp 34 + \snippet qstring/main.cpp 34 \sa left(), right() */ @@ -3718,7 +3716,7 @@ QString QString::mid(int position, int n) const If \a cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive. - \snippet doc/src/snippets/qstring/main.cpp 65 + \snippet qstring/main.cpp 65 \sa endsWith() */ @@ -3774,7 +3772,7 @@ bool QString::startsWith(const QStringRef &s, Qt::CaseSensitivity cs) const If \a cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive. - \snippet doc/src/snippets/qstring/main.cpp 20 + \snippet qstring/main.cpp 20 \sa startsWith() */ @@ -4280,7 +4278,7 @@ QString& QString::setUnicode(const QChar *unicode, int size) Example: - \snippet doc/src/snippets/qstring/main.cpp 57 + \snippet qstring/main.cpp 57 \sa trimmed() */ @@ -4370,7 +4368,7 @@ QString QString::simplified() const Example: - \snippet doc/src/snippets/qstring/main.cpp 82 + \snippet qstring/main.cpp 82 Unlike simplified(), trimmed() leaves internal whitespace alone. @@ -4418,7 +4416,7 @@ QString QString::trimmed() const Example: - \snippet doc/src/snippets/qstring/main.cpp 85 + \snippet qstring/main.cpp 85 The return value is of type QCharRef, a helper class for QString. When you get an object of type QCharRef, you can use it as if it @@ -4457,7 +4455,7 @@ modifiable reference. Equivalent to \c at(position). Example: - \snippet doc/src/snippets/qstring/main.cpp 83 + \snippet qstring/main.cpp 83 If \a position is negative, it is equivalent to passing zero. @@ -4477,7 +4475,7 @@ void QString::truncate(int pos) If \a n is greater than size(), the result is an empty string. Example: - \snippet doc/src/snippets/qstring/main.cpp 15 + \snippet qstring/main.cpp 15 If you want to remove characters from the \e beginning of the string, use remove() instead. @@ -4497,7 +4495,7 @@ void QString::chop(int n) Example: - \snippet doc/src/snippets/qstring/main.cpp 21 + \snippet qstring/main.cpp 21 \sa resize() */ @@ -4536,7 +4534,7 @@ QString& QString::fill(QChar ch, int size) Example: - \snippet doc/src/snippets/qstring/main.cpp 58 + \snippet qstring/main.cpp 58 \sa isEmpty(), resize() */ @@ -4547,7 +4545,7 @@ QString& QString::fill(QChar ch, int size) Example: - \snippet doc/src/snippets/qstring/main.cpp 28 + \snippet qstring/main.cpp 28 Qt makes a distinction between null strings and empty strings for historical reasons. For most applications, what matters is @@ -4564,7 +4562,7 @@ QString& QString::fill(QChar ch, int size) Example: - \snippet doc/src/snippets/qstring/main.cpp 27 + \snippet qstring/main.cpp 27 \sa size() */ @@ -4576,7 +4574,7 @@ QString& QString::fill(QChar ch, int size) Example: - \snippet doc/src/snippets/qstring/main.cpp 84 + \snippet qstring/main.cpp 84 This operation is typically very fast (\l{constant time}), because QString preallocates extra space at the end of the string @@ -4598,7 +4596,7 @@ QString& QString::fill(QChar ch, int size) \overload operator+=() Appends the byte array \a ba to this string. The byte array is converted - to Unicode using the fromAscii() function. If any NUL characters ('\0') + to Unicode using the fromAscii() function. If any NUL characters ('\\0') are embedded in the \a ba byte array, they will be included in the transformation. @@ -4805,7 +4803,7 @@ QString& QString::fill(QChar ch, int size) a human would expect. Consider sorting user-visible strings with localeAwareCompare(). - \snippet doc/src/snippets/qstring/main.cpp 16 + \snippet qstring/main.cpp 16 \sa operator==(), operator<(), operator>() */ @@ -5089,13 +5087,13 @@ const ushort *QString::utf16() const If \a truncate is false and the size() of the string is more than \a width, then the returned string is a copy of the string. - \snippet doc/src/snippets/qstring/main.cpp 32 + \snippet qstring/main.cpp 32 If \a truncate is true and the size() of the string is more than \a width, then any characters in a copy of the string after position \a width are removed, and the copy is returned. - \snippet doc/src/snippets/qstring/main.cpp 33 + \snippet qstring/main.cpp 33 \sa rightJustified() */ @@ -5125,7 +5123,7 @@ QString QString::leftJustified(int width, QChar fill, bool truncate) const Returns a string of size() \a width that contains the \a fill character followed by the string. For example: - \snippet doc/src/snippets/qstring/main.cpp 49 + \snippet qstring/main.cpp 49 If \a truncate is false and the size() of the string is more than \a width, then the returned string is a copy of the string. @@ -5134,7 +5132,7 @@ QString QString::leftJustified(int width, QChar fill, bool truncate) const \a width, then the resulting string is truncated at position \a width. - \snippet doc/src/snippets/qstring/main.cpp 50 + \snippet qstring/main.cpp 50 \sa leftJustified() */ @@ -5163,7 +5161,7 @@ QString QString::rightJustified(int width, QChar fill, bool truncate) const /*! Returns a lowercase copy of the string. - \snippet doc/src/snippets/qstring/main.cpp 75 + \snippet qstring/main.cpp 75 The case conversion will always happen in the 'C' locale. For locale dependent case folding use QLocale::toLower() @@ -5286,7 +5284,7 @@ QString QString::toCaseFolded() const /*! Returns an uppercase copy of the string. - \snippet doc/src/snippets/qstring/main.cpp 81 + \snippet qstring/main.cpp 81 The case conversion will always happen in the 'C' locale. For locale dependent case folding use QLocale::toUpper() @@ -5369,14 +5367,14 @@ QString QString::toUpper() const \c{long long}). If you need those, use the standard snprintf() function instead: - \snippet doc/src/snippets/qstring/main.cpp 63 + \snippet qstring/main.cpp 63 \warning We do not recommend using QString::sprintf() in new Qt code. Instead, consider using QTextStream or arg(), both of which support Unicode strings seamlessly and are type-safe. Here's an example that uses QTextStream: - \snippet doc/src/snippets/qstring/main.cpp 64 + \snippet qstring/main.cpp 64 For \l {QObject::tr()}{translations}, especially if the strings contains more than one escape sequence, you should consider using @@ -5749,7 +5747,7 @@ QString &QString::vsprintf(const char* cformat, va_list ap) Example: - \snippet doc/src/snippets/qstring/main.cpp 74 + \snippet qstring/main.cpp 74 \sa number(), toULongLong(), toInt(), QLocale::toLongLong() */ @@ -5784,7 +5782,7 @@ qint64 QString::toLongLong(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 79 + \snippet qstring/main.cpp 79 \sa number(), toLongLong(), QLocale::toULongLong() */ @@ -5821,7 +5819,7 @@ quint64 QString::toULongLong(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 73 + \snippet qstring/main.cpp 73 \sa number(), toULong(), toInt(), QLocale::toLong() */ @@ -5856,7 +5854,7 @@ long QString::toLong(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 78 + \snippet qstring/main.cpp 78 \sa number(), QLocale::toULong() */ @@ -5890,7 +5888,7 @@ ulong QString::toULong(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 72 + \snippet qstring/main.cpp 72 \sa number(), toUInt(), toDouble(), QLocale::toInt() */ @@ -5923,7 +5921,7 @@ int QString::toInt(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 77 + \snippet qstring/main.cpp 77 \sa number(), toInt(), QLocale::toUInt() */ @@ -5956,7 +5954,7 @@ uint QString::toUInt(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 76 + \snippet qstring/main.cpp 76 \sa number(), toUShort(), toInt(), QLocale::toShort() */ @@ -5989,7 +5987,7 @@ short QString::toShort(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 80 + \snippet qstring/main.cpp 80 \sa number(), toShort(), QLocale::toUShort() */ @@ -6014,25 +6012,25 @@ ushort QString::toUShort(bool *ok, int base) const If a conversion error occurs, \c{*}\a{ok} is set to false; otherwise \c{*}\a{ok} is set to true. - \snippet doc/src/snippets/qstring/main.cpp 66 + \snippet qstring/main.cpp 66 Various string formats for floating point numbers can be converted to double values: - \snippet doc/src/snippets/qstring/main.cpp 67 + \snippet qstring/main.cpp 67 The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toDouble() - \snippet doc/src/snippets/qstring/main.cpp 68 + \snippet qstring/main.cpp 68 For historic reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toDouble(). - \snippet doc/src/snippets/qstring/main.cpp 69 + \snippet qstring/main.cpp 69 - \sa number() QLocale::setDefault() QLocale::toDouble() trimmed() + \sa number(), QLocale::setDefault(), QLocale::toDouble(), trimmed() */ double QString::toDouble(bool *ok) const @@ -6052,7 +6050,7 @@ double QString::toDouble(bool *ok) const Example: - \snippet doc/src/snippets/qstring/main.cpp 71 + \snippet qstring/main.cpp 71 \sa number(), toDouble(), toInt(), QLocale::toFloat() */ @@ -6081,7 +6079,7 @@ float QString::toFloat(bool *ok) const The base is 10 by default and must be between 2 and 36. For bases other than 10, \a n is treated as an unsigned integer. - \snippet doc/src/snippets/qstring/main.cpp 56 + \snippet qstring/main.cpp 56 The formatting always uses QLocale::C, i.e., English/UnitedStates. To get a localized string representation of a number, use @@ -6220,7 +6218,7 @@ QString &QString::setNum(double n, char f, int prec) To get a localized string representation of a number, use QLocale::toString() with the appropriate locale. - \snippet doc/src/snippets/qstring/main.cpp 35 + \snippet qstring/main.cpp 35 \sa setNum() */ @@ -6318,7 +6316,7 @@ QString QString::number(double n, char f, int prec) Example: - \snippet doc/src/snippets/qstring/main.cpp 62 + \snippet qstring/main.cpp 62 \sa QStringList::join(), section() */ @@ -6369,18 +6367,18 @@ QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivit Here's an example where we extract the words in a sentence using one or more whitespace characters as the separator: - \snippet doc/src/snippets/qstring/main.cpp 59 + \snippet qstring/main.cpp 59 Here's a similar example, but this time we use any sequence of non-word characters as the separator: - \snippet doc/src/snippets/qstring/main.cpp 60 + \snippet qstring/main.cpp 60 Here's a third example where we use a zero-length assertion, \b{\\b} (word boundary), to split the string into an alternating sequence of non-word and word tokens: - \snippet doc/src/snippets/qstring/main.cpp 61 + \snippet qstring/main.cpp 61 \sa QStringList::join(), section() */ @@ -6418,18 +6416,18 @@ QStringList QString::split(const QRegExp &rx, SplitBehavior behavior) const Here's an example where we extract the words in a sentence using one or more whitespace characters as the separator: - \snippet doc/src/snippets/qstring/main.cpp 90 + \snippet qstring/main.cpp 90 Here's a similar example, but this time we use any sequence of non-word characters as the separator: - \snippet doc/src/snippets/qstring/main.cpp 91 + \snippet qstring/main.cpp 91 Here's a third example where we use a zero-length assertion, - \bold{\\b} (word boundary), to split the string into an + \b{\\b} (word boundary), to split the string into an alternating sequence of non-word and word tokens: - \snippet doc/src/snippets/qstring/main.cpp 92 + \snippet qstring/main.cpp 92 \sa QStringList::join(), section() */ @@ -6770,7 +6768,7 @@ static QString replaceArgEscapes(const QString &s, const ArgEscapeData &d, int f This example shows how we might create a \c status string for reporting progress while processing a list of files: - \snippet doc/src/snippets/qstring/main.cpp 11 + \snippet qstring/main.cpp 11 First, \c arg(i) replaces \c %1. Then \c arg(total) replaces \c %2. Finally, \c arg(fileName) replaces \c %3. @@ -6806,7 +6804,7 @@ QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const strings \a a1 and \a a2 are replaced in one pass. This can make a difference if \a a1 contains e.g. \c{%1}: - \snippet doc/src/snippets/qstring/main.cpp 13 + \snippet qstring/main.cpp 13 */ /*! @@ -6893,8 +6891,8 @@ QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const locale was specified, the "C" locale is used. The 'L' flag is ignored if \a base is not 10. - \snippet doc/src/snippets/qstring/main.cpp 12 - \snippet doc/src/snippets/qstring/main.cpp 14 + \snippet qstring/main.cpp 12 + \snippet qstring/main.cpp 14 If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the @@ -6930,8 +6928,8 @@ QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const using QLocale::setDefault(). The 'L' flag is ignored if \a base is not 10. - \snippet doc/src/snippets/qstring/main.cpp 12 - \snippet doc/src/snippets/qstring/main.cpp 14 + \snippet qstring/main.cpp 12 + \snippet qstring/main.cpp 14 If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the @@ -7114,7 +7112,7 @@ QString QString::arg(char a, int fieldWidth, QChar fillChar) const value produces right-aligned text; a negative value produces left-aligned text. - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 2 + \snippet code/src_corelib_tools_qstring.cpp 2 The '%' can be followed by an 'L', in which case the sequence is replaced with a localized representation of \a a. The conversion @@ -7310,7 +7308,7 @@ bool QString::isRightToLeft() const Example: - \snippet doc/src/snippets/qstring/main.cpp 19 + \snippet qstring/main.cpp 19 Note that the pointer remains valid only as long as the string is not modified by other means. For read-only access, constData() is @@ -7398,8 +7396,8 @@ bool QString::isRightToLeft() const Here's an example of how we can use a QRegExp on raw data in memory without requiring to copy the data into a QString: - \snippet doc/src/snippets/qstring/main.cpp 22 - \snippet doc/src/snippets/qstring/main.cpp 23 + \snippet qstring/main.cpp 22 + \snippet qstring/main.cpp 23 \warning A string created with fromRawData() is \e not '\\0'-terminated, unless the raw data contains a '\\0' character @@ -7475,11 +7473,11 @@ QString &QString::setRawData(const QChar *unicode, int size) the \c{const char *} data. For example, assuming \c str is a QString, - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 3 + \snippet code/src_corelib_tools_qstring.cpp 3 is much faster than - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 4 + \snippet code/src_corelib_tools_qstring.cpp 4 because it doesn't construct four temporary QString objects and make a deep copy of the character data. @@ -7491,7 +7489,7 @@ QString &QString::setRawData(const QChar *unicode, int size) just a very thin wrapper around a \c{const char *}. Using QLatin1String, the example code above becomes - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 5 + \snippet code/src_corelib_tools_qstring.cpp 5 This is a bit longer to type, but it provides exactly the same benefits as the first version of the code, and is faster than @@ -7501,7 +7499,7 @@ QString &QString::setRawData(const QChar *unicode, int size) QLatin1String can be used everywhere a QString is expected. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 6 + \snippet code/src_corelib_tools_qstring.cpp 6 \sa QString, QLatin1Char, QStringLiteral */ @@ -8369,7 +8367,7 @@ QString &QString::append(const QStringRef &str) If \a n is greater than size() or less than zero, a reference to the entire string is returned. - \snippet doc/src/snippets/qstring/main.cpp leftRef + \snippet qstring/main.cpp leftRef \sa left(), rightRef(), midRef(), startsWith() */ @@ -8389,7 +8387,7 @@ QStringRef QString::leftRef(int n) const If \a n is greater than size() or less than zero, a reference to the entire string is returned. - \snippet doc/src/snippets/qstring/main.cpp rightRef + \snippet qstring/main.cpp rightRef \sa right(), leftRef(), midRef(), endsWith() */ @@ -8416,7 +8414,7 @@ QStringRef QString::rightRef(int n) const Example: - \snippet doc/src/snippets/qstring/main.cpp midRef + \snippet qstring/main.cpp midRef \sa mid(), leftRef(), rightRef() */ @@ -9160,7 +9158,7 @@ QVector QStringRef::toUcs4() const Example: - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 7 + \snippet code/src_corelib_tools_qstring.cpp 7 */ QString QString::toHtmlEscaped() const { diff --git a/src/corelib/tools/qstringbuilder.cpp b/src/corelib/tools/qstringbuilder.cpp index 6999972172..a044cca3c9 100644 --- a/src/corelib/tools/qstringbuilder.cpp +++ b/src/corelib/tools/qstringbuilder.cpp @@ -95,7 +95,7 @@ QT_BEGIN_NAMESPACE \c QChar, \c QCharRef, \c QLatin1Char, and \c char. */ -/*! \fn QByteArray QStringBuilder::toLatin1() const +/* \fn QByteArray QStringBuilder::toLatin1() const Returns a Latin-1 representation of the string as a QByteArray. The returned byte array is undefined if the string contains non-Latin1 characters. diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index bfe2c5ec2d..c25d326b9d 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -102,7 +102,7 @@ QT_BEGIN_NAMESPACE {QList::operator+=()}{operator+=()} and \l {QStringList::operator<<()}{operator<<()} functions. For example: - \snippet doc/src/snippets/qstringlist/main.cpp 0 + \snippet qstringlist/main.cpp 0 \section1 Iterating over the strings @@ -111,15 +111,15 @@ QT_BEGIN_NAMESPACE Indexing: - \snippet doc/src/snippets/qstringlist/main.cpp 1 + \snippet qstringlist/main.cpp 1 Java-style iterator: - \snippet doc/src/snippets/qstringlist/main.cpp 2 + \snippet qstringlist/main.cpp 2 STL-style iterator: - \snippet doc/src/snippets/qstringlist/main.cpp 3 + \snippet qstringlist/main.cpp 3 The QStringListIterator class is simply a type definition for QListIterator. QStringList also provide the @@ -133,12 +133,12 @@ QT_BEGIN_NAMESPACE string list into a single string (with an optional separator) using the join() function. For example: - \snippet doc/src/snippets/qstringlist/main.cpp 4 + \snippet qstringlist/main.cpp 4 To break up a string into a string list, use the QString::split() function: - \snippet doc/src/snippets/qstringlist/main.cpp 6 + \snippet qstringlist/main.cpp 6 The argument to split can be a single character, a string, or a QRegExp. @@ -152,7 +152,7 @@ QT_BEGIN_NAMESPACE contain a particular substring (or match a particular regular expression): - \snippet doc/src/snippets/qstringlist/main.cpp 7 + \snippet qstringlist/main.cpp 7 The contains() function tells you whether the list contains a given string, while the indexOf() function returns the index of @@ -163,7 +163,7 @@ QT_BEGIN_NAMESPACE Finally, the replaceInStrings() function calls QString::replace() on each string in the string list in turn. For example: - \snippet doc/src/snippets/qstringlist/main.cpp 8 + \snippet qstringlist/main.cpp 8 \sa QString */ @@ -180,7 +180,7 @@ QT_BEGIN_NAMESPACE Constructs a string list that contains the given string, \a str. Longer lists are easily created like this: - \snippet doc/src/snippets/qstringlist/main.cpp 9 + \snippet qstringlist/main.cpp 9 \sa append() */ @@ -255,13 +255,13 @@ void QtPrivate::QStringList_sort(QStringList *that, Qt::CaseSensitivity cs) comparison is case sensitive; otherwise the comparison is case insensitive. - \snippet doc/src/snippets/qstringlist/main.cpp 5 - \snippet doc/src/snippets/qstringlist/main.cpp 10 + \snippet qstringlist/main.cpp 5 + \snippet qstringlist/main.cpp 10 This is equivalent to - \snippet doc/src/snippets/qstringlist/main.cpp 11 - \snippet doc/src/snippets/qstringlist/main.cpp 12 + \snippet qstringlist/main.cpp 11 + \snippet qstringlist/main.cpp 12 \sa contains() */ @@ -348,8 +348,8 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegula For example: - \snippet doc/src/snippets/qstringlist/main.cpp 5 - \snippet doc/src/snippets/qstringlist/main.cpp 13 + \snippet qstringlist/main.cpp 5 + \snippet qstringlist/main.cpp 13 \sa QString::replace() */ @@ -372,8 +372,8 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QString &b For example: - \snippet doc/src/snippets/qstringlist/main.cpp 5 - \snippet doc/src/snippets/qstringlist/main.cpp 14 + \snippet qstringlist/main.cpp 5 + \snippet qstringlist/main.cpp 14 For regular expressions that contain \l{capturing parentheses}, occurrences of \b{\\1}, \b{\\2}, ..., in \a after are @@ -381,8 +381,8 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QString &b For example: - \snippet doc/src/snippets/qstringlist/main.cpp 5 - \snippet doc/src/snippets/qstringlist/main.cpp 15 + \snippet qstringlist/main.cpp 5 + \snippet qstringlist/main.cpp 15 */ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegExp &rx, const QString &after) { diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp index f0d8c248b4..0c1ed4de84 100644 --- a/src/corelib/tools/qtimeline.cpp +++ b/src/corelib/tools/qtimeline.cpp @@ -182,7 +182,7 @@ void QTimeLinePrivate::setCurrentTime(int msecs) Example: - \snippet doc/src/snippets/code/src_corelib_tools_qtimeline.cpp 0 + \snippet code/src_corelib_tools_qtimeline.cpp 0 You can also use QTimeLine with the \l{Graphics View}{Graphics View framework} for diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc index e92f91aa47..748126012b 100644 --- a/src/corelib/tools/qvarlengtharray.qdoc +++ b/src/corelib/tools/qvarlengtharray.qdoc @@ -35,12 +35,12 @@ The C++ language doesn't support variable-length arrays on the stack. For example, the following code won't compile: - \snippet doc/src/snippets/code/doc_src_qvarlengtharray.cpp 0 + \snippet code/doc_src_qvarlengtharray.cpp 0 The alternative is to allocate the array on the heap (with \c{new}): - \snippet doc/src/snippets/code/doc_src_qvarlengtharray.cpp 1 + \snippet code/doc_src_qvarlengtharray.cpp 1 However, if myfunc() is called very frequently from the application's inner loop, heap allocation can be a major source @@ -53,7 +53,7 @@ it is much faster than heap allocation. Example: - \snippet doc/src/snippets/code/doc_src_qvarlengtharray.cpp 2 + \snippet code/doc_src_qvarlengtharray.cpp 2 In the example above, QVarLengthArray will preallocate 1024 elements on the stack and use them unless \c{n + 1} is greater @@ -260,7 +260,7 @@ be used to access and modify the items in the array. Example: - \snippet doc/src/snippets/code/doc_src_qvarlengtharray.cpp 3 + \snippet code/doc_src_qvarlengtharray.cpp 3 The pointer remains valid as long as the array isn't reallocated. diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp index 0026338047..20501f98ff 100644 --- a/src/corelib/tools/qvector.cpp +++ b/src/corelib/tools/qvector.cpp @@ -119,20 +119,20 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) Here's an example of a QVector that stores integers and a QVector that stores QString values: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 0 + \snippet code/src_corelib_tools_qvector.cpp 0 QVector stores a vector (or array) of items. Typically, vectors are created with an initial size. For example, the following code constructs a QVector with 200 elements: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 1 + \snippet code/src_corelib_tools_qvector.cpp 1 The elements are automatically initialized with a \l{default-constructed value}. If you want to initialize the vector with a different value, pass that value as the second argument to the constructor: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 2 + \snippet code/src_corelib_tools_qvector.cpp 2 You can also call fill() at any time to fill the vector with a value. @@ -142,11 +142,11 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) non-const vectors, operator[]() returns a reference to the item that can be used on the left side of an assignment: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 3 + \snippet code/src_corelib_tools_qvector.cpp 3 For read-only access, an alternative syntax is to use at(): - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 4 + \snippet code/src_corelib_tools_qvector.cpp 4 at() can be faster than operator[](), because it never causes a \l{deep copy} to occur. @@ -164,7 +164,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) backward. Both return the index of the matching item if they found one; otherwise, they return -1. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 5 + \snippet code/src_corelib_tools_qvector.cpp 5 If you simply want to check whether a vector contains a particular value, use contains(). If you want to find out how @@ -411,7 +411,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) can be used to access and modify the items in the vector. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 6 + \snippet code/src_corelib_tools_qvector.cpp 6 The pointer remains valid as long as the vector isn't reallocated. @@ -482,7 +482,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) Inserts \a value at the end of the vector. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 7 + \snippet code/src_corelib_tools_qvector.cpp 7 This is the same as calling resize(size() + 1) and assigning \a value to the new last element in the vector. @@ -499,7 +499,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) Inserts \a value at the beginning of the vector. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 8 + \snippet code/src_corelib_tools_qvector.cpp 8 This is the same as vector.insert(0, \a value). @@ -519,7 +519,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) value is appended to the vector. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 9 + \snippet code/src_corelib_tools_qvector.cpp 9 For large vectors, this operation can be slow (\l{linear time}), because it requires moving all the items at indexes \a i and @@ -538,7 +538,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) vector. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 10 + \snippet code/src_corelib_tools_qvector.cpp 10 */ /*! \fn QVector::iterator QVector::insert(iterator before, const T &value) @@ -592,7 +592,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) size beforehand. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 11 + \snippet code/src_corelib_tools_qvector.cpp 11 \sa resize() */ @@ -604,7 +604,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) Returns -1 if no item matched. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 12 + \snippet code/src_corelib_tools_qvector.cpp 12 This function requires the value type to have an implementation of \c operator==(). @@ -620,7 +620,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) last item. Returns -1 if no item matched. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 13 + \snippet code/src_corelib_tools_qvector.cpp 13 This function requires the value type to have an implementation of \c operator==(). @@ -966,7 +966,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 14 + \snippet code/src_corelib_tools_qvector.cpp 14 \sa fromList(), QList::fromVector() */ @@ -977,7 +977,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 15 + \snippet code/src_corelib_tools_qvector.cpp 15 \sa toList(), QList::toVector() */ @@ -989,7 +989,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 16 + \snippet code/src_corelib_tools_qvector.cpp 16 \sa toStdVector(), QList::fromStdList() */ @@ -999,7 +999,7 @@ int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT) Returns a std::vector object with the data contained in this QVector. Example: - \snippet doc/src/snippets/code/src_corelib_tools_qvector.cpp 17 + \snippet code/src_corelib_tools_qvector.cpp 17 \sa fromStdVector(), QList::toStdList() */ diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index df2c2f998f..769cdc9495 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -291,7 +291,7 @@ QXmlStreamEntityResolver *QXmlStreamReader::entityResolver() const A typical loop with QXmlStreamReader looks like this: - \snippet doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp 0 + \snippet code/src_corelib_xml_qxmlstream.cpp 0 QXmlStreamReader is a well-formed XML 1.0 parser that does \e not @@ -2900,11 +2900,11 @@ QStringRef QXmlStreamReader::documentEncoding() const The following abridged code snippet shows the basic use of the class to write formatted XML with indentation: - \snippet doc/src/snippets/qxmlstreamwriter/main.cpp start stream + \snippet qxmlstreamwriter/main.cpp start stream \dots - \snippet doc/src/snippets/qxmlstreamwriter/main.cpp write element + \snippet qxmlstreamwriter/main.cpp write element \dots - \snippet doc/src/snippets/qxmlstreamwriter/main.cpp finish stream + \snippet qxmlstreamwriter/main.cpp finish stream QXmlStreamWriter takes care of prefixing namespaces, all you have to do is specify the \c namespaceUri when writing elements or @@ -3561,7 +3561,7 @@ void QXmlStreamWriter::writeEmptyElement(const QString &namespaceUri, const QStr This is a convenience function equivalent to: - \snippet doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp 1 + \snippet code/src_corelib_xml_qxmlstream.cpp 1 */ void QXmlStreamWriter::writeTextElement(const QString &qualifiedName, const QString &text) @@ -3578,7 +3578,7 @@ void QXmlStreamWriter::writeTextElement(const QString &qualifiedName, const QStr This is a convenience function equivalent to: - \snippet doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp 2 + \snippet code/src_corelib_xml_qxmlstream.cpp 2 */ void QXmlStreamWriter::writeTextElement(const QString &namespaceUri, const QString &name, const QString &text) diff --git a/src/corelib/xml/qxmlutils.cpp b/src/corelib/xml/qxmlutils.cpp index 7ec208816c..89912b42fa 100644 --- a/src/corelib/xml/qxmlutils.cpp +++ b/src/corelib/xml/qxmlutils.cpp @@ -227,7 +227,7 @@ bool QXmlUtils::isBaseChar(const QChar c) Determines whether \a encName is a valid instance of production [81]EncName in the XML 1.0 specification. If it is, true is returned, otherwise false. - \sa \l {http://www.w3.org/TR/REC-xml/#NT-EncName} + \sa {http://www.w3.org/TR/REC-xml/#NT-EncName}, {Extensible Markup Language (XML) 1.0 (Fourth Edition), [81] EncName} */ bool QXmlUtils::isEncName(const QString &encName) @@ -248,7 +248,7 @@ bool QXmlUtils::isEncName(const QString &encName) Determines whether \a c is a valid instance of production [84]Letter in the XML 1.0 specification. If it is, true is returned, otherwise false. - \sa \l {http://www.w3.org/TR/REC-xml/#NT-Letter} + \sa {http://www.w3.org/TR/REC-xml/#NT-Letter}, {Extensible Markup Language (XML) 1.0 (Fourth Edition), [84] Letter} */ bool QXmlUtils::isLetter(const QChar c) @@ -262,7 +262,7 @@ bool QXmlUtils::isLetter(const QChar c) Determines whether \a c is a valid instance of production [2]Char in the XML 1.0 specification. If it is, true is returned, otherwise false. - \sa \l {http://www.w3.org/TR/REC-xml/#NT-Char} + \sa {http://www.w3.org/TR/REC-xml/#NT-Char}, {Extensible Markup Language (XML) 1.0 (Fourth Edition), [2] Char} */ bool QXmlUtils::isChar(const QChar c) @@ -281,7 +281,7 @@ bool QXmlUtils::isChar(const QChar c) production [4]NameChar in the XML 1.0 specification. If it is, true is returned, otherwise false. - \sa \l {http://www.w3.org/TR/REC-xml/#NT-NameChar} + \sa {http://www.w3.org/TR/REC-xml/#NT-NameChar}, {Extensible Markup Language (XML) 1.0 (Fourth Edition), [4] NameChar} */ bool QXmlUtils::isNameChar(const QChar c) @@ -304,7 +304,7 @@ bool QXmlUtils::isNameChar(const QChar c) production [12] PubidLiteral in the XML 1.0 specification. If it is, true is returned, otherwise false. - \sa \l {http://www.w3.org/TR/REC-xml/#NT-PubidLiteral} + \sa {http://www.w3.org/TR/REC-xml/#NT-PubidLiteral}, {Extensible Markup Language (XML) 1.0 (Fourth Edition), [12] PubidLiteral} */ bool QXmlUtils::isPublicID(const QString &candidate) @@ -363,7 +363,7 @@ bool QXmlUtils::isPublicID(const QString &candidate) production [4]NCName in the XML 1.0 Namespaces specification. If it is, true is returned, otherwise false. - \sa \l {http://www.w3.org/TR/REC-xml-names/#NT-NCName} + \sa {http://www.w3.org/TR/REC-xml-names/#NT-NCName}, {W3CNamespaces in XML 1.0 (Second Edition), [4] NCName} */ bool QXmlUtils::isNCName(const QStringRef &ncName) -- cgit v1.2.3