diff options
Diffstat (limited to 'doc/src/snippets')
59 files changed, 1701 insertions, 221 deletions
diff --git a/doc/src/snippets/code/doc_src_emb-pointer.qdoc b/doc/src/snippets/code/doc_src_emb-pointer.qdoc index d333c90136..b051a98e2e 100644 --- a/doc/src/snippets/code/doc_src_emb-pointer.qdoc +++ b/doc/src/snippets/code/doc_src_emb-pointer.qdoc @@ -104,6 +104,10 @@ QWS_MOUSE_PROTO=IntelliMouse:/dev/input/mouse0 //! [11] +//! [show permissions] +ls -l /dev/input/mouse0 +//! [show permissions] + //! [12] chmod a+rw /dev/input/mouse0 //! [12] diff --git a/doc/src/snippets/code/doc_src_fdl.qdoc b/doc/src/snippets/code/doc_src_fdl.qdoc index 3c15dfee37..b55e66339b 100644 --- a/doc/src/snippets/code/doc_src_fdl.qdoc +++ b/doc/src/snippets/code/doc_src_fdl.qdoc @@ -7,11 +7,11 @@ ** This file is part of the documentation of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:FDL$ -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in a -** written agreement between you and Nokia. +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. ** ** GNU Free Documentation License ** Alternatively, this file may be used under the terms of the GNU Free diff --git a/doc/src/snippets/code/doc_src_installation.qdoc b/doc/src/snippets/code/doc_src_installation.qdoc index 05935670f5..2e59db981d 100644 --- a/doc/src/snippets/code/doc_src_installation.qdoc +++ b/doc/src/snippets/code/doc_src_installation.qdoc @@ -301,11 +301,24 @@ make runonphone -s lib/Qt.sis //! [47] +//! [runonphone with device file path] +runonphone -s lib/Qt.sis -p /dev/ttyUSB1 +//! [runonphone with device file path] + //! [48] cd demos/embedded/fluidlauncher runonphone -s fluidlauncher.sis fluidlauncher.exe //! [48] +//! [make runonphone with options] +make runonphone "QT_RUN_ON_PHONE_OPTIONS=-p /dev/ttyUSB1" +//! [make runonphone with options] + +//! [make runonphone with preset environment variable] +export QT_RUN_ON_PHONE_OPTIONS="-p /dev/ttyUSB1" +make runonphone +//! [make runonphone with preset environment variable] + //! [49] cd myapp qmake diff --git a/doc/src/snippets/code/doc_src_properties.qdoc b/doc/src/snippets/code/doc_src_properties.qdoc index 7704160f74..a4ed409a52 100644 --- a/doc/src/snippets/code/doc_src_properties.qdoc +++ b/doc/src/snippets/code/doc_src_properties.qdoc @@ -91,7 +91,7 @@ for (int i=0; i<count; ++i) { class MyClass : public QObject { Q_OBJECT - Q_PROPERTY(Priority priority READ priority WRITE setPriority) + Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged) Q_ENUMS(Priority) public: @@ -100,8 +100,19 @@ public: enum Priority { High, Low, VeryHigh, VeryLow }; - void setPriority(Priority priority); - Priority priority() const; + 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] diff --git a/doc/src/snippets/code/doc_src_qmake-manual.qdoc b/doc/src/snippets/code/doc_src_qmake-manual.qdoc index 8c35c3fb09..4f74e9cb98 100644 --- a/doc/src/snippets/code/doc_src_qmake-manual.qdoc +++ b/doc/src/snippets/code/doc_src_qmake-manual.qdoc @@ -1009,3 +1009,23 @@ my_exports = \ "bar.h /epoc32/include/mylib/bar.h" BLD_INF_RULES.prj_exports += my_exports //! [152] + +//! [153] +my_note.pkg_postrules.installer = "\"myinstallnote.txt\" - \"\", FILETEXT, TEXTCONTINUE" +DEPLOYMENT += my_note +//! [153] + +//! [154] +DEPLOYMENT -= default_bin_deployment default_resource_deployment default_reg_deployment +//! [154] + +//! [155] +default_bin_deployment.flags += FILERUN RUNINSTALL +dep_note.sources = install_note.txt +dep_note.flags = FILETEXT TEXTEXIT +DEPLOYMENT += dep_note +//! [155] + +//! [156] +DEPLOYMENT.display_name = My Qt App +//! [156] diff --git a/doc/src/snippets/code/src_qtestlib_qtestcase.cpp b/doc/src/snippets/code/src_qtestlib_qtestcase.cpp index c9bda6132a..adb0c343c6 100644 --- a/doc/src/snippets/code/src_qtestlib_qtestcase.cpp +++ b/doc/src/snippets/code/src_qtestlib_qtestcase.cpp @@ -48,7 +48,7 @@ QVERIFY(1 + 1 == 2); //! [1] -QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occured."); +QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occurred."); //! [1] @@ -230,5 +230,21 @@ widget.show(); QTest::qWaitForWindowShown(&widget); //! [24] +//! [25] +QWidget widget; + +QTest::touchEvent(&widget) + .press(0, QPoint(10, 10)); +QTest::touchEvent(&widget) + .stationary(0) + .press(1, QPoint(40, 10)); +QTest::touchEvent(&widget) + .move(0, QPoint(12, 12)) + .move(1, QPoint(45, 5)); +QTest::touchEvent(&widget) + .release(0) + .release(1); +//! [25] + } diff --git a/doc/src/snippets/declarative/borderimage/borderimage-defaults.qml b/doc/src/snippets/declarative/borderimage/borderimage-defaults.qml new file mode 100644 index 0000000000..1888f4eb82 --- /dev/null +++ b/doc/src/snippets/declarative/borderimage/borderimage-defaults.qml @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +import QtQuick 1.0 + +Rectangle { + id: page + color: "white" + width: 180; height: 180 + +//! [tiled border image] +BorderImage { + width: 180; height: 180 + border { left: 30; top: 30; right: 30; bottom: 30 } + source: "pics/borderframe.png" +} +//! [tiled border image] +} diff --git a/doc/src/snippets/declarative/comments.qml b/doc/src/snippets/declarative/comments.qml index a8e47ada05..97659a5414 100644 --- a/doc/src/snippets/declarative/comments.qml +++ b/doc/src/snippets/declarative/comments.qml @@ -38,7 +38,6 @@ ** ****************************************************************************/ -//![0] import QtQuick 1.0 //![0] diff --git a/doc/src/snippets/declarative/flipable/flipable.qml b/doc/src/snippets/declarative/flipable/flipable.qml index cd5da4bdca..8d48bd9eab 100644 --- a/doc/src/snippets/declarative/flipable/flipable.qml +++ b/doc/src/snippets/declarative/flipable/flipable.qml @@ -46,26 +46,27 @@ Flipable { width: 240 height: 240 - property int angle: 0 property bool flipped: false - front: Image { source: "front.png" } - back: Image { source: "back.png" } + front: Image { source: "front.png"; anchors.centerIn: parent } + back: Image { source: "back.png"; anchors.centerIn: parent } transform: Rotation { - origin.x: flipable.width/2; origin.y: flipable.height/2 - axis.x: 0; axis.y: 1; axis.z: 0 // rotate around y-axis - angle: flipable.angle + id: rotation + origin.x: flipable.width/2 + origin.y: flipable.height/2 + axis.x: 0; axis.y: 1; axis.z: 0 // set axis.y to 1 to rotate around y-axis + angle: 0 // the default angle } states: State { name: "back" - PropertyChanges { target: flipable; angle: 180 } + PropertyChanges { target: rotation; angle: 180 } when: flipable.flipped } transitions: Transition { - NumberAnimation { properties: "angle"; duration: 1000 } + NumberAnimation { target: rotation; property: "angle"; duration: 4000 } } MouseArea { diff --git a/doc/src/snippets/declarative/keys/keys-handler.qml b/doc/src/snippets/declarative/keys/keys-handler.qml index 9e3a3b4ec5..be0eedba77 100644 --- a/doc/src/snippets/declarative/keys/keys-handler.qml +++ b/doc/src/snippets/declarative/keys/keys-handler.qml @@ -38,7 +38,7 @@ ** ****************************************************************************/ -import Qt 4.7 +import QtQuick 1.0 Item { width: 400; height: 400 diff --git a/doc/src/snippets/declarative/keys/keys-pressed.qml b/doc/src/snippets/declarative/keys/keys-pressed.qml index 523c95b809..90a4e37906 100644 --- a/doc/src/snippets/declarative/keys/keys-pressed.qml +++ b/doc/src/snippets/declarative/keys/keys-pressed.qml @@ -38,7 +38,7 @@ ** ****************************************************************************/ -import Qt 4.7 +import QtQuick 1.0 Item { width: 400; height: 400 diff --git a/doc/src/snippets/declarative/loader/sizeitem.qml b/doc/src/snippets/declarative/loader/sizeitem.qml new file mode 100644 index 0000000000..6ace8d6510 --- /dev/null +++ b/doc/src/snippets/declarative/loader/sizeitem.qml @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +//![0] +import QtQuick 1.0 + +Item { + width: 200; height: 200 + + Loader { + // position the Loader in the center of the parent + anchors.centerIn: parent + sourceComponent: rect + } + + Component { + id: rect + Rectangle { + width: 50 + height: 50 + color: "red" + } + } +} +//![0] diff --git a/doc/src/snippets/declarative/loader/sizeloader.qml b/doc/src/snippets/declarative/loader/sizeloader.qml new file mode 100644 index 0000000000..eac7d57dd7 --- /dev/null +++ b/doc/src/snippets/declarative/loader/sizeloader.qml @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +//![0] +import QtQuick 1.0 + +Item { + width: 200; height: 200 + + Loader { + // Explicitly set the size of the Loader to the parent item's size + anchors.fill: parent + sourceComponent: rect + } + + Component { + id: rect + Rectangle { + width: 50 + height: 50 + color: "red" + } + } +} +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/context-advanced/MyItem.qml b/doc/src/snippets/declarative/qtbinding/context-advanced/MyItem.qml new file mode 100644 index 0000000000..607651a7f3 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/context-advanced/MyItem.qml @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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] +// MyItem.qml +import QtQuick 1.0 + +Text { text: applicationData.getCurrentDateTime() } +//![0] + diff --git a/doc/src/snippets/declarative/qtbinding/context-advanced/applicationdata.h b/doc/src/snippets/declarative/qtbinding/context-advanced/applicationdata.h new file mode 100644 index 0000000000..930e381284 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/context-advanced/applicationdata.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QObject> +#include <QDateTime> + +//![0] +class ApplicationData : public QObject +{ + Q_OBJECT +public: + Q_INVOKABLE QDateTime getCurrentDateTime() const { + return QDateTime::currentDateTime(); + } +}; +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp b/doc/src/snippets/declarative/qtbinding/context-advanced/connections.qml index 124422ff9b..749bea3d1e 100644 --- a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp +++ b/doc/src/snippets/declarative/qtbinding/context-advanced/connections.qml @@ -37,26 +37,16 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +import QtQuick 1.0 -#include "stopwatch.h" +//![0] +Text { + text: applicationData.getCurrentDateTime() -Stopwatch::Stopwatch() - : m_running(false) -{ -} - -bool Stopwatch::isRunning() const -{ - return m_running; -} - -void Stopwatch::start() -{ - m_running = true; -} - -void Stopwatch::stop() -{ - m_running = false; + Connections { + target: applicationData + onDataChanged: console.log("The application data changed!") + } } +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/context-advanced/context-advanced.pro b/doc/src/snippets/declarative/qtbinding/context-advanced/context-advanced.pro new file mode 100644 index 0000000000..188a9fb9f5 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/context-advanced/context-advanced.pro @@ -0,0 +1,3 @@ +QT += declarative +SOURCES += main.cpp +HEADERS += applicationdata.h diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/main.cpp b/doc/src/snippets/declarative/qtbinding/context-advanced/main.cpp index 7481b759c4..b92215b34e 100644 --- a/doc/src/snippets/declarative/qtbinding/custompalette/main.cpp +++ b/doc/src/snippets/declarative/qtbinding/context-advanced/main.cpp @@ -37,22 +37,21 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QtCore> +#include <QtDeclarative> -#include <QApplication> -#include <QDeclarativeView> -#include <QDeclarativeContext> - -#include "custompalette.h" +#include "applicationdata.h" //![0] -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { QApplication app(argc, argv); QDeclarativeView view; - view.rootContext()->setContextProperty("palette", new CustomPalette); - view.setSource(QUrl::fromLocalFile("main.qml")); + ApplicationData data; + view.rootContext()->setContextProperty("applicationData", &data); + + view.setSource(QUrl::fromLocalFile("MyItem.qml")); view.show(); return app.exec(); diff --git a/doc/src/snippets/declarative/qtbinding/context/MyItem.qml b/doc/src/snippets/declarative/qtbinding/context/MyItem.qml new file mode 100644 index 0000000000..faa42dcf90 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/context/MyItem.qml @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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] +// MyItem.qml +import QtQuick 1.0 + +Text { text: currentDateTime } +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro b/doc/src/snippets/declarative/qtbinding/context/context.pro index 68eeaf211b..68eeaf211b 100644 --- a/doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro +++ b/doc/src/snippets/declarative/qtbinding/context/context.pro diff --git a/doc/src/snippets/declarative/qtbinding/context/main.cpp b/doc/src/snippets/declarative/qtbinding/context/main.cpp new file mode 100644 index 0000000000..bbe9956c37 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/context/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore> +#include <QtDeclarative> + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + +//![0] +QDeclarativeView view; +view.rootContext()->setContextProperty("currentDateTime", QDateTime::currentDateTime()); +view.setSource(QUrl::fromLocalFile("MyItem.qml")); +view.show(); +//![0] + + return app.exec(); +} + diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h deleted file mode 100644 index 7e84bd4d6b..0000000000 --- a/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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 <QObject> -#include <QColor> - -//![0] -class CustomPalette : public QObject -{ - Q_OBJECT - Q_PROPERTY(QColor background READ background WRITE setBackground NOTIFY backgroundChanged) - Q_PROPERTY(QColor text READ text WRITE setText NOTIFY textChanged) - -public: - CustomPalette() : m_background(Qt::white), m_text(Qt::black) {} - - QColor background() const { return m_background; } - void setBackground(const QColor &c) { - if (c != m_background) { - m_background = c; - emit backgroundChanged(); - } - } - - QColor text() const { return m_text; } - void setText(const QColor &c) { - if (c != m_text) { - m_text = c; - emit textChanged(); - } - } - -signals: - void textChanged(); - void backgroundChanged(); - -private: - QColor m_background; - QColor m_text; -}; - -//![0] diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro b/doc/src/snippets/declarative/qtbinding/enums/enums.pro index e6af0d033e..82bc123461 100644 --- a/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro +++ b/doc/src/snippets/declarative/qtbinding/enums/enums.pro @@ -1,3 +1,3 @@ QT += declarative -HEADERS += custompalette.h SOURCES += main.cpp +HEADERS += imageviewer.h diff --git a/doc/src/snippets/declarative/qtbinding/enums/imageviewer.h b/doc/src/snippets/declarative/qtbinding/enums/imageviewer.h new file mode 100644 index 0000000000..8aaddeed4a --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/enums/imageviewer.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore> +#include <QtDeclarative> + +//![start] +class ImageViewer : public QDeclarativeItem +{ + Q_OBJECT + Q_ENUMS(Status) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) +public: + enum Status { + Ready, + Loading, + Error + }; + + Status status() const; +//![start] + + ImageViewer(QDeclarativeItem *parent = 0); + +public slots: + void emitSignals(); + +//![end] +signals: + void statusChanged(); +}; +//![end] diff --git a/doc/src/snippets/declarative/qtbinding/enums/main.cpp b/doc/src/snippets/declarative/qtbinding/enums/main.cpp new file mode 100644 index 0000000000..9243f4bbce --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/enums/main.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore> +#include <QtDeclarative> + +#include "imageviewer.h" + +ImageViewer::ImageViewer(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ + QTimer::singleShot(0, this, SLOT(emitSignals())); +} + +ImageViewer::Status ImageViewer::status() const +{ + return Ready; +} + +void ImageViewer::emitSignals() +{ + emit statusChanged(); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + qmlRegisterType<ImageViewer>("MyLibrary", 1, 0, "ImageViewer"); + + QDeclarativeView view; + view.setSource(QUrl::fromLocalFile("standalone.qml")); + view.show(); + + return app.exec(); +} + diff --git a/doc/src/snippets/declarative/qtbinding/enums/standalone.qml b/doc/src/snippets/declarative/qtbinding/enums/standalone.qml new file mode 100644 index 0000000000..ad6c14ce9d --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/enums/standalone.qml @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ +import MyLibrary 1.0 + +//![0] +ImageViewer { + onStatusChanged: { + if (status == ImageViewer.Ready) + console.log("Image viewer is ready!") + } +} +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/main.qml b/doc/src/snippets/declarative/qtbinding/functions-cpp/MyItem.qml index f894f716f8..8d8cd563a5 100644 --- a/doc/src/snippets/declarative/qtbinding/stopwatch/main.qml +++ b/doc/src/snippets/declarative/qtbinding/functions-cpp/MyItem.qml @@ -37,21 +37,18 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - //![0] +// MyItem.qml import QtQuick 1.0 -Rectangle { - width: 300 - height: 300 +Item { + width: 100; height: 100 MouseArea { anchors.fill: parent onClicked: { - if (stopwatch.isRunning()) - stopwatch.stop() - else - stopwatch.start(); + myObject.cppMethod("Hello from QML") + myObject.cppSlot(12345) } } } diff --git a/doc/src/snippets/declarative/qtbinding/functions-cpp/functions-qml.pro b/doc/src/snippets/declarative/qtbinding/functions-cpp/functions-qml.pro new file mode 100644 index 0000000000..01066c1bc4 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/functions-cpp/functions-qml.pro @@ -0,0 +1,3 @@ +QT += declarative +SOURCES += main.cpp +HEADERS += myclass.h diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp b/doc/src/snippets/declarative/qtbinding/functions-cpp/main.cpp index 12481dacf0..91d6aec545 100644 --- a/doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp +++ b/doc/src/snippets/declarative/qtbinding/functions-cpp/main.cpp @@ -37,23 +37,20 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QtCore> +#include <QtDeclarative> -#include "stopwatch.h" - -#include <QDeclarativeView> -#include <QDeclarativeContext> -#include <QApplication> +#include "myclass.h" //![0] -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { QApplication app(argc, argv); QDeclarativeView view; - view.rootContext()->setContextProperty("stopwatch", - new Stopwatch); + MyClass myClass; + view.rootContext()->setContextProperty("myObject", &myClass); - view.setSource(QUrl::fromLocalFile("main.qml")); + view.setSource(QUrl::fromLocalFile("MyItem.qml")); view.show(); return app.exec(); diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/main.qml b/doc/src/snippets/declarative/qtbinding/functions-cpp/myclass.h index a20d9e0e68..76c628ecf1 100644 --- a/doc/src/snippets/declarative/qtbinding/custompalette/main.qml +++ b/doc/src/snippets/declarative/qtbinding/functions-cpp/myclass.h @@ -37,26 +37,21 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QObject> +#include <QDebug> //![0] -import QtQuick 1.0 - -Rectangle { - width: 240 - height: 320 - color: palette.background - - Text { - anchors.centerIn: parent - color: palette.text - text: "Click me to change color!" +class MyClass : public QObject +{ + Q_OBJECT +public: + Q_INVOKABLE void cppMethod(const QString &msg) { + qDebug() << "Called the C++ method with" << msg; } - MouseArea { - anchors.fill: parent - onClicked: { - palette.text = "blue"; - } +public slots: + void cppSlot(int number) { + qDebug() << "Called the C++ slot with" << number; } -} +}; //![0] diff --git a/doc/src/snippets/declarative/qtbinding/contextproperties/main.qml b/doc/src/snippets/declarative/qtbinding/functions-qml/MyItem.qml index 425346d8c9..6161d6e028 100644 --- a/doc/src/snippets/declarative/qtbinding/contextproperties/main.qml +++ b/doc/src/snippets/declarative/qtbinding/functions-qml/MyItem.qml @@ -37,19 +37,14 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - //![0] +// MyItem.qml import QtQuick 1.0 -Rectangle { - width: 300 - height: 300 - - color: backgroundColor - - Text { - anchors.centerIn: parent - text: "Hello Yellow World!" +Item { + function myQmlFunction(msg) { + console.log("Got message:", msg) + return "some return value" } } //![0] diff --git a/doc/src/snippets/declarative/qtbinding/functions-qml/functions-qml.pro b/doc/src/snippets/declarative/qtbinding/functions-qml/functions-qml.pro new file mode 100644 index 0000000000..68eeaf211b --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/functions-qml/functions-qml.pro @@ -0,0 +1,2 @@ +QT += declarative +SOURCES += main.cpp diff --git a/doc/src/snippets/declarative/qtbinding/functions-qml/main.cpp b/doc/src/snippets/declarative/qtbinding/functions-qml/main.cpp new file mode 100644 index 0000000000..3e9e51e38a --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/functions-qml/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore> +#include <QtDeclarative> + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + +//![0] +// main.cpp +QDeclarativeEngine engine; +QDeclarativeComponent component(&engine, "MyItem.qml"); +QObject *object = component.create(); + +QVariant returnedValue; +QVariant msg = "Hello from C++"; +QMetaObject::invokeMethod(object, "myQmlFunction", + Q_RETURN_ARG(QVariant, returnedValue), + Q_ARG(QVariant, msg)); + +qDebug() << "QML function returned:" << returnedValue.toString(); +delete object; +//![0] +} + diff --git a/doc/src/snippets/declarative/qtbinding/loading/MyItem.qml b/doc/src/snippets/declarative/qtbinding/loading/MyItem.qml new file mode 100644 index 0000000000..40138f6bd7 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/loading/MyItem.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ +//![start] +import QtQuick 1.0 + +Item { + width: 100; height: 100 +//![start] + +//![child] + Rectangle { + anchors.fill: parent + objectName: "rect" + } +//![child] + +//![end] +} +//![end] diff --git a/doc/src/snippets/declarative/qtbinding/loading/loading.pro b/doc/src/snippets/declarative/qtbinding/loading/loading.pro new file mode 100644 index 0000000000..68eeaf211b --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/loading/loading.pro @@ -0,0 +1,2 @@ +QT += declarative +SOURCES += main.cpp diff --git a/doc/src/snippets/declarative/qtbinding/loading/main.cpp b/doc/src/snippets/declarative/qtbinding/loading/main.cpp new file mode 100644 index 0000000000..bd400b0a9c --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/loading/main.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore> +#include <QtDeclarative> + +static void withComponent() +{ +//![QDeclarativeComponent-a] +// Using QDeclarativeComponent +QDeclarativeEngine engine; +QDeclarativeComponent component(&engine, + QUrl::fromLocalFile("MyItem.qml")); +QObject *object = component.create(); +//![QDeclarativeComponent-a] +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + +//![QDeclarativeView] +// Using QDeclarativeView +QDeclarativeView view; +view.setSource(QUrl::fromLocalFile("MyItem.qml")); +view.show(); +QObject *object = view.rootObject(); +//![QDeclarativeView] + +//![properties] +object->setProperty("width", 500); +QDeclarativeProperty(object, "width").write(500); +//![properties] + +//![cast] +QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(object); +item->setWidth(500); +//![cast] + +//![findChild] +QObject *rect = object->findChild<QObject*>("rect"); +if (rect) + rect->setProperty("color", "red"); +//![findChild] + +//![QDeclarativeComponent-b] +delete object; +//![QDeclarativeComponent-b] + +withComponent(); + + return app.exec(); +} + diff --git a/doc/src/snippets/declarative/qtbinding/newelements/imageviewer.h b/doc/src/snippets/declarative/qtbinding/newelements/imageviewer.h new file mode 100644 index 0000000000..fd9db5eb7d --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/newelements/imageviewer.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore> +#include <QtDeclarative> + +//![0] +class ImageViewer : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged) + +public: + void setImage(const QUrl &url); + QUrl image() const; + +signals: + void imageChanged(); +}; +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/newelements/main.cpp b/doc/src/snippets/declarative/qtbinding/newelements/main.cpp new file mode 100644 index 0000000000..57994ca31d --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/newelements/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore> +#include <QtDeclarative> + +#include "imageviewer.h" + +void ImageViewer::setImage(const QUrl &url) {} +QUrl ImageViewer::image() const { return QUrl(); } + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + //![register] + qmlRegisterType<ImageViewer>("MyLibrary", 1, 0, "ImageViewer"); + //![register] + + QDeclarativeView view; + view.setSource(QUrl::fromLocalFile("standalone.qml")); + view.show(); + + return app.exec(); +} + diff --git a/doc/src/snippets/declarative/qtbinding/newelements/newelements.pro b/doc/src/snippets/declarative/qtbinding/newelements/newelements.pro new file mode 100644 index 0000000000..82bc123461 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/newelements/newelements.pro @@ -0,0 +1,3 @@ +QT += declarative +SOURCES += main.cpp +HEADERS += imageviewer.h diff --git a/doc/src/snippets/declarative/qtbinding/newelements/standalone.qml b/doc/src/snippets/declarative/qtbinding/newelements/standalone.qml new file mode 100644 index 0000000000..7345f21881 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/newelements/standalone.qml @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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] +import MyLibrary 1.0 + +ImageViewer { image: "smile.png" } +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/properties-cpp/MyItem.qml b/doc/src/snippets/declarative/qtbinding/properties-cpp/MyItem.qml new file mode 100644 index 0000000000..9db4b93e2e --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/properties-cpp/MyItem.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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] +// MyItem.qml +import QtQuick 1.0 + +Rectangle { + width: 100; height: 100 + color: applicationData.backgroundColor + + MouseArea { + anchors.fill: parent + onClicked: applicationData.backgroundColor = "red" + } +} +//![0] + diff --git a/doc/src/snippets/declarative/qtbinding/properties-cpp/applicationdata.h b/doc/src/snippets/declarative/qtbinding/properties-cpp/applicationdata.h new file mode 100644 index 0000000000..763a451646 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/properties-cpp/applicationdata.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QObject> +#include <QColor> + +//![0] +class ApplicationData : public QObject +{ + Q_OBJECT + Q_PROPERTY(QColor backgroundColor + READ backgroundColor + WRITE setBackgroundColor + NOTIFY backgroundColorChanged) + +public: + void setBackgroundColor(const QColor &c) { + if (c != m_color) { + m_color = c; + emit backgroundColorChanged(); + } + } + + QColor backgroundColor() const { + return m_color; + } + +signals: + void backgroundColorChanged(); + +private: + QColor m_color; +}; +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/properties-cpp/main.cpp b/doc/src/snippets/declarative/qtbinding/properties-cpp/main.cpp new file mode 100644 index 0000000000..36b508d30c --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/properties-cpp/main.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore> +#include <QtDeclarative> + +#include "applicationdata.h" + +int main(int argc, char *argv[]) { + QApplication app(argc, argv); + + QDeclarativeView view; + + ApplicationData data; + view.rootContext()->setContextProperty("applicationData", &data); + + view.setSource(QUrl::fromLocalFile("MyItem.qml")); + view.show(); + + return app.exec(); +} + diff --git a/doc/src/snippets/declarative/qtbinding/properties-cpp/properties-cpp.pro b/doc/src/snippets/declarative/qtbinding/properties-cpp/properties-cpp.pro new file mode 100644 index 0000000000..188a9fb9f5 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/properties-cpp/properties-cpp.pro @@ -0,0 +1,3 @@ +QT += declarative +SOURCES += main.cpp +HEADERS += applicationdata.h diff --git a/doc/src/snippets/declarative/qtbinding/properties-qml/MyItem.qml b/doc/src/snippets/declarative/qtbinding/properties-qml/MyItem.qml new file mode 100644 index 0000000000..a43ded8d40 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/properties-qml/MyItem.qml @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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] +// MyItem.qml +import QtQuick 1.0 + +Item { + property int someNumber: 100 +} +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/properties-qml/main.cpp b/doc/src/snippets/declarative/qtbinding/properties-qml/main.cpp new file mode 100644 index 0000000000..d8daff8be7 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/properties-qml/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore> +#include <QtDeclarative> + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + +//![0] +QDeclarativeEngine engine; +QDeclarativeComponent component(&engine, "MyItem.qml"); +QObject *object = component.create(); + +qDebug() << "Property value:" << QDeclarativeProperty::read(object, "someNumber").toInt(); +QDeclarativeProperty::write(object, "someNumber", 5000); + +qDebug() << "Property value:" << object->property("someNumber").toInt(); +object->setProperty("someNumber", 100); +//![0] + + return app.exec(); +} + diff --git a/doc/src/snippets/declarative/qtbinding/properties-qml/properties-qml.pro b/doc/src/snippets/declarative/qtbinding/properties-qml/properties-qml.pro new file mode 100644 index 0000000000..68eeaf211b --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/properties-qml/properties-qml.pro @@ -0,0 +1,2 @@ +QT += declarative +SOURCES += main.cpp diff --git a/doc/src/snippets/declarative/qtbinding/resources/main.qml b/doc/src/snippets/declarative/qtbinding/resources/main.qml index 644d96388e..43029cf6bd 100644 --- a/doc/src/snippets/declarative/qtbinding/resources/main.qml +++ b/doc/src/snippets/declarative/qtbinding/resources/main.qml @@ -39,9 +39,8 @@ ****************************************************************************/ //![0] +// main.qml import QtQuick 1.0 -Image { - source: "images/background.png" -} +Image { source: "images/background.png" } //![0] diff --git a/doc/src/snippets/declarative/qtbinding/signals-cpp/MyItem.qml b/doc/src/snippets/declarative/qtbinding/signals-cpp/MyItem.qml new file mode 100644 index 0000000000..d900830ab0 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/signals-cpp/MyItem.qml @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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] +// MyItem.qml +import QtQuick 1.0 + +Item { + Connections { + target: imageViewer + onImageChanged: console.log("Image has changed!") + } +} +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/signals-cpp/imageviewer.h b/doc/src/snippets/declarative/qtbinding/signals-cpp/imageviewer.h new file mode 100644 index 0000000000..7288d119c9 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/signals-cpp/imageviewer.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore> +#include <QtDeclarative> + +//![start] +class ImageViewer : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged) +public: +//![start] + ImageViewer(QDeclarativeItem *item = 0); + + void setImage(const QUrl &url) {} + QUrl image() const { return QUrl(); } + +public slots: + void emitSignals(); + +//![end] +signals: + void imageChanged(); + void loadingError(const QString &errorMsg); +}; +//![end] + diff --git a/doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp b/doc/src/snippets/declarative/qtbinding/signals-cpp/main.cpp index 6887e8fe7a..e5dd33c314 100644 --- a/doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp +++ b/doc/src/snippets/declarative/qtbinding/signals-cpp/main.cpp @@ -37,42 +37,45 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QtCore> +#include <QtDeclarative> -#include <QDeclarativeComponent> -#include <QDeclarativeEngine> +#include "imageviewer.h" -//![0] -#include <QApplication> -#include <QDeclarativeView> -#include <QDeclarativeContext> + +ImageViewer::ImageViewer(QDeclarativeItem *item) + : QDeclarativeItem(item) +{ + QTimer::singleShot(0, this, SLOT(emitSignals())); +} + +void ImageViewer::emitSignals() +{ + emit imageChanged(); + emit loadingError("some error message"); +} int main(int argc, char *argv[]) { QApplication app(argc, argv); - QDeclarativeView view; - QDeclarativeContext *context = view.rootContext(); - context->setContextProperty("backgroundColor", - QColor(Qt::yellow)); + qmlRegisterType<ImageViewer>("MyLibrary", 1, 0, "ImageViewer"); - view.setSource(QUrl::fromLocalFile("main.qml")); - view.show(); + QDeclarativeView standalone; + standalone.setSource(QUrl::fromLocalFile("standalone.qml")); + standalone.show(); - return app.exec(); -} -//![0] +//![connections] +ImageViewer viewer; -static void alternative() -{ - // Alternatively, if we don't actually want to display main.qml: -//![1] - QDeclarativeEngine engine; - QDeclarativeContext *windowContext = new QDeclarativeContext(engine.rootContext()); - windowContext->setContextProperty("backgroundColor", QColor(Qt::yellow)); +QDeclarativeView view; +view.rootContext()->setContextProperty("imageViewer", &viewer); - QDeclarativeComponent component(&engine, "main.qml"); - QObject *window = component.create(windowContext); -//![1] +view.setSource(QUrl::fromLocalFile("MyItem.qml")); +view.show(); +//![connections] + + return app.exec(); } diff --git a/doc/src/snippets/declarative/qtbinding/signals-cpp/signals-cpp.pro b/doc/src/snippets/declarative/qtbinding/signals-cpp/signals-cpp.pro new file mode 100644 index 0000000000..9aa8702432 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/signals-cpp/signals-cpp.pro @@ -0,0 +1,3 @@ +QT += declarative +SOURCES += main.cpp +HEADERS += "imageviewer.h" diff --git a/doc/src/snippets/declarative/qtbinding/signals-cpp/standalone.qml b/doc/src/snippets/declarative/qtbinding/signals-cpp/standalone.qml new file mode 100644 index 0000000000..4027b19a86 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/signals-cpp/standalone.qml @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ +import MyLibrary 1.0 + +//![0] +ImageViewer { + onImageChanged: console.log("Image changed!") + onLoadingError: console.log("Image failed to load:", errorMsg) +} +//![0] + diff --git a/doc/src/snippets/declarative/qtbinding/signals-qml/MyItem.qml b/doc/src/snippets/declarative/qtbinding/signals-qml/MyItem.qml new file mode 100644 index 0000000000..e4b6cedb7d --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/signals-qml/MyItem.qml @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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] +// MyItem.qml +import QtQuick 1.0 + +Item { + id: item + width: 100; height: 100 + + signal qmlSignal(string msg) + + MouseArea { + anchors.fill: parent + onClicked: item.qmlSignal("Hello from QML") + } +} +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/signals-qml/main.cpp b/doc/src/snippets/declarative/qtbinding/signals-qml/main.cpp new file mode 100644 index 0000000000..f1d03c4bb1 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/signals-qml/main.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore> +#include <QtDeclarative> + +//![0] +int main(int argc, char *argv[]) { + QApplication app(argc, argv); + + QDeclarativeView view(QUrl::fromLocalFile("MyItem.qml")); + QObject *item = view.rootObject(); + + MyClass myClass; + QObject::connect(item, SIGNAL(qmlSignal(QString)), + &myClass, SLOT(cppSlot(QString))); + + view.show(); + return app.exec(); +} +//![0] + +#include "moc_main.cpp" diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h b/doc/src/snippets/declarative/qtbinding/signals-qml/myclass.h index fd65916fe1..c326a54498 100644 --- a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h +++ b/doc/src/snippets/declarative/qtbinding/signals-qml/myclass.h @@ -37,25 +37,15 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - #include <QObject> - +#include <QDebug> //![0] -class Stopwatch : public QObject +class MyClass : public QObject { Q_OBJECT -public: - Stopwatch(); - - Q_INVOKABLE bool isRunning() const; - public slots: - void start(); - void stop(); - -private: - bool m_running; + void cppSlot(const QString &msg) { + qDebug() << "Called the C++ slot with message:" << msg; + } }; - //![0] - diff --git a/doc/src/snippets/declarative/qtbinding/signals-qml/signals-qml.pro b/doc/src/snippets/declarative/qtbinding/signals-qml/signals-qml.pro new file mode 100644 index 0000000000..01066c1bc4 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/signals-qml/signals-qml.pro @@ -0,0 +1,3 @@ +QT += declarative +SOURCES += main.cpp +HEADERS += myclass.h diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro deleted file mode 100644 index d803e6a351..0000000000 --- a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro +++ /dev/null @@ -1,3 +0,0 @@ -QT += declarative -HEADERS += stopwatch.h -SOURCES += main.cpp stopwatch.cpp diff --git a/doc/src/snippets/moc/myclass2.h b/doc/src/snippets/moc/myclass2.h index ca79515167..daea23c1f0 100644 --- a/doc/src/snippets/moc/myclass2.h +++ b/doc/src/snippets/moc/myclass2.h @@ -58,8 +58,11 @@ public: MyClass(QObject *parent = 0); ~MyClass(); - void setPriority(Priority priority); - Priority priority() const; + void setPriority(Priority priority) { m_priority = priority; } + Priority priority() const { return m_priority; } + +private: + Priority m_priority; }; //! [0] |