Results 1 to 9 of 9

Thread: complications with connection to local Bluetooth

  1. #1
    Join Date
    Jul 2016
    Posts
    41
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default complications with connection to local Bluetooth

    Hi!

    I am trying to connect to local Bluetooth address:

    Qt Code:
    1. void Widget::connect_to_local_Bluetooth( )
    2. {
    3.  
    4. qDebug()<<"trying to connect"<<endl;
    5. QBluetoothAddress address("00:1A:7D:DA:71:15");
    6. qDebug()<<address.toString()<<endl;
    7. if(socket.state() != QBluetoothSocket::UnconnectedState)
    8. {
    9. qDebug()<<"socket.state"<<endl;
    10. if(address != socket.peerAddress())//???
    11. {
    12. qDebug()<<"socket.peeradress"<<endl;
    13. socket.disconnectFromService();
    14. socket.connectToService(address, QBluetoothUuid(QBluetoothUuid::SerialPort));
    15. }
    16. //else
    17. // emit connected();
    18. }
    19. else{
    20. qDebug()<<"else case"<<endl;
    21. socket.connectToService(address, QBluetoothUuid(QBluetoothUuid::SerialPort));
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 
    When I compile and run this, it all is working, but when this SLOT is called program writes:

    trying to connect

    address

    else

    and then unexpectedly finishes. Why so? What should I correct here? Thank you!

    P.S. When I compile and run it on my Android device it does not interrupt, but I have no idea, is he connected to my Desktop or not. local address of Desktop is 00:1A:7D:DA:71:15

    here is message from debugger:

    ///////////////////////////////////////////////////// bluetooth is powered off W/ResourceType(15962): No package identifier when getting name for resource number 0x00000005 I/View (15962): Touch down dispatch to org.qtproject.qt5.android.QtSurface{41e7a900 V.E..... ........ 0,0-1024,695 #5}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=175.8283, y[0]=70.87516, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=12082488, downTime=12082488, deviceId=3, source=0x1002 } I/BufferQueue( 136): SurfaceView [queue] fps:0.67, dur:3002.75, max:2887.19, min:115.55 I/BufferQueue( 136): SurfaceView [release] fps:0.66, dur:3009.61, max:2887.47, min:122.15 W/ResourceType(15962): No package identifier when getting name for resource number 0x00000005 I/View (15962): Touch up dispatch to org.qtproject.qt5.android.QtSurface{41e7a900 V.E..... ........ 0,0-1024,695 #5}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=175.8283, y[0]=70.87516, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=12082557, downTime=12082488, deviceId=3, source=0x1002 } D/libA_for_w8.so(15962): ..\A_for_w8\widget.cpp:59 (void Widget::try_connect_to_local_address()): trying to connect D/libA_for_w8.so(15962): D/libA_for_w8.so(15962): ..\A_for_w8\widget.cpp:61 (void Widget::try_connect_to_local_address()): "00:1A:7D:DA:71:15" D/libA_for_w8.so(15962): D/libA_for_w8.so(15962): ..\A_for_w8\widget.cpp:64 (void Widget::try_connect_to_local_address()): socket.state D/libA_for_w8.so(15962): D/BluetoothDevice(15962): mAddress: 00:1A:7D:DA:71:15

    // /////////////////////////// bluetooth is on

    W/ResourceType(15962): No package identifier when getting name for resource number 0x00000006 I/View (15962): Touch down dispatch to org.qtproject.qt5.android.QtSurface{41dce2d8 V.E..... ........ 0,0-1024,695 #6}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=178.82536, y[0]=70.87516, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=12161746, downTime=12161746, deviceId=3, source=0x1002 } I/BufferQueue( 136): SurfaceView new GraphicBuffer needed D/GraphicBuffer(15962): create handle(0x6aa44f78) (w:1024, h:695, f:1) I/BufferQueue( 136): SurfaceView [queue] fps:0.40, dur:5054.98, max:4978.11, min:76.87 I/BufferQueue( 136): SurfaceView [release] fps:0.20, dur:4970.67, max:4970.67, min:4970.67 W/ResourceType(15962): No package identifier when getting name for resource number 0x00000006 I/View (15962): Touch up dispatch to org.qtproject.qt5.android.QtSurface{41dce2d8 V.E..... ........ 0,0-1024,695 #6}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=178.82536, y[0]=70.87516, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=12161842, downTime=12161746, deviceId=3, source=0x1002 } D/libA_for_w8.so(15962): ..\A_for_w8\widget.cpp:59 (void Widget::try_connect_to_local_address()): trying to connect D/libA_for_w8.so(15962): D/libA_for_w8.so(15962): ..\A_for_w8\widget.cpp:61 (void Widget::try_connect_to_local_address()): "00:1A:7D:DA:71:15" D/libA_for_w8.so(15962): D/libA_for_w8.so(15962): ..\A_for_w8\widget.cpp:64 (void Widget::try_connect_to_local_address()): socket.state D/libA_for_w8.so(15962): D/BluetoothDevice(15962): mAddress: 00:1A:7D:DA:71:15

    ///////////////////////////////////// bluetooth is on too

    W/ResourceType(18110): No package identifier when getting name for resource number 0x00000004 I/View (18110): Touch down dispatch to org.qtproject.qt5.android.QtSurface{4202d638 V.E..... ........ 0,0-1024,695 #4}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=187.81659, y[0]=65.88166, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=12572050, downTime=12572050, deviceId=3, source=0x1002 } I/BufferQueue( 136): SurfaceView new GraphicBuffer needed D/GraphicBuffer(18110): create handle(0x6c277498) (w:1024, h:695, f:1) I/BufferQueue( 136): SurfaceView [queue] fps:0.39, dur:5184.50, max:5110.70, min:73.81 I/BufferQueue( 136): SurfaceView [release] fps:0.20, dur:5127.71, max:5127.71, min:5127.71 W/ResourceType(18110): No package identifier when getting name for resource number 0x00000004 I/View (18110): Touch up dispatch to org.qtproject.qt5.android.QtSurface{4202d638 V.E..... ........ 0,0-1024,695 #4}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=187.81659, y[0]=65.88166, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=12572146, downTime=12572050, deviceId=3, source=0x1002 } D/libA_for_w8.so(18110): ..\A_for_w8\widget.cpp:59 (void Widget::try_connect_to_local_address()): trying to connect D/libA_for_w8.so(18110): D/libA_for_w8.so(18110): ..\A_for_w8\widget.cpp:61 (void Widget::try_connect_to_local_address()): "00:1A:7D:DA:71:15" D/libA_for_w8.so(18110): D/libA_for_w8.so(18110): ..\A_for_w8\widget.cpp:75 (void Widget::try_connect_to_local_address()): else D/libA_for_w8.so(18110): D/BluetoothAdapter(18110): 1105859416: getState(). Returning 12 D/BluetoothDevice(18110): mAddress: 00:1A:7D:DA:71:15 D/libA_for_w8.so(18110): ..\A_for_w8\widget.cpp:80 (void Widget::try_connect_to_local_address()): D/libA_for_w8.so(18110): D/dalvikvm(18110): threadid=13: interp stack at 0x6c857000 W/BluetoothAdapter(18110): getBluetoothService() called with no BluetoothManagerCallback D/BluetoothSocket(18110): connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[71]} D/BluetoothDevice(18110): mAddress: 00:1A:7D:DA:71:15 W/System.err(18110): java.io.IOException: read failed, socket might closed or timeout, read ret: -1 W/System.err(18110): at android.bluetooth.BluetoothSocket.readAll(Bluetoot hSocket.java:505) W/System.err(18110): at android.bluetooth.BluetoothSocket.readInt(Bluetoot hSocket.java:516) W/System.err(18110): at android.bluetooth.BluetoothSocket.connect(Bluetoot hSocket.java:320) W/System.err(18110): at dalvik.system.NativeStart.run(Native Method) W/libA_for_w8.so(18110): (null):0 ((null)): qt.bluetooth.android: Falling back to workaround. W/libA_for_w8.so(18110): (null):0 ((null)): qt.bluetooth.android: Cannot determine RFCOMM service channel. D/BluetoothDevice(18110): mAddress: 00:1A:7D:DA:71:15 W/libA_for_w8.so(18110): (null):0 ((null)): qt.bluetooth.android: Workaround thread invoked. D/dalvikvm(18110): threadid=13: bye! D/dalvikvm(18110): threadid=13: interp stack at 0x6c857000 W/BluetoothAdapter(18110): getBluetoothService() called with no BluetoothManagerCallback D/BluetoothSocket(18110): connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[70]} D/BluetoothDevice(18110): mAddress: 00:1A:7D:DA:71:15

    To sum up:
    1) Why it does not interrupt on Android, but does on Desktop ?
    2) How can I understand, is there connection between two my devices ?
    3) if doesn't what am I doing incorrectly?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: complications with connection to local Bluetooth

    Have you checked the stack trace of the program at the time of the crash?

    Cheers,
    _

  3. #3
    Join Date
    Jul 2016
    Posts
    41
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: complications with connection to local Bluetooth

    It says:

    The inferior stopped because it received a signal from OS.
    Signal name: SIGSEGV.
    Signal meaning: Segmentation fault.

    it crashes on the line socket.connectToService(address, QBluetoothUuid(QBluetoothUuid::SerialPort));

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: complications with connection to local Bluetooth

    When a program crashes on a Unix system (assuming that is one due to SIGSEV), then it usually generates a core dump file, which can be analyized with a debugger.

    Or the program can be run in the debugger and it will then know the last trace of function calls at the time of the crash.

    That line itself doesn't look like it could crash (no pointer or uninitialized data present), so it could be inside the connectToService() method.

    But make sure that "this" is a valid object.

    Cheers,
    _

  5. #5
    Join Date
    Jul 2016
    Posts
    41
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: complications with connection to local Bluetooth

    Why it does not crash, when I run it on Android device?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: complications with connection to local Bluetooth

    There can be many reasons.

    For example if "this" is no longer a valid object then the memory "socket" points to could still be accessible depending on the operating system's memory managment.

    Which is why the stack trace is important.
    If it crashes in some internal function inside connectToService() it could be a bug in the platform's implementation for that function that is not in the implementation of the other platform.
    But if the crash is in application code, then it might just be hidden on one of the platforms.

    Very often, when crashes seemingly happen in library code it is actually the application code that is wrong.
    When access to non-heap members fails, like in this case, it is often that the "this" object has already been destroyed.

    Cheers,
    _

  7. #7
    Join Date
    Jul 2016
    Posts
    41
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: complications with connection to local Bluetooth

    Look, ich hab noch nicht verstanded..
    Why "this" can not be a valid object? If I firslty just push the button, which calls slot try_to_connect_to_local_address after I run my program?
    And "this" must be valid!
    oder ist das falsch?

    Grüße,

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: complications with connection to local Bluetooth

    It is likely that "this" is valid, but it can happen that a method is called on an object that has already been deleted.

    Then the method will often execute nicely but can crash if access to certain members or in a certain way can no longer be done properly.

    For example, the following works nicely for me, despite the object having been deleted
    Qt Code:
    1. #include <iostream>
    2. #include <string>
    3.  
    4. using namespace std;
    5.  
    6. class Test
    7. {
    8. public:
    9. Test() : m_int(0) {}
    10.  
    11. void noMemberAccess()
    12. {
    13. cout << "noMemberAccess called" << endl;
    14. }
    15.  
    16. void intReadAccess()
    17. {
    18. cout << "intReadAccess called: value=" << m_int << endl;
    19. }
    20.  
    21. void stringWriteAccess()
    22. {
    23. m_string = "foo";
    24. cout << "stringWriteAccess called:" << m_string << endl;
    25. }
    26.  
    27. int m_int;
    28. string m_string;
    29. };
    30.  
    31. int main()
    32. {
    33. Test *t = new Test;
    34.  
    35. t->noMemberAccess();
    36. t->intReadAccess();
    37. t->stringWriteAccess();
    38.  
    39. cout << "deleting object" << endl;
    40.  
    41. delete t;
    42.  
    43. t->noMemberAccess();
    44. t->intReadAccess();
    45. t->stringWriteAccess();
    46.  
    47. return 0;
    48. }
    To copy to clipboard, switch view to plain text mode 
    Obvioulsy the memory pointed to by "t" is still OK enough, but that is not in any way guaranteed.
    So different systems or different loads on the same system, etc. can lead to different outcomes. It might work nicely but it could crash.

    The result is often weird stack traces, like QString::length() appearing to crash, while actually QString::length() was called on a QString member variable of a destroyed object.

    Hence it is important to see how deep the stack trace goes into the method you are experiencing a crash with, but also important to verify that the object the call is coming from is still valid,

    Cheers,
    _

  9. #9
    Join Date
    Jul 2016
    Posts
    41
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: complications with connection to local Bluetooth

    wow!
    it is very unexpectedly for me!)
    Thank you for full explanation.

Similar Threads

  1. Cannot find my local Bluetooth module
    By Blitzor DDD in forum Qt Programming
    Replies: 4
    Last Post: 18th August 2016, 12:08
  2. Replies: 1
    Last Post: 3rd August 2012, 11:32
  3. Replies: 1
    Last Post: 3rd August 2012, 08:50
  4. Replies: 0
    Last Post: 11th November 2011, 19:18
  5. Replies: 1
    Last Post: 2nd April 2010, 06:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.