免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1100 | 回复: 0
打印 上一主题 下一主题

控制led的qt实验,加上布局管理器后效果好多了 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-22 10:55 |只看该作者 |倒序浏览

                控制led的qt实验,加上布局管理器后效果好多了。
hello.h--------------------------
#include
#include
#include
#include
#include
#include
class myMainWindow : public QWidget
{
    Q_OBJECT
    public:
        myMainWindow();
    public slots:
        void ledOn1();
        void ledOff1();
        void ledOn2();
        void ledOff2();
        void ledOn3();
        void ledOff3();
        void ledOn4();
        void ledOff4();
        void ledOnAll();
        void ledOffAll();
    private:
        int fd;
        QPushButton *b_on1;
        QPushButton *b_off1;
        QPushButton *b_on2;
        QPushButton *b_off2;
        QPushButton *b_on3;
        QPushButton *b_off3;
        QPushButton *b_on4;
        QPushButton *b_off4;
        QPushButton *b_onAll;
        QPushButton *b_offAll;
        QLabel *label;
};
hello.cpp--------------------------
#include
#include
#include
#include
#include
#include
class myMainWindow : public QWidget
{
    Q_OBJECT
    public:
        myMainWindow();
    public slots:
        void ledOn1();
        void ledOff1();
        void ledOn2();
        void ledOff2();
        void ledOn3();
        void ledOff3();
        void ledOn4();
        void ledOff4();
        void ledOnAll();
        void ledOffAll();
    private:
        int fd;
        QPushButton *b_on1;
        QPushButton *b_off1;
        QPushButton *b_on2;
        QPushButton *b_off2;
        QPushButton *b_on3;
        QPushButton *b_off3;
        QPushButton *b_on4;
        QPushButton *b_off4;
        QPushButton *b_onAll;
        QPushButton *b_offAll;
        QLabel *label;
};
hello.cpp------------------------
#include "hello.h"
myMainWindow::myMainWindow()
{
    setMinimumSize(200,200);
    label = new QLabel(this);
    label->setMinimumSize(150,30);
    label->setMaximumSize(240,30);
    label->setText("press these buttons to\n"
                    "control the leds on or off");
    label->setAlignment(AlignCenter);
    b_on1 = new QPushButton("on 1",this);
    b_on1->setMinimumSize(50,20);
    b_on1->setFont(QFont("Times",15,QFont::Bold));
    b_off1 = new QPushButton("off 1",this);
    b_off1->setMinimumSize(50,20);
    b_off1->setFont(QFont("Times",15,QFont::Bold));
    b_on2 = new QPushButton("on 2",this);
    b_on2->setMinimumSize(50,20);
    b_on2->setFont(QFont("Times",15,QFont::Bold));
    b_off2 = new QPushButton("off 2",this);
    b_off2->setMinimumSize(50,20);
    b_off2->setFont(QFont("Times",15,QFont::Bold));
    b_on3 = new QPushButton("on 3",this);
    b_on3->setMinimumSize(50,20);
    b_on3->setFont(QFont("Times",15,QFont::Bold));
    b_off3 = new QPushButton("off 3",this);
    b_off3->setMinimumSize(50,20);
    b_off3->setFont(QFont("Times",15,QFont::Bold));
    b_on4 = new QPushButton("on 4",this);
    b_on4->setMinimumSize(50,20);
    b_on4->setFont(QFont("Times",15,QFont::Bold));
    b_off4 = new QPushButton("off 4",this);
    b_off4->setMinimumSize(50,20);
    b_off4->setFont(QFont("Times",15,QFont::Bold));
    b_onAll = new QPushButton("on All",this);
    b_onAll->setMinimumSize(50,20);
    b_onAll->setFont(QFont("Times",15,QFont::Bold));
    b_offAll = new QPushButton("off All",this);
    b_offAll->setMinimumSize(50,20);
    b_offAll->setFont(QFont("Times",15,QFont::Bold));
    QVBoxLayout *vbox = new QVBoxLayout(this);
    QHBoxLayout *hbox1 = new QHBoxLayout();
    QHBoxLayout *hbox2 = new QHBoxLayout();
    QHBoxLayout *hbox3 = new QHBoxLayout();
    QHBoxLayout *hbox4 = new QHBoxLayout();
    QHBoxLayout *hbox5 = new QHBoxLayout();
    QHBoxLayout *hbox6 = new QHBoxLayout();
    vbox->addLayout(hbox1);
    vbox->addLayout(hbox2);
    vbox->addLayout(hbox3);
    vbox->addLayout(hbox4);
    vbox->addLayout(hbox5);
    vbox->addLayout(hbox6);
    hbox1->addWidget(label);
    hbox2->addWidget(b_on1);
    hbox2->addWidget(b_off1);
    hbox3->addWidget(b_on2);
    hbox3->addWidget(b_off2);
    hbox4->addWidget(b_on3);
    hbox4->addWidget(b_off3);
    hbox5->addWidget(b_on4);
    hbox5->addWidget(b_off4);
    hbox6->addWidget(b_onAll);
    hbox6->addWidget(b_offAll);
    connect(b_on1,SIGNAL(clicked()),this,SLOT(ledOn1()));
    connect(b_off1,SIGNAL(clicked()),this,SLOT(ledOff1()));
    connect(b_on2,SIGNAL(clicked()),this,SLOT(ledOn2()));
    connect(b_off2,SIGNAL(clicked()),this,SLOT(ledOff2()));
    connect(b_on3,SIGNAL(clicked()),this,SLOT(ledOn3()));
    connect(b_off3,SIGNAL(clicked()),this,SLOT(ledOff3()));
    connect(b_on4,SIGNAL(clicked()),this,SLOT(ledOn4()));
    connect(b_off4,SIGNAL(clicked()),this,SLOT(ledOff4()));
    connect(b_onAll,SIGNAL(clicked()),this,SLOT(ledOnAll()));
    connect(b_offAll,SIGNAL(clicked()),this,SLOT(ledOffAll()));
}
#include
#include
#include
#include
#include
#include
#include
void myMainWindow::ledOn1()
{
    fd = open("/dev/leds0", 0);
    if (fd



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93291/showart_2100270.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP