• 8370阅读
  • 5回复

qt编程中能不能open()打开linux下的设备? [复制链接]

上一主题 下一主题
离线slbbls
 
只看楼主 倒序阅读 楼主  发表于: 2010-01-04
想在板子上读取串口,能不能像在linux下编程一样open设备来做?
怎么open()没定义什么的
大侠们帮帮忙吧
离线dbzhang800

只看该作者 1楼 发表于: 2010-01-04
系统api 该怎么用就怎么用,Qt对此没影响
离线slbbls
只看该作者 2楼 发表于: 2010-01-04
int car::com_init()
{
    struct termios opt;

    gps_fd=open("/dev/ttySAC1",O_RDONLY);
}

编译报错:
car.cpp: In member function 'int car::com_init()':
car.cpp:33: error: no matching function for call to 'car::open(const char [13], int)'
../QT/QtE-4.5.3/include/QtGui/qdialog.h:99: note: candidates are: void QDialog::open()


我在程序里加了头文件啦
#include <termios.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>

不知道这错误怎么回事???
离线dbzhang800

只看该作者 3楼 发表于: 2010-01-04
引用第2楼slbbls于2010-01-04 11:48发表的  :
int car::com_init()
{
    struct termios opt;
    gps_fd=::open("/dev/ttySAC1",O_RDONLY);
.......
离线slbbls
只看该作者 4楼 发表于: 2010-01-04
谢谢楼上的,我是新手,刚开始学,也没学过C++
不知道为什么要加::
离线dbzhang800

只看该作者 5楼 发表于: 2010-01-04
引用第4楼slbbls于2010-01-04 12:03发表的  :
谢谢楼上的,我是新手,刚开始学,也没学过C++
不知道为什么要加::


Qt  是 C++ 的库,学Qt必然要学C++

你这个是 C++ 的 命名空间和作用域 的问题
快速回复
限100 字节
 
上一个 下一个