Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to run CAN Bus example in QtCreator ?
Forum Update on Monday, May 27th 2025

How to run CAN Bus example in QtCreator ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imene
    wrote on last edited by imene
    #1

    Hello,
    I want to run CAN Bus example in QtCreator but it doesn't exist in QtCreator examples list !
    https://stuff.mit.edu/afs/athena/software/texmaker_v5.0.2/qt57/doc/qtserialbus/qtserialbus-can-example.html

    This is what i get when i implement it as a new project:
    49b22e95-1b9a-4498-a29c-fa651b1ecbcc-image.png

    OS: Raspbian GNU/Linux 11 (bullseye) [linux version 5.15.53-v7+]
    Qt Creator 4.14.1
    Based on Qt 5.15.2 (GCC 10.2.1 20210110, 32 bit)

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      Check you have serialbus added in your .pro

      QT += serialbus widgets

      I found the can example in:
      Qt5.xx⁩ ▸ ⁨Examples⁩ ▸ ⁨Qt-5.xx⁩ ▸ ⁨serialbus⁩ ▸ ⁨can

      1 Reply Last reply
      1
      • I Offline
        I Offline
        imene
        wrote on last edited by
        #3

        Hi @mpergand
        QT += serialbus widgets doesn't exist in my .pro file should i uncomment line n°9 ? :
        d5e947c6-28ae-415b-9ba3-3774843e3f60-image.png
        i didn't find serialbus example:
        69aa099d-022f-48b8-b1ed-919f92b3babe-image.png

        JonBJ 1 Reply Last reply
        0
        • I imene

          Hi @mpergand
          QT += serialbus widgets doesn't exist in my .pro file should i uncomment line n°9 ? :
          d5e947c6-28ae-415b-9ba3-3774843e3f60-image.png
          i didn't find serialbus example:
          69aa099d-022f-48b8-b1ed-919f92b3babe-image.png

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @imene
          You have to add it yourself! E.g. put that QT += serialbus widgets as a line beneath the existing QT += ... one.
          Oh and after doing that make sure you do a complete new qmake before proceeding to compile.

          1 Reply Last reply
          0
          • I Offline
            I Offline
            imene
            wrote on last edited by imene
            #5

            Hi @JonB
            i've made a mistake, i forget to past the right code of .pro from the site this is the right one contain QT += serialbus widgets :
            6173f01b-0b13-4a51-8b47-6f250d5d179a-image.png

            Now i'm facing those issues "invalid initiazation of reference of type 'const QByteArray&' from expression of type 'const QString'":

            b4144874-5582-4e75-8fd1-a1e9e3c06e24-image.png

            JonBJ 1 Reply Last reply
            0
            • I imene

              Hi @JonB
              i've made a mistake, i forget to past the right code of .pro from the site this is the right one contain QT += serialbus widgets :
              6173f01b-0b13-4a51-8b47-6f250d5d179a-image.png

              Now i'm facing those issues "invalid initiazation of reference of type 'const QByteArray&' from expression of type 'const QString'":

              b4144874-5582-4e75-8fd1-a1e9e3c06e24-image.png

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @imene
              I know nothing about this, but look at your line #199 (connectdialog.cpp, your code?). I see something like an attempt to use a QByteArray & to iterate through a QStringList?

              M 1 Reply Last reply
              0
              • JonBJ JonB

                @imene
                I know nothing about this, but look at your line #199 (connectdialog.cpp, your code?). I see something like an attempt to use a QByteArray & to iterate through a QStringList?

                M Offline
                M Offline
                mpergand
                wrote on last edited by mpergand
                #7

                Seems you're using an old version, from the version in Qt 5.12, I see no usage of Q_FOREACH nor QByteArray in ConnectDialog.

                It seems in the new version, it looks like that:

                for (const QCanBusDeviceInfo &info : qAsConst(m_interfaces)) {

                And @JonB guessing right, m_interfaces is a QList of QCanBusDeviceInfo

                I suggest you to update to a newer version to avoid unnecessary headaches.

                1 Reply Last reply
                1
                • I Offline
                  I Offline
                  imene
                  wrote on last edited by
                  #8

                  Hi @mpergand i can't make an update it's already the newest version available under debian(bullseye) OS Qt 5.15.2 (GCC 10.2.1 20210110, 32 bit)

                  M 1 Reply Last reply
                  0
                  • I imene

                    Hi @mpergand i can't make an update it's already the newest version available under debian(bullseye) OS Qt 5.15.2 (GCC 10.2.1 20210110, 32 bit)

                    M Offline
                    M Offline
                    mpergand
                    wrote on last edited by
                    #9

                    @imene
                    You are using an incompatible version of the CAN example with Qt 5.15, because of that:
                    In Qt 5.6 QCanBus class

                    QList<QByteArray> plugins() const; 
                    

                    In Qt 5.15 :

                    QStringList QCanBus::plugins() const
                    

                    The CAN example you are using is not the one provide with Qt 5.15 and you must use the right one otherwise it doesn't compile.

                    1 Reply Last reply
                    2
                    • I Offline
                      I Offline
                      imene
                      wrote on last edited by imene
                      #10

                      Thanks @mpergand i'm gonna try to implement this example CAN Bus example | Qt Serial Bus 5.15.2 (https://code.qt.io/cgit/qt/qtserialbus.git/tree/examples/serialbus/can?h=5.15.2) i hope it works

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved