/*******************************************************************
* OK335xS tmp75 Qt 温度读取
* 说明:
* 简单的Qt显示tmp75温度值,其驱动已经在Linux驱动中存在,只需要
* 注册一下I2C设备就行了。
*
* 2016-3-26 深圳 南山平山村 曾剑锋
******************************************************************/ \\\\\\\\\\\-*- 目录 -*-///////////
| 一、cat main.c
| 二、cat mainwindow.h
| 三、cat mainwindow.cpp
| 四、cat temperaturethread.h
| 五、cat temperaturethread.cpp
|||||||||||||||||||||||||||||||||| 一、cat main.c
#include "mainwindow.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.setWindowFlags(w.windowFlags()& ~Qt::WindowMaximizeButtonHint& ~Qt::WindowMinimizeButtonHint);
w.show(); return a.exec();
} 二、cat mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow>
#include <temperaturethread.h>
#include <QString> namespace Ui {
class MainWindow;
} class MainWindow : public QMainWindow
{
Q_OBJECT public:
explicit MainWindow(QWidget *parent = );
~MainWindow();
TemperatureThread tempThread; public slots:
void dealWithData(QString); protected:
void moveEvent(QMoveEvent *);
void resizeEvent(QResizeEvent *);
void closeEvent(QCloseEvent *); private:
Ui::MainWindow *ui;
}; #endif // MAINWINDOW_H 三、cat mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox> MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this); connect(&tempThread, SIGNAL(msg(QString)),this, SLOT(dealWithData(QString))); tempThread.threadRunning = true;
tempThread.start();
} void MainWindow::dealWithData(QString data) { if( data.trimmed().length() == ) {
QMessageBox::about(this, "About", "Please check your temperature modle.");
exit(-);
} ui->temp->setText(QString("Temperature: ").append(QString::number(data.toFloat()/)).append(" C"));
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::moveEvent(QMoveEvent *)
{
this->move(QPoint(,));
} void MainWindow::resizeEvent(QResizeEvent *)
{
this->showMaximized();
} void MainWindow::closeEvent(QCloseEvent *)
{
exit();
} 四、cat temperaturethread.h
#ifndef TEMPERATURETHREAD_H
#define TEMPERATURETHREAD_H #include <QThread>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <QFileInfo>
#include <QMessageBox>
#include <QTreeView>
#include <QDir>
#include <QFile>
#include <QDebug>
#include <QMessageBox> class TemperatureThread : public QThread
{
Q_OBJECT
public:
explicit TemperatureThread(QObject *parent = );
QString readTempFile(void); bool threadRunning; signals:
void msg(QString str); public slots:
void run(); }; #endif // TEMPERATURETHREAD_H 五、cat temperaturethread.cpp
#include "temperaturethread.h" #define tmp75Path "/sys/bus/i2c/devices/3-004c/temp1_input" TemperatureThread::TemperatureThread(QObject *parent) :
QThread(parent)
{
} void TemperatureThread::run(){ while(threadRunning) { emit msg(readTempFile()); msleep(); } } QString TemperatureThread::readTempFile(){ QFile *file=new QFile(tmp75Path); if ( file->exists() ) {
file->open(QIODevice::ReadOnly|QIODevice::Text);
QString data = QString(file->readAll());
file->close();
return data;
} else {
return "";
}
}

OK335xS tmp75 Qt 温度读取的更多相关文章

  1. OK335xS Linux Qt make: icpc: Command not found

    OK335xS Linux Qt make: icpc: Command not found 一.出错现象: make: icpc: Command not found make: *** [main ...

  2. Qt QtXml读取xml文件内容

    Qt QtXml读取xml文件内容 xml文件内容 <?xml version="1.0" encoding="UTF-8"?> <YG_RT ...

  3. Qt之读取配置文件

    一.读取配置文件增删功能与修改参数数据 #ifndef CONFIG_H #define CONFIG_H #define QS_FILEPATH "E:\\woo\\Code\\Qt\\A ...

  4. Qt XML读取写入操作

    XML(eXtensible Markup Language,可扩展标记语言)是普通用于数据交换和数据存储的一种多用途文本文件格式: SVG(可标量矢量图形)XML格式,QtSvg模块提供了可用于载入 ...

  5. QT+OpenGL读取显示图片,OpenGL在QT里的刷新问题(好几篇)

    GLuint readImage(char *filename){    GLuint tex_id;    GLint alignment; QImage tex, buf;    buf.load ...

  6. QT中读取文本数据(txt)

    下面的代码实现读取txt文档中的数据,并且是一行一行的读取. void MainWindow::on_pushButton_clicked() { QFile file("abcd.txt& ...

  7. QT 读取txt文件的几种方法

    废话不说直接上代码 1. QString displayString; QFile file("/home/alvin/text.txt"); if(!file.open(QIOD ...

  8. Qt qtextstream读取文件

    今天发现一个很有用的类:qtextstream 这个类可以以文件句柄为构造函数 然后用readAll函数返回一个QString的字符串

  9. Qt如何读取ico文件中的image(使用QImageReader和QIcon)

    ico文件是一个容器,内部可以装载许多个image,我们可以通过QIcon的pixmap方法来获取需要的image QPixmap pixmap ( const QSize & size, M ...

随机推荐

  1. container_of宏定义分析---linux内核

    问题:如何通过结构中的某个变量获取结构本身的指针??? 关于container_of宏定义在[include/linux/kernel.h]中:/*_** container_of - cast a ...

  2. ScheduledExecutorService的用法——定时执行两个任务

    package control; import java.text.DateFormat; import java.text.ParseException; import java.text.Simp ...

  3. PCB优化设计(二) 转载

    PCB优化设计(二) 2011-04-25 11:41:05|  分类: PCB设计   目 前SMT技术已经非常成熟,并在电子产品上广泛应用,因此,电子产品设计师有必要了解SMT技术的常识和可制造性 ...

  4. spot 5、ALOS监督分类波段组成

    spot 5监督分类RGB:412 ALOS分类波段RGB:432

  5. 统一iOS客户端和服务器端认证

    最近公司的同事业余时间搞了一个内部的类about.me(https://about.me/)的网站Ocelots,想来是一个很洋气的注意,以后跟客户介绍公司的时候,直接登录该网站,谈到谁的时候,就打开 ...

  6. Insist

    1.怎么自动截断文本? 如题,当数据库中的数据内容超出了要显示的长度时,如果不采取措施,会破坏页面的布局美观,所以可以采用自动截断文本,需要查看的时候再把其他的内容显示出来. 没截断的时候如下图: 再 ...

  7. 权限管理数据库设计_Rev1

    贴出来自身接触项目以来所接触过的一些企业管理信息系统权限部门的一个通用数据库设计初稿: 设计的文字解释以及各部分的作用等确定可行会再进行描述: 图: 如果有不同意见请轻拍!

  8. SVM整理

    SVM整理 Last modified: 2015.9.2 1.算法总结 支持向量机是Cortes和Vapnik于1995年首先提出的,它在解决小样本,非线性及高维模式识别中表现出许多特有的优势,并能 ...

  9. jasper ireport create a report with parameters without sql query

    I'm new in jasper ireport , and I want to know if it is possible to create a report only with static ...

  10. C++11新特性:右值引用和转移构造函数

    问题背景 #include <iostream> using namespace std; vector<int> doubleValues (const vector< ...