<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to detect if a QCanBusDevice has been physically disconnected?]]></title><description><![CDATA[<p dir="auto">I'm using QCanBusDevice to interface with a Peak Can-Usb adapter.</p>
<p dir="auto">How can I tell if the device has been removed, i.e. the usb adapter has been physically disconnected from my computer? I looked at all methods QCanBusDevice offers, but none of them tell me if the device is still physically connected.</p>
<ul>
<li>QCanBusDevice::state() remains in the ConnectedState (this is probably the most counterintuitive)</li>
<li>QCanBusDevice::hasBusStatus() remains true</li>
<li>neither QCanBusDevice::error() nor QCanBusDevice::errorString() report  an error</li>
<li>QCanBusDevice::errorOccured() is not emitted</li>
</ul>
<p dir="auto">It seems like the QCanBusDevice doesnt notice at all that adapter is no longer there.<br />
The <strong>only</strong> thing that seems to change (and what I'm using right now) is the QCanBusDevice::deviceInfo(), which goes blank when you remove the adapter. Still, this seems rather hacky, so I'm wondering if I'm doing something unintended or if this feature is simply not implemented in QCanBusDevice (or PeakCanBackend to be specific)</p>
]]></description><link>https://forum.qt.io/topic/165182/how-to-detect-if-a-qcanbusdevice-has-been-physically-disconnected</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Nov 2026 05:02:35 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/165182.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 Oct 2026 14:04:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to detect if a QCanBusDevice has been physically disconnected? on Wed, 21 Oct 2026 09:00:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/aha_1980">@<bdi>aha_1980</bdi></a> Thanks for taking care of this!</p>
<p dir="auto">I think a method like <code>deviceState()</code> or <code>deviceType()</code> would be appropriate and offer more flexibility for the different CAN plugins. I wouldn't change <code>QCanBusDevice::state()</code> or <code>busStatus()</code>, they have a different meaning.</p>
<p dir="auto">I have noticed that the Peak USB devices actually fall back to a virtual CAN interface the moment you disconnect the usb device (the virtual interface is called "PCANLight_USB_16" in PCAN-View). This might explain why no errors are reported and the QCanBusDevice remains connected - the virtual interface is still working. This automatic fallback seems to be an intended feature of the peak driver.</p>
<p dir="auto">Ideally there'd be a <code>DeviceType</code> enum with values like <code>Virtual</code> and <code>Physical</code> to represent what kind of device it currently is. But this switching behaviour seems pretty specific to peak devices, so perhaps somebody has an idea for a more general approach.<br />
Ideally-ideally this change would also be emitted as a signal :)</p>
]]></description><link>https://forum.qt.io/post/840552</link><guid isPermaLink="true">https://forum.qt.io/post/840552</guid><dc:creator><![CDATA[__mk__]]></dc:creator><pubDate>Wed, 21 Oct 2026 09:00:38 GMT</pubDate></item><item><title><![CDATA[Reply to How to detect if a QCanBusDevice has been physically disconnected? on Fri, 16 Oct 2026 16:47:52 GMT]]></title><description><![CDATA[<p dir="auto">I've added a task for that: <a href="https://qt-project.atlassian.net/browse/QTBUG-151640" target="_blank" rel="noopener noreferrer nofollow ugc">https://qt-project.atlassian.net/browse/QTBUG-151640</a></p>
]]></description><link>https://forum.qt.io/post/840522</link><guid isPermaLink="true">https://forum.qt.io/post/840522</guid><dc:creator><![CDATA[aha_1980]]></dc:creator><pubDate>Fri, 16 Oct 2026 16:47:52 GMT</pubDate></item><item><title><![CDATA[Reply to How to detect if a QCanBusDevice has been physically disconnected? on Fri, 16 Oct 2026 14:49:37 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/__mk__">@<bdi>__mk__</bdi></a> ,</p>
<p dir="auto">there is indeed no dedicated API for that problem currently.</p>
<p dir="auto">What comes closest is <code>QCanBusDevice::busStatus()</code>, but that will currently (most likely) return <code>CanBusStatus::Unknown</code> as there is no special enum for that case.</p>
<p dir="auto">But I'll take your post as feature request and see if I can add something. I'm not completely sure if that fits into <code>busStatus()</code> or if a separated <code>deviceStatus()</code> would be better. I'm open for suggestions.</p>
<p dir="auto">Note: <code>QCanBusDevice::hasBusStatus() </code> just tells you if the device supports the function <code>busStatus()</code>, it is <em>not</em> the actual <code>busStatus()</code>.</p>
<p dir="auto">Regards</p>
]]></description><link>https://forum.qt.io/post/840521</link><guid isPermaLink="true">https://forum.qt.io/post/840521</guid><dc:creator><![CDATA[aha_1980]]></dc:creator><pubDate>Fri, 16 Oct 2026 14:49:37 GMT</pubDate></item></channel></rss>