天嵌 ARM开发社区

 找回密码
 注册
查看: 1942|回复: 5

弱弱的问下这段QT程序为什么不对啊?

[复制链接]
yezhubenyue 发表于 2010-12-24 11:36:23 | 显示全部楼层 |阅读模式
  1. //main.cpp
  2. #include"mybeep.h"
  3. #include<QApplication>
  4. int main(int argc, char *argv[])
  5. {
  6.     QApplication app(argc,argv);
  7.     beep *b;
  8.     b->show();
  9.     return app.exec();
  10. }


复制代码
  1. //mybeep.h
  2. #ifndef MYBEEP_H
  3. #define MYBEEP_H
  4. #include <QtGui>
  5. class beep:public QMainWindow
  6. {
  7. Q_OBJECT
  8. public:
  9.   beep();
  10. public:
  11.   QPushButton *button;
  12. private slots:
  13.   void beep_init();
  14. };
  15. #endif // MYBEEP_H

复制代码
  1. //mybeep.cpp
  2. #include"mybeep.h"
  3. #include<QtGui>
  4. #include<sys/types.h>
  5. #include<sys/stat.h>
  6. #include<fcntl.h>
  7. #include<string.h>
  8. #include<sys/ioctl.h>
  9. #include<stdio.h>
  10. #include<QDirectPainter>
  11.   static int fd;
  12. beep::beep()
  13. {
  14. button=new QPushButton;
  15. button->setText("hello word");
  16. connect(button,SIGNAL(clicked()),this,SLOT(beep_init()));
  17. }
  18. void beep::beep_init()
  19. {
  20. fd=open("/dev/PWM-Test",O_RDWR);
  21. if(fd<0)
  22. {
  23. close();
  24. }
  25. ioctl(fd,10,4);
  26. }
复制代码
编译的时候能通过但烧到板子上的时候就报Segmentation fault错  谢谢了~~
天嵌_support1 发表于 2010-12-24 14:21:17 | 显示全部楼层
1# yezhubenyue


用什么编译器呢?
 楼主| yezhubenyue 发表于 2010-12-24 14:38:55 | 显示全部楼层
2# embedsky_lxt


用的是qt creator 代码我找到原因了,是  beep *b;
指针没初始化。
现在的问题是我按了button之后蜂鸣器没反应~~!那个
槽这样写对吗?
connect(button,SIGNAL(clicked()),this,SLOT(beep_init()));
void beep::beep_init()
{
fd=open("/dev/PWM-Test",O_RDWR);
ioctl(fd,10,4);
}


还有led灯的槽
这样写也没反应
void led::led_init()
{
fd=open("/dev/GPIO-Control",O_RDWR);
ioctl(fd,0,0);
ioctl(fd,0,1);
ioctl(fd,0,2);
ioctl(fd,0,3);
}我看手册上好像也是这么写的为什么不对啊?谢谢了
 楼主| yezhubenyue 发表于 2010-12-24 17:18:59 | 显示全部楼层
这里void beep::beep_init()
{
fd=open("/dev/PWM-Test",O_RDWR);
if(fd<0)
{
perror("open device fail");
}
ioctl(fd,10,4);
}
这里串口上输出的是open device fail: Device or resource busy
不知道为什么打不开啊?
天嵌_support1 发表于 2010-12-24 18:55:26 | 显示全部楼层
4# yezhubenyue


你是打开了设备,但是没有关闭啊
 楼主| yezhubenyue 发表于 2010-12-24 20:19:44 | 显示全部楼层
5# embedsky_lxt


那个再问下咋么关闭设备啊,我输close(fp);QT下报错,说没这个函数。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-9-28 01:27 , Processed in 1.039102 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表