主题 : 如何在QT里面对dev进行操作啊 复制链接 | 浏览器收藏 | 打印
级别: 侠客
UID: 90672
精华: 0
发帖: 71
金钱: 355 两
威望: 71 点
综合积分: 142 分
注册时间: 2013-04-22
最后登录: 2013-10-27
楼主  发表于: 2013-05-20 10:16

 如何在QT里面对dev进行操作啊

micro2440开发板,显示界面已经基本设计完成了,接下来要对底层的设备进行操作,比如PWM等。
在网上找了很多源代码,基本上了解是通过open等函数进行操作,但是这些代码都用到了一个称为Form的类,里面有open等函数,
我的界面是用QWidget设计的啊,好像没有open这些函数啊,我用的Qte4.6.3

我把别人的代码用我的QtCreate编译,也通不过。

哪位大侠知道是怎么回事啊?
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2013-05-20 16:39

 回 楼主(zjun726) 的帖子

我不熟悉Form类,不过我确定你可以用open函数(http://linux.die.net/man/2/open)操作设备文件。这是系统调用,只要你的系统里有C库,就可以使用。关于系统调用,可以参考http://www.cnblogs.com/yanlingyin/archive/2012/04/23/2466141.html
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 90672
精华: 0
发帖: 71
金钱: 355 两
威望: 71 点
综合积分: 142 分
注册时间: 2013-04-22
最后登录: 2013-10-27
2楼  发表于: 2013-05-21 22:32

 回 1楼(kasim) 的帖子

谢谢,我看到别人的例子中用到的是::open(),不太明白为什么要在open前面加上::
级别: 侠客
UID: 90672
精华: 0
发帖: 71
金钱: 355 两
威望: 71 点
综合积分: 142 分
注册时间: 2013-04-22
最后登录: 2013-10-27
3楼  发表于: 2013-05-22 08:56

 回 1楼(kasim) 的帖子

今天试了一下,但是提示 open was not declared in this scope. 源码如下,哪里出错了吗?
#include "smartdelaywidget.h"
#include <QApplication>
#include <QWSServer>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    int fd;

    QApplication a(argc, argv);
    SmartDelayWidget w;
    QWSServer::setCursorVisible(false); //hide the cursor
    w.setWindowFlags(Qt::FramelessWindowHint);  //hide the Window title
    w.show();

    fd = open("/dev/pwm", 0);
    if (fd < 0) {
        perror("open pwm_buzzer device");
        exit(1);
    }
  
    return a.exec();
}
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
4楼  发表于: 2013-05-23 22:36

 回 3楼(zjun726) 的帖子

能否给出编译过程完整的命令行及其输出?
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 90672
精华: 0
发帖: 71
金钱: 355 两
威望: 71 点
综合积分: 142 分
注册时间: 2013-04-22
最后登录: 2013-10-27
5楼  发表于: 2013-05-28 11:00

 回 4楼(kasim) 的帖子

这个问题解决了,原因是头文件<fcntl.h>没有include进去