#ifndef MYBUTTON_H_
#define MYBUTTON_H_
#include<iostream>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
class MyButton : public QPushButton
{
Q_OBJECT
public:
MyButton(const QString &text, QWidget * parent)
~MyButton()
public:
void setLed(int argc, char *argv[])
public slots:
void sendButtonText()
private:
signals:
void isClickButton(const QString &text)
}
#endif
[cpp] view plain copy
/**********MyButton.cpp************/
#include "MyButton.h"
extern "C"{
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>物纯
#include <sys/ioctl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
void MyButton::setLed(int argc, char *argv[]){
int on
int led_number
int fd
if (argc != 3 || sscanf(argv[1], "%d", &led_number) != 1 || sscanf(argv[2],"%d", &on) != 1 ||
on <0 || on >1 || led_number <0 || led_number >罩者咐 3) {
fprintf(stderr, "Usage:\n")
fprintf(stderr, "\t led led_number on|off\n"嫌手)
fprintf(stderr, "Options:\n")
fprintf(stderr, "\t led_number from 0 to 3\n")
fprintf(stderr, "\t on 1off 0\n")
exit(1)
}
fd = open("/dev/led", 0)
if (fd <0) {
perror("open device /dev/led")
exit(1)
}
ioctl(fd, on, led_number)
::close(fd) //请注意,此处如果要调用C语言库中的close()一定要加上“::",否则程序将到当前类的作用域中寻找close()方法,导致不明错误。
}
}
MyButton::MyButton(const QString &text,QWidget *widget)
:QPushButton(text,widget)
{
connect(this,SIGNAL(clicked()),this,SLOT(sendButtonText()))
}
MyButton::~MyButton()
{
}
void MyButton::sendButtonText(){
emit isClickButton(this->text())
char open_1[]="1"
char open_2[]="1"
char open_3[]="1"
char *o1=open_1
char *o2=open_2
char *o3=open_3
char close_1[]="1"
char close_2[]="1"
char close_3[]="0"
char *c1=close_1
char *c2=close_2
char *c3=close_3
char *open[]={o1,o2,o3}
char *close[]={c1,c2,c3}
QString *str=new QString(this->text())
if((str->compare("mb1"))==0){
std::cout<<"mb1 is clicked!\n"
setLed(3,open)
}
if((str->compare("mb2"))==0){
std::cout<<"mb2 is clicked!\n"
setLed(3,close)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)