Results 1 to 9 of 9

Thread: complications with connection to local Bluetooth

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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));

  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

    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,
    _

  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

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

  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

    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,
    _

  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

    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,

  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

    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,
    _

  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

    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
  •  
Qt is a trademark of The Qt Company.