QT and SPI on Raspberry PI (include files problem)
Hi,
I am trying to use SPI bus on Raspberry wit Qt framework but without 3rd party libraries.
I have tried to implement simple loopback test (https://www.raspberrypi.org/document.../spi/README.md) but I have got following errors:
Code:
/usr/include/c++/6/bits/stl_algo.h:59: In file included from /usr/include/c++/6/bits/stl_algo.h:59:0,
/usr/include/c++/6/algorithm:62: from /usr/include/c++/6/algorithm:62,
/usr/include/arm-linux-gnueabihf/qt5/QtCore/qglobal.h:94: from /usr/include/arm-linux-gnueabihf/qt5/QtCore/qglobal.h:94,
/usr/include/arm-linux-gnueabihf/qt5/QtGui/qwindowdefs.h:43: from /usr/include/arm-linux-gnueabihf/qt5/QtGui/qwindowdefs.h:43,
/usr/include/arm-linux-gnueabihf/qt5/QtWidgets/qwidget.h:43: from /usr/include/arm-linux-gnueabihf/qt5/QtWidgets/qwidget.h:43,
/usr/include/arm-linux-gnueabihf/qt5/QtWidgets/qmainwindow.h:43: from /usr/include/arm-linux-gnueabihf/qt5/QtWidgets/qmainwindow.h:43,
/usr
/include
/arm
-linux
-gnueabihf
/qt5
/QtWidgets
/QMainWindow:1: from
/usr
/include
/arm
-linux
-gnueabihf
/qt5
/QtWidgets
/QMainWindow:1,
/home/pi/MyAppFolder/application/MyApp/mainwindow.h:14: from ../MyApp/mainwindow.h:14,
/home/pi/MyAppFolder/application/MyApp/main.cpp:1: from ../MyApp/main.cpp:1:
/usr/include/c++/6/cstdlib:75: error: stdlib.h: No such file or directory
#include_next <stdlib.h>
My .pro file is:
Code:
#-------------------------------------------------
#
# Project created by QtCreator 2018-06-13T08:59:05
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MyApp
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
mainwindow.cpp \
cbc.cpp \
spi.cpp
HEADERS += mainwindow.h \
cbc.h
FORMS += mainwindow.ui
#LIBS+=-L/usr/local/lib -lwiringPi
INCLUDEPATH+=/usr/include
My includes are:
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <linux/ioctl.h> //in spidev_test it is <sys/ioctl.h> but i don't have this header in sys folfder
#include <linux/types.h>
#include <linux/spi/spidev.h>
#include <QMainWindow>
#include "qmessagebox.h"
#include "qstorageinfo.h"
#include "qstring.h"
#include "qtextstream.h"
//#include </root/wiringPi/wiringPi/wiringPiSPI.h>
//#include </root/wiringPi/wiringPi/wiringPi.h>
If I remove INCLUDEPATH+=/usr/include from .pro file then include files can not be located.
Can someone help me with this error.
P.S. Another solution to this problem can be example of usage of wiringPiSPI for spidev1.0
Thanks in advance!
Re: QT and SPI on Raspberry PI (include files problem)
Quote:
/usr/include/c++/6/cstdlib:75: error: stdlib.h: No such file or directory
#include_next <stdlib.h>
Your problem does not seem to be an issue with SPI but with your STL includes.
Try using the form:
Code:
//#include <stdint.h>
//#include <unistd.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include <getopt.h>
//#include <fcntl.h>
#include <stdint>
#include <unistd>
#include <stdio>
#include <stdlib>
#include <getopt>
#include <fcntl>
And see if it helps.
Re: QT and SPI on Raspberry PI (include files problem)
Quote:
Originally Posted by
high_flyer
Your problem does not seem to be an issue with SPI but with your STL includes.
Try using the form:
Code:
//#include <stdint.h>
//#include <unistd.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include <getopt.h>
//#include <fcntl.h>
#include <stdint>
#include <unistd>
#include <stdio>
#include <stdlib>
#include <getopt>
#include <fcntl>
And see if it helps.
Thank you for your reply.
I have tried your solution but then I have got following error:
Code:
In file included from ../MyApp/main.cpp:1:0:
stdint: No such file or directory
I agree that the problem is with including standard headers but I do not know how to resolve this issue.
Did I correctly write line in .pro file?
Code:
INCLUDEPATH+=/usr/include
Re: QT and SPI on Raspberry PI (include files problem)
I have solved the problem with STL includes.
The INCLUDEPATH+=/usr/include line should be removed, but this path should be added to Tools->Options->C++->File Naming->Search Paths (add /usr/include).
For SPI header linux/ioctl.h must be changed to sys/ioctl.h like in original spidev_test.c.
After this modification I successfully tested SPI but now I am facing other problems with it. I can not call close() function and I can not change spidev1.0 mode to 1. I know that this is not a topic for this forum, so I will ask it somewhere elese but if someone has any ideas about my problem, please write.
Best regards.