diff options
Diffstat (limited to 'src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp')
-rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp | 111 |
1 files changed, 17 insertions, 94 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp index fddda64b19..e3bbac7a3c 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause //! [1] QObject *obj = new QPushButton; @@ -176,13 +129,6 @@ void MyObject::timerEvent(QTimerEvent *event) //! [8] -//! [9] -QList<QObject *> list = window()->queryList("QAbstractButton")); -foreach (QObject *obj, list) - static_cast<QAbstractButton *>(obj)->setEnabled(false); -//! [9] - - //! [10] QPushButton *button = parentWidget->findChild<QPushButton *>("button1"); //! [10] @@ -251,22 +197,6 @@ MyWindow::MyWindow() } -//! [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; @@ -430,26 +360,18 @@ public: //! [39] -//! [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<QPushButton *>("button1", Qt::FindDirectChildrenOnly); //! [41] //! [42] -QListWidget *list = parentWidget->findChild<QListWidget *>(QString(), Qt::FindDirectChildrenOnly); +QListWidget *list = parentWidget->findChild<QListWidget *>(Qt::FindDirectChildrenOnly); //! [42] //! [43] -QList<QPushButton *> childButtons = parentWidget.findChildren<QPushButton *>(QString(), Qt::FindDirectChildrenOnly); +QList<QPushButton *> childButtons = parentWidget.findChildren<QPushButton *>(Qt::FindDirectChildrenOnly); //! [43] //! [44] @@ -534,18 +456,6 @@ public: }; //! [52] -//! [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] //! [53] { @@ -559,3 +469,16 @@ const bool wasBlocked = someQObject->blockSignals(true); // no signals here someQObject->blockSignals(wasBlocked); //! [54] + +{ +//! [invalid-timer-id] + QObject *obj; + ... + int id = obj->startTimer(100ms); + if (id > Qt::TimerId::Invalid) + // The timer has been started successfully + + if (id > 0) // Equivalent, albeit less readable + // The timer has been started successfully +//! [invalid-timer-id] +} |