QT 5.7与Bluez 5.47连接设备时出现Segmentation Fault求助
Let's break down your issue and walk through targeted fixes based on the crash trace and your setup details:
Background
You've worked past the initial gcc 7 compilation bug, but now hit a segmentation fault when running build/ankicar. The crash occurs inside QLowEnergyController::connectToDevice(), pointing to a compatibility or configuration issue between Qt Bluetooth and your BlueZ setup.
Crash Trace
#0 0x00007ffff7931ccb in QLowEnergyController::connectToDevice() () from /usr/lib/x86_64-linux-gnu/libQt5Bluetooth.so.5 No symbol table info available. #1 0x00005555555718cc in AnkiCar::reconnect (this=0x5555557a82d0) at src/ankicar.cpp:444 No locals. #2 0x00005555555654b3 in DriveMode::requestBatteryUpdate (this=0x5555557a6400) at src/drivemode.cpp:102 racecar = 0x5555557a82d0 _container_ = {c = {<QListSpecialMethods<Racecar*>> = {<No data fields>}, {p = {static shared_null = {ref = {atomic = {_q_value = {<std::__atomic_base<int>> = {static _S_alignment = 4, _M_i = -1}, <No data fields>}}}, alloc = 0, begin = 0, end = 0, array = {0x0}}, d = 0x5555557a85a0}, d = 0x5555557a85a0}}, i = {i = 0x5555557a85b8}, e = {i = 0x5555557a85d0}, control = 1} #3 0x00005555555768df in DriveMode::qt_static_metacall (_o=0x5555557a6400, _c=QMetaObject::InvokeMetaMethod, _id=8, _a=0x7fffffffdf20) at moc_drivemode.cpp:156 _t = 0x5555557a6400 #4 0x00007ffff745f5b5 in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 No symbol table info available. #5 0x00007ffff746c027 in QTimer::timeout(QTimer::QPrivateSignal) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 No symbol table info available. #6 0x00007ffff746c388 in QTimer::timerEvent(QTimerEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 No symbol table info available. #7 0x00007ffff74600db in QObject::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 No symbol table info available. #8 0x00007ffff7430991 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 No symbol table info available. #9 0x00007ffff7488d8e in QTimerInfoList::activateTimers() () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 No symbol table info available. #10 0x00007ffff7489551 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 No symbol table info available. #11 0x00007ffff5002287 in g_main_context_dispatch () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 No symbol table info available. #12 0x00007ffff50024c0 in ?? () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 No symbol table info available. #13 0x00007ffff500254c in g_main_context_iteration () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 No symbol table info available. #14 0x00007ffff74898ef in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 No symbol table info available. #15 0x00007ffff742e9ea in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 No symbol table info available. #16 0x00007ffff7437a84 in QCoreApplication::exec() () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 No symbol table info available. #17 0x000055555555b42e in main (argc=1, argv=0x7fffffffe468) at src/main.cpp:29 a = <incomplete type>
Potential Fixes
1. Ensure BlueZ Experimental Mode is Fully Activated
You compiled BlueZ with --enable-experimental, but the service might not be using these features yet:
- Edit
/lib/systemd/system/bluetooth.serviceand update theExecStartline to:ExecStart=/usr/lib/bluetooth/bluetoothd --experimental - Reload the daemon and restart Bluetooth:
sudo systemctl daemon-reload sudo systemctl restart bluetooth - Verify experimental mode is active:
You should seebluetoothctl show | grep FeaturesExperimentalFeatureslisted in the output.
2. Downgrade BlueZ to the Project-Specified 5.42 Version
The project documentation explicitly references BlueZ 5.42. Newer versions like 5.47 may have API changes that break compatibility with Kubuntu 18.04's default Qt 5.9.x Bluetooth bindings. To downgrade:
- Uninstall your current BlueZ version:
sudo apt remove --purge bluez - Download, compile, and install BlueZ 5.42 with your required flags:
wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.42.tar.xz tar xf bluez-5.42.tar.xz cd bluez-5.42 ./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-experimental --enable-maintainer-mode make sudo make install - Restart the Bluetooth service after installation.
3. Enable Qt Bluetooth Debug Logs
Get more context about what's failing before the crash by enabling debug logging:
- Run your application with this environment variable set:
The logs may reveal issues like failed device discovery, invalid controller handles, or permission errors.QT_LOGGING_RULES="qt.bluetooth*=true" ./build/ankicar
4. Check User Bluetooth Permissions
Ensure your user has the necessary access to Bluetooth devices:
- Add your user to the
bluetoothgroup:sudo usermod -aG bluetooth $USER - Log out and back in for the changes to take effect.
5. Inspect the AnkiCar::reconnect Implementation
The crash happens in AnkiCar::reconnect at line 444 of src/ankicar.cpp. Double-check that the QLowEnergyController instance being used is valid (not a dangling pointer) before calling connectToDevice(). It's possible the controller was deleted or not properly initialized prior to this call.
内容的提问来源于stack exchange,提问作者Renji

