Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Using socketcan and qt via crosscompile

Using socketcan and qt via crosscompile

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 2 Posters 1.8k 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.
  • H Offline
    H Offline
    haxxe
    wrote on last edited by haxxe
    #1

    hi, im trying to use my can interface with qt.
    but it already fails at the init.
    im not able to create the device.
    if i use this:

    QCanBusDevice *device = QCanBus::instance()->createDevice(QStringLiteral("socketcan"), QStringLiteral("can0"));
    

    it says:

    mainwindow.cpp:20:114: error: no matching function for call to ‘QCanBus::createDevice(QString, QString)’
         QCanBusDevice *device = QCanBus::instance()->createDevice(QStringLiteral("socketcan"), QStringLiteral("can0"));
                                                                                                                      ^
    

    alt text
    why is this? is it because im compiling in my ubuntu machine and there is no socketcan available?
    The can device inside the pi is configured and ready.
    QCanBus is compiled right, or Qtserialbus respectivly.
    this is my code:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QtSerialBus/QCanBus>
    #include <QtSerialBus/QCanBusDevice>
    #include <QtSerialBus/QCanBusFrame>
    #include <QByteArray>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    void MainWindow::initCan(){
        QCanBusDevice *device = QCanBus::instance()->createDevice(QStringLiteral("socketcan"), QStringLiteral("can0"));
        device->connectDevice();
    }
    

    nothing special as it already fails in the beginning.
    what can i do?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Which version of Qt are you using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        haxxe
        wrote on last edited by
        #3

        Hi, I'm using Qt 5.9.1 on Ubuntu und 5.9 on my raspberry pi, I guess.
        But I probably found a solution.
        By adding Qt=+ serialbus in the .pro I'm able to use qcanbus properly.
        But now I have a another problem:
        Now the pi is searching for the lib5qtserialbus (or something like that, I'm not infront of my computer) lib.
        But I have qtserialbus compiled for my pi, what can I do?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you install your cross-compiled Qt on your device ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • H Offline
            H Offline
            haxxe
            wrote on last edited by haxxe
            #5

            Yes.
            now, i compiled it by myself and im finally a little bit more able to use it!
            Now i can include the QCanBus and start working, but unfortunately the first command isnt working, heres my code:

            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include <QDebug>
            #include <QCanBus>
            #include <QCanBusDevice>
            #include <QCanBusFactory>
            #include <QCanBusFrame>
            
            MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
                init();
            }
            
            MainWindow::~MainWindow()
            {
                delete ui;
            }
            
            void MainWindow::init()
            {
                QCanBusDevice *device = QCanBus::instance()->createDevice(QStringLiteral("socketcan"), QStringLiteral("vcan0"));
                  device->connectDevice();
            }
            

            alt text
            it seems like a constructor problem, but why?

            EDIT:
            And if make a QByteArray manually, he compiles my programm but the application crashed with this error:
            alt text

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Are you really sure your application doesn't load a system installed Qt on your target ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • H Offline
                H Offline
                haxxe
                wrote on last edited by
                #7

                Oh i finally got it.
                At first, i was using a tutorial von qtrpi.com and during the tutorial i made a raspberry kit with qmake version 5.7.0
                and of course im not able to use qt 5.9.1 things with qmake 5.7, after changing to a newer qmake, im able to use the code and i already sent my first testframe.
                Finally!
                One last question: i dont know why, but QCanBusDeviceInfo is still not working/isnt found, i also cannot include it.
                Why? i installed everything today fresh via the qt linux installer.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  That class has appeared in QT 5.9.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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