Using socketcan and qt via crosscompile



  • 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?


  • Lifetime Qt Champion

    Hi,

    Which version of Qt are you using ?



  • 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?


  • Lifetime Qt Champion

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



  • 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


  • Lifetime Qt Champion

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



  • 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.


  • Lifetime Qt Champion

    That class has appeared in QT 5.9.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.