<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qcanbus.cpp --> <title>QCanBus Class | Qt Serial Bus 5.9</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.9</td><td ><a href="qtserialbus-index.html">Qt Serial Bus</a></td><td ><a href="qtserialbus-module.html">C++ Classes</a></td><td >QCanBus</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#public-functions">Public Functions</a></li> <li class="level1"><a href="#static-public-members">Static Public Members</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">QCanBus Class</h1> <!-- $$$QCanBus-brief --> <p>The <a href="qcanbus.html">QCanBus</a> class handles registration and creation of bus plugins. <a href="#details">More...</a></p> <!-- @@@QCanBus --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QCanBus></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += serialbus</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign"> Qt 5.8</td></tr></table></div><ul> <li><a href="qcanbus-members.html">List of all members, including inherited members</a></li> </ul> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> QList<QCanBusDeviceInfo> </td><td class="memItemRight bottomAlign"><b><a href="qcanbus.html#availableDevices">availableDevices</a></b>(const QString &<i>plugin</i>, QString *<i>errorMessage</i> = nullptr) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QCanBusDevice *</td><td class="memItemRight bottomAlign"><b><a href="qcanbus.html#createDevice">createDevice</a></b>(const QString &<i>plugin</i>, const QString &<i>interfaceName</i>, QString *<i>errorMessage</i> = nullptr) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QStringList </td><td class="memItemRight bottomAlign"><b><a href="qcanbus.html#plugins">plugins</a></b>() const</td></tr> </table></div> <a name="static-public-members"></a> <h2 id="static-public-members">Static Public Members</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> QCanBus *</td><td class="memItemRight bottomAlign"><b><a href="qcanbus.html#instance">instance</a></b>()</td></tr> </table></div> <a name="details"></a> <!-- $$$QCanBus-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qcanbus.html">QCanBus</a> class handles registration and creation of bus plugins.</p> <p><a href="qcanbus.html">QCanBus</a> loads Qt CAN Bus plugins at runtime. The ownership of serial bus plugins is transferred to the loader.</p> </div> <!-- @@@QCanBus --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$availableDevices[overload1]$$$availableDevicesconstQString&QString* --> <h3 class="fn" id="availableDevices"><a name="availableDevices"></a><span class="type">QList</span><<span class="type"><a href="qcanbusdeviceinfo.html">QCanBusDeviceInfo</a></span>> QCanBus::<span class="name">availableDevices</span>(const <span class="type">QString</span> &<i>plugin</i>, <span class="type">QString</span> *<i>errorMessage</i> = nullptr) const</h3> <p>Returns the available interfaces for <i>plugin</i>. In case of failure, the optional parameter <i>errorMessage</i> returns a textual error description.</p> <p><b>Note: </b>Some plugins might not or only partially support this function.</p><p>For example, the following call returns a list of all available SocketCAN interfaces (which can be used for <a href="qcanbus.html#createDevice">createDevice</a>()):</p> <pre class="cpp"> <span class="type">QString</span> errorString; <span class="keyword">const</span> <span class="type">QList</span><span class="operator"><</span><span class="type"><a href="qcanbusdeviceinfo.html">QCanBusDeviceInfo</a></span><span class="operator">></span> devices <span class="operator">=</span> <span class="type">QCanBus</span><span class="operator">::</span>instance()<span class="operator">-</span><span class="operator">></span>availableDevices( <span class="type">QStringLiteral</span>(<span class="string">"socketcan"</span>)<span class="operator">,</span> <span class="operator">&</span>errorString); <span class="keyword">if</span> (<span class="operator">!</span>errorString<span class="operator">.</span>isEmpty()) qDebug() <span class="operator"><</span><span class="operator"><</span> errorString; </pre> <p>This function was introduced in Qt 5.9.</p> <p><b>See also </b><a href="qcanbus.html#createDevice">createDevice</a>().</p> <!-- @@@availableDevices --> <!-- $$$createDevice[overload1]$$$createDeviceconstQString&constQString&QString* --> <h3 class="fn" id="createDevice"><a name="createDevice"></a><span class="type"><a href="qcanbusdevice.html">QCanBusDevice</a></span> *QCanBus::<span class="name">createDevice</span>(const <span class="type">QString</span> &<i>plugin</i>, const <span class="type">QString</span> &<i>interfaceName</i>, <span class="type">QString</span> *<i>errorMessage</i> = nullptr) const</h3> <p>Creates a CAN bus device. <i>plugin</i> is the name of the plugin as returned by the <a href="qcanbus.html#plugins">plugins</a>() method. <i>interfaceName</i> is the CAN bus interface name. In case of failure, the optional parameter <i>errorMessage</i> returns a textual error description.</p> <p>Ownership of the returned plugin is transferred to the caller. Returns <code>nullptr</code> if no suitable device can be found.</p> <p>For example, the following call would connect to the SocketCAN interface vcan0:</p> <pre class="cpp"> <span class="type">QString</span> errorString; <span class="type"><a href="qcanbusdevice.html">QCanBusDevice</a></span> <span class="operator">*</span>device <span class="operator">=</span> <span class="type">QCanBus</span><span class="operator">::</span>instance()<span class="operator">-</span><span class="operator">></span>createDevice( <span class="type">QStringLiteral</span>(<span class="string">"socketcan"</span>)<span class="operator">,</span> <span class="type">QStringLiteral</span>(<span class="string">"vcan0"</span>)<span class="operator">,</span> <span class="operator">&</span>errorString); <span class="keyword">if</span> (<span class="operator">!</span>device) qDebug() <span class="operator"><</span><span class="operator"><</span> errorString; <span class="keyword">else</span> device<span class="operator">-</span><span class="operator">></span>connectDevice(); </pre> <p><b>Note: </b>The <i>interfaceName</i> is plugin-dependent. See the corresponding plugin documentation for more information: <a href="qtcanbus-backends.html#can-bus-plugins">CAN Bus Plugins</a>. To get a list of available interfaces, <a href="qcanbus.html#availableDevices">availableDevices</a>() can be used.</p><p><b>See also </b><a href="qcanbus.html#availableDevices">availableDevices</a>().</p> <!-- @@@createDevice --> <!-- $$$instance[overload1]$$$instance --> <h3 class="fn" id="instance"><a name="instance"></a><code>[static] </code><span class="type">QCanBus</span> *QCanBus::<span class="name">instance</span>()</h3> <p>Returns a pointer to the <a href="qcanbus.html">QCanBus</a> class. The object is loaded if necessary. <a href="qcanbus.html">QCanBus</a> uses the singleton design pattern.</p> <!-- @@@instance --> <!-- $$$plugins[overload1]$$$plugins --> <h3 class="fn" id="plugins"><a name="plugins"></a><span class="type">QStringList</span> QCanBus::<span class="name">plugins</span>() const</h3> <p>Returns a list of identifiers for all loaded plugins.</p> <!-- @@@plugins --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>