QuteMessenger - Bluetooth Chat
Article Metadata
Code Example
Platform Security
Article
A Qt application using QBluetoothZero library to chat and send files to nearby devices.
The idea of creating this program was to have a cheap and easy to handle way to communicate with other nearby devices. So, people in a classroom, in a house and so on can chat for free. Also in the same time users can send files to the other devices.
How to run
First download source files from File:QuteMessenger.zip.
- For Symbian (before compile): there is a folder named QBluetoothZero. In there, a folder exists by the name symbian. Copy its contents (the epoc32 folder) to the root folder of the Symbian SDK that you are using (e.x. C:\QtSDK\Symbian\SDKs\Symbian1Qt473). This will lead to merge the already existing epoc32 folder in there, with the new one that has only the binaries of the QBluetoothZero library.
Next step, compile as Phone Debug/Release configuration and if all goes well it will be successful.
- For Windows (before first run): make sure you have the QBluetoothZero.dll file in the same directory that the executable of your application is placed.
Details
From now on we assume that every device that we want to connect to in order to chat, has the same application installed and running.
As soon as the application starts, a QBtSerialPortServer is created and is set to publish the service by the name "Messenger Protocol " + the name of the device. So any other device that finds this device through device discovery (QBtDeviceDiscoverer) then it already knows which service to look for.
An other device will act as client (QBtSerialPortClient), will search for the above server through device discovery, select it and press Options -> Start Chat. On the creation of the new view where the chat board will be placed, at the same time a QBtSerialPortClient is created and tries to connect to the selected server. If all this is successful then those two devices will be able to exchange messages.
On the server side, if the connection with the client is lost then the QBtSerialPortServer instance previously created is deleted and re-instantiated to be able accept future connection requests by other client.
On both server and client side, if the connection is lost the view containing the chat board is useless so it should be closed manually. An other view will be created in case of new connection (on server side it is automatically created on successful client connection whereas the client creates the view when user presses Start chat as mentioned above).
Also at the main view (where the devices found are shown), selecting a device and pressing Options softkey provides and an other operation. User can send s selected file to the remote device. If selected, a QFileDialog is show for the user to select the file to send. Then a User's device instantiates a QBtObjectExchangeClient which connects to the remote device (doesn't require a QBtObjectExchangeServer to be created, the default OBEX server is just fine!). Upon successful connection, the QBtObjectExchangeClient sends the file by calling PutFile(filename).
Links
favoritas37 00:47, 5 January 2012 (EET)


Contents
Klonikar - Project not building on Windows 7
The compilation goes fine, but I get the following linker error: g++ -mthreads -Wl,-subsystem,windows -o debug/QuteMessenger.exe object_script.QuteMessenger.Debug -L'c:/QtSDK/Desktop/Qt/4.7.4/mingw/lib' -lmingw32 -lqtmaind -LC:\Users\lonikar\Downloads\QuteMessenger\QBluetooth\win32\bin\Debug -lQBluetooth_0x2003328D -lBsSDK -lQtGuid4 -lQtCored4 -LC:\OpenSSL-Win32_full\lib mingw32-make[1]: Leaving directory `C:/Users/lonikar/Downloads/QuteMessenger-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug' ./debug/QChatWidgetClient.o: In function `GetDeviceHandle': C:\Users\lonikar\Downloads\QuteMessenger-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../QuteMessenger/QBluetooth/win32/include/QBluetooth/QBtAuxFunctions.h:167: undefined reference to `_imp___ZNK10QBtAddress19toReversedByteArrayEv' ./debug/QChatWidgetClient.o:C:\Users\lonikar\Downloads\QuteMessenger-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../QuteMessenger/QChatWidgetClient.cpp:58: undefined reference to `_imp___ZN19QBtSerialPortClientC1EP7QObject' ./debug/QChatWidgetClient.o:C:\Users\lonikar\Downloads\QuteMessenger-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../QuteMessenger/QChatWidgetClient.cpp:72: undefined reference to `_imp___ZN19QBtSerialPortClient7connectERK9QBtDeviceRK10QBtService' ./debug/QChatWidgetClient.o:C:\Users\lonikar\Downloads\QuteMessenger-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../QuteMessenger/QChatWidgetClient.cpp:77: undefined reference to `_imp___ZN9QBtDeviceC1ERKS_'
I checked the library QBluetooth/win32/bin/Debug/QBluetooth_0x2003328D.lib as below:
nm QBluetooth_0x2003328D.lib|grep BtAddress | grep ReversedByteArray
00000000 T ?toReversedByteArray@QBtAddress@@QBE?AVQByteArray@@XZ 00000000 I __imp_?toReversedByteArray@QBtAddress@@QBE?AVQByteArray@@XZ
As you can see, the library has the symbol but mangled in a different way. The symbol the library has is __imp_?toReversedByteArray@QBtAddress@@QBE?AVQByteArray@@XZ and the linker is looking for _imp___ZN19QBtSerialPortClientC1EP7QObject.
I am building with standard QtSDK. Can you tell me I am using incorrect library? I tried with Release version as well, but no luck.klonikar 11:14, 6 November 2011 (EET)
Are you building it using Mingw compiler? If you do, you need to change it to MSVC compiler for it to work. favoritas37 22:24, 6 November 2011 (EET)
Klonikar - Project not building on Windows 7
Yes, I was building it with mingw since thats what comes with QtSDK. Unfortunately, I do not have MSVC, so I will not able to build with that. Instead, is it possible for you to build the QBluetooth*.lib and dll with mingw and put it on some location? I tried doing that myself, but QBluetooth is building neither on windows nor Symbian1Qt473, and I am not able to proceed.
As a workaround, I created a simple server application with bluecove (java bluetooth jsr-82 library) and ran it on my windows machine with the name "Messenger Protocol MyMachineName". I then tried to connect the QuteMessenger running on my Nokia 5800 to the server, and the moment I selected "Start chat", the QuteMessenger crashed. The server on windows got a connection but showed EOFException when reading (possibly because the client crashed).
What could I be doing wrong? Is it that the QuteMessenger is OBEX based connection and the server is not OBEX?klonikar 05:25, 7 November 2011 (EET)
Hamishwillee - Favoritas may not be watching
I suggest you try a private message to the author, or post on the discussion boards.hamishwillee 07:36, 9 November 2011 (EET)
Favoritas37 - I am here :P
I haven't forgot you but these days are a bit crazy. I will try today to reply to you.
EDIT: one quick correction, the protocol through which the bluetooth chat is achieved is the Serial Port Profile not OBEX. OBEX is only used in the option to send a file to the selected device.
EDIT 2: is it that difficult to install the MSVC compiler through the Qt Creator? Just asking...
Favoritas37 - Problem compiling for Mingw
From klonikar request i tried to compile the project for Mingw but it is impossible due to the following error:
Running build steps for project QBluetooth3rdP... Starting: "c:\qtsdk\desktop\qt\4.7.4\mingw\bin\qmake.exe" C:\QtSDKProjects\QBluetooth3rdP\QBluetooth3rdP.pro -r -spec win32-g++ In file C:\ndk_buildrepos\qt-desktop/src/corelib/tools/qstring.cpp, line 1298: Out of memory The process "c:\qtsdk\desktop\qt\4.7.4\mingw\bin\qmake.exe" crashed. Error while building project QBluetooth3rdP (target: Desktop) When executing build step 'qmake'
I give up if no idea comes up.I am getting the same error if i try to compile it for MSVC2008 from Qt Creator. Meanwhile for the MSVC2008 it compiles successfully if done through Visual Studio 2008. Also Symbian part compiles successfully.
favoritas37 17:55, 13 November 2011 (EET)
Hamishwillee - Worth updating to Qt Mobility Bluetooth classes?
Now that Qt has Bluetooth support http://doc.qt.nokia.com/qtmobility/connectivity-api.html#bluetooth-classes , should this be updated?
Regards
Hamishhamishwillee 07:51, 17 February 2012 (EET)