Use the qinithzero Bluetooth Library

Source: Internet
Author: User
Use the qinithzero Bluetooth Library


Qinithzero is a QT Bluetooth library developed by a third party.(The previous name was qbluetooth, but in order to be different from the official QT Bluetooth library, it was changed to q1_thzero, but the official QT Bluetooth library was released recently ),Encapsulates the underlying Bluetooth operation of Symbian s60It is very convenient to use, but compilation does have a little problem. Today we will introduce in detail the q1_thzero Bluetooth Library:


The qinithzero Bluetooth library comes with a qutemessenger test program, which basically uses the main functions of the qinithzero Bluetooth library, including search and transmission, our job today is to successfully compile qutemessenger and run it in Nokia 5230. Second, refer to qutemessenger to write a simple test program and run it in Nokia 5230.After these two steps are completed, we can use the qinithzero Bluetooth library to develop our own Bluetooth app:

Reference: http://blog.csdn.net/dyw/article/details/5505415



1.

First


2.

Decompress the package and use QT to open qutemessenger. Pro,Select "Saipan device" and "QT Simulator" in the target settings"Such:





3.

Copy the epoc32 from Symbian under qinithzero in the qutemessenger folder to the Symbian installation directory of the qt sdk, for example (C: \ qtsdk \ Symbian \ sdks \ symbian1qt473 ), overwrite the epoc32 folder with the same name. In this way, you can find the corresponding header file when generating the target device.

For more information, see http://www.developer.nokia.com/community/wiki/qutemessenger_-_~th_chat's how to run section.




4.

Connect to the mobile phone and select "Saipan device debugging" in the lower left corner of the QT interface to start compilation. Although it is slow and has many warnings, compilation can be completed.The running result on the mobile phone is as follows:

Click Start search to search for a bluetooth device:



Bluetooth device found:





Next let's start Part 2: Refer to qutemessenger to write a simple test program and run it in Nokia 5230.

In our example, there is a search button and a stop button. Press the search button to start searching for the bluetooth device and list the searched information in the text box below:


We use the traditional QT Design Method, Specific reference http://blog.csdn.net/htttw/article/details/7632103

For the example in this article, refer to the official qw.thzero example (a slight error), Details:

Http://www.developer.nokia.com/Community/Wiki/Discovering_nearby_Bluetooth_services_with_the_QBluetooth_library

And:

Http://www.developer.nokia.com/Community/Wiki/QBluetooth_-_A_Qt_bluetooth_library


1.

Create a new "qt gui application" and enter "bttest" in the project name"



Select "Saipan device" in the target settings ":




Select qwidget:



Created!



2.

Modify the widget. UI and add a Pushbutton with the ID of btnsearch; add a Pushbutton with the ID of btnstop; add a plain text edit with the ID of textresult, for example:






3. Modify the widget. h as follows:

#ifndef WIDGET_H#define WIDGET_H#include <QWidget>#include <QBluetoothZero.h>namespace Ui {    class Widget;}class Widget : public QWidget{    Q_OBJECTpublic:    explicit Widget(QWidget *parent = 0);    ~Widget();private:    void put(const QString & s);private slots:    void searchButtonPressed();    void stopButtonPressed();    void discoveryStarted();    void discoveryEnded();    void newDeviceFound(const QBtDevice & device);private:    Ui::Widget *ui;    QBtServiceDiscovererForAll discoverer;};#endif // WIDGET_H


4. Modify widget. cpp as follows:

#include "widget.h"#include "ui_widget.h"Widget::Widget(QWidget *parent) :    QWidget(parent),    ui(new Ui::Widget){    ui->setupUi(this);    /* signal-slots for the service discoverer */    connect( &discoverer, SIGNAL(discoveryEnded()), SLOT(discoveryEnded()) );    connect( &discoverer, SIGNAL(discoveryStarted()), SLOT(discoveryStarted()) );    connect( &discoverer, SIGNAL(newDeviceFound(const QBtDevice &)), SLOT(newDeviceFound(const QBtDevice &)) );    /* signal-slots for buttons */    connect(ui->btnSearch, SIGNAL(clicked()), SLOT(searchButtonPressed()));    connect(ui->btnStop, SIGNAL(clicked()), SLOT(stopButtonPressed()));    /* ask for user if bluetooth is powered off */    QBtLocalDevice::askUserTurnOnBtPower();}Widget::~Widget(){    delete ui;}void Widget::put(const QString & s){    ui->textResult->appendPlainText(s);}void Widget::searchButtonPressed(){    /* do not start if the discovery is still busy finding devices */    if(discoverer.isBusy())    {        return;    }    /* clear the text box */    ui->textResult->clear();    /* let's go! */    discoverer.startDiscovery();}void Widget::stopButtonPressed(){    if(discoverer.isBusy())    {        discoverer.stopDiscovery();    }}void Widget::discoveryStarted (){    put("Discovery started");}void Widget::newDeviceFound (const QBtDevice & device){    put(QString("Found device: %1, address: %2").arg(device.getName()).arg(device.getAddress().toString()));    /* let's list all services */    put("Listing services");    const QBtService::List & services = device.getSupportedServices();    foreach(const QBtService & s, services)    {       put(s.getName());    }}void Widget::discoveryEnded(){    put("Discovery stopped");}



The code comment is very detailed. The general idea is that qinithzero sends a signal after performing an operation (such as searching devices, stopping searches, and discovering new devices, we just need to connect it to our own slot.



5. Modify bttest. Pro as follows (note that you do not need to modify target. uid3 ):

#-------------------------------------------------## Project created by QtCreator 2012-06-06T08:50:56##-------------------------------------------------QT       += core guiTARGET = BtTestTEMPLATE = appSOURCES += main.cpp\        widget.cppHEADERS  += widget.hFORMS    += widget.uiCONFIG += mobilitysymbian {    INCLUDEPATH += /epoc32/include/QBluetoothZero    LIBS += -lQBluetoothZero    TARGET.UID3 = 0xefe7eef5    TARGET.CAPABILITY = LocalServices   \                        NetworkServices \                        ReadUserData    \                        UserEnvironment \                        WriteUserData    TARGET.EPOCSTACKSIZE = 0x14000    TARGET.EPOCHEAPSIZE = 0x020000 0x800000    customrules.pkg_prerules  = ";QBluetoothZero" \                                "@\"$$(EPOCROOT)Epoc32/InstallToDevice/QBluetoothZero.sis\",(0xA003328D)"\                                " "    DEPLOYMENT += customrules}



6. Then, select the self-signature in the running of the project's Saipan device:




7. Connect to the mobile phone and select "Saipan device" in the lower left corner of QT to start compilation. After the compilation is completed, the running results in the mobile phone are as follows:

If Bluetooth is disabled when the software is started, the system prompts whether to enable Bluetooth:




Start Bluetooth and click search to search for the bluetooth device. The information is displayed in the text box below:




Click the stop button to stop searching.



Well, you can continue to expand and implement many functions such as file transfer and communication, all of which are implemented in qutemessenger. So, the Code is the best teacher ~~


Finally, I uploaded the Code:

Http://download.csdn.net/detail/htttw/4355020



Done!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.