From 76d5bc087cd80582af9b9a9c8b828bf9efb5cde5 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 7 Mar 2014 15:23:27 +0100 Subject: Build the bluetooth doc snippet. This ensures that it keeps compiling and is correct. Although it wasn't able to compile due to a partial implementation, the snippet itself had errors which demonstrated wrong API aspects. Change-Id: I24048d968573e260d5b3ba92e38ce1dc9d24e52f Reviewed-by: Nedim Hadzic Reviewed-by: Alex Blasche --- src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp | 72 ++++++++++++++++++---- src/bluetooth/doc/snippets/doc_src_qtbluetooth.pro | 43 ------------- src/bluetooth/doc/snippets/snippets.pro | 8 +++ src/bluetooth/doc/src/bluetooth-cpp.qdoc | 2 +- src/bluetooth/doc/src/bluetooth-index.qdoc | 2 +- src/src.pro | 4 ++ 6 files changed, 73 insertions(+), 58 deletions(-) delete mode 100644 src/bluetooth/doc/snippets/doc_src_qtbluetooth.pro create mode 100644 src/bluetooth/doc/snippets/snippets.pro diff --git a/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp b/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp index 56459e72..e6e787f3 100644 --- a/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp +++ b/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the documentation of the Qt Toolkit. @@ -39,13 +39,36 @@ ****************************************************************************/ //! [include] -#include +#include //! [include] +#include +#include +#include +#include +#include +#include +#include +#include //! [namespace] QT_USE_NAMESPACE //! [namespace] +class MyClass : public QObject +{ + Q_OBJECT +public: + MyClass() : QObject() {} + void localDevice(); + void startDiscovery(); + void objectPush(); + +public slots: + void deviceDiscovered(const QBluetoothDeviceInfo &device); + void transferFinished(QBluetoothTransferReply* reply); +}; + +void MyClass::localDevice() { //! [turningon] QBluetoothLocalDevice localDevice; QString localDeviceName; @@ -60,20 +83,25 @@ if (localDevice.isValid()) { localDeviceName = localDevice.name(); // Make it visible to others - localDevice.setHostMode(QBluetoothLocalDevice::HostDiscoverable) + localDevice.setHostMode(QBluetoothLocalDevice::HostDiscoverable); } //! [turningon] +} //! [discovery] -// Create a discovery agent and connect to its signals -QBluetoothDiscoveryAgent *discoveryAgent = new QBluetoothDiscoveryAgent(this); -connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), - this, SLOT(deviceDiscovered(QBluetoothDeviceInfo))); +void MyClass::startDiscovery() +{ -// Start a discovery -discoveryAgent->start(); + // Create a discovery agent and connect to its signals + QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this); + connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), + this, SLOT(deviceDiscovered(QBluetoothDeviceInfo))); -... + // Start a discovery + discoveryAgent->start(); + + //... +} // In your local slot, read information about the found devices void MyClass::deviceDiscovered(const QBluetoothDeviceInfo &device) @@ -82,18 +110,36 @@ void MyClass::deviceDiscovered(const QBluetoothDeviceInfo &device) } //! [discovery] +void MyClass::objectPush() +{ //! [sendfile] // Create a transfer manager QBluetoothTransferManager *transferManager = new QBluetoothTransferManager(this); // Create the transfer request and file to be sent -QBluetoothTransferRequest request(device.address()); +QBluetoothAddress remoteAddress("00:11:22:33:44:55:66"); +QBluetoothTransferRequest request(remoteAddress); QFile *file = new QFile("testfile.txt"); // Ask the transfer manager to send it QBluetoothTransferReply *reply = transferManager->put(request, file); // Connect to the reply's signals to be informed about the status and do cleanups when done -connect(reply, SIGNAL(finished(QBluetoothTransferReply*)), - this, SLOT(transferFinished(QBluetoothTransferReply*))); +QObject::connect(reply, SIGNAL(finished(QBluetoothTransferReply*)), + this, SLOT(transferFinished(QBluetoothTransferReply*))); //! [sendfile] +} + +void MyClass::transferFinished(QBluetoothTransferReply* /*reply*/) +{ +} + +int main(int argc, char** argv) +{ + QCoreApplication app(argc, argv); + MyClass cl; + + return app.exec(); +} + +#include "doc_src_qtbluetooth.moc" diff --git a/src/bluetooth/doc/snippets/doc_src_qtbluetooth.pro b/src/bluetooth/doc/snippets/doc_src_qtbluetooth.pro deleted file mode 100644 index ca021b72..00000000 --- a/src/bluetooth/doc/snippets/doc_src_qtbluetooth.pro +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** 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 Digia Plc 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$ -** -****************************************************************************/ - -#! [contacts project modification] -QT += bluetooth -#! [contacts project modification] diff --git a/src/bluetooth/doc/snippets/snippets.pro b/src/bluetooth/doc/snippets/snippets.pro new file mode 100644 index 00000000..f59983ee --- /dev/null +++ b/src/bluetooth/doc/snippets/snippets.pro @@ -0,0 +1,8 @@ +TEMPLATE = app +TARGET = bluetooth_cppsnippet +QT = core +#! [contacts project modification] +QT += bluetooth +#! [contacts project modification] + +SOURCES += doc_src_qtbluetooth.cpp diff --git a/src/bluetooth/doc/src/bluetooth-cpp.qdoc b/src/bluetooth/doc/src/bluetooth-cpp.qdoc index 9bef246b..df18cc6a 100644 --- a/src/bluetooth/doc/src/bluetooth-cpp.qdoc +++ b/src/bluetooth/doc/src/bluetooth-cpp.qdoc @@ -42,6 +42,6 @@ To use the C++ library in your application, add the following configuration option to your \c .pro file: - \snippet doc_src_qtbluetooth.pro contacts project modification + \snippet snippets.pro contacts project modification */ diff --git a/src/bluetooth/doc/src/bluetooth-index.qdoc b/src/bluetooth/doc/src/bluetooth-index.qdoc index 77575994..ecc9561c 100644 --- a/src/bluetooth/doc/src/bluetooth-index.qdoc +++ b/src/bluetooth/doc/src/bluetooth-index.qdoc @@ -43,7 +43,7 @@ them. To use the C++ library in your application, add the following configuration option to your \c .pro file: -\snippet doc_src_qtbluetooth.pro contacts project modification +\snippet snippets.pro contacts project modification To use the classes of the module in your application you need the following import statement in your \c .qml file: diff --git a/src/src.pro b/src/src.pro index 1b937f61..7f37867e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -3,6 +3,10 @@ TEMPLATE = subdirs SUBDIRS += bluetooth nfc android: SUBDIRS += android +bluetooth_doc_snippets.subdir = bluetooth/doc/snippets +bluetooth_doc_snippets.depends = bluetooth +SUBDIRS += bluetooth_doc_snippets + qtHaveModule(quick) { imports.depends += bluetooth nfc SUBDIRS += imports -- cgit v1.2.3