/*******************************************************************
* 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. 【python】开始python之旅

    上午开始抽空学习python,具体内容如下: (1)安装了python 2.7 (2)安装了notepad ++,安装它之前,在notepad++和Sublime Text之间纠结了一下,baidu了 ...

  2. IOS 透​视​投​影​矩​阵​推​导(转)

    http://wenku.baidu.com/link?url=wDkyQR9fDI_tZas1BlMRUnNNoKwiQDygltm2wWxRr_sDwcDB51_QCDfR4Gb5wYrIUZ_t ...

  3. 实战开发中UI资源制作标准

    资源制作标准设定建议 1.所有的UI资源全部采用PNG导出 因为Unity不支持外部压缩,所以,不论是用PNG还是JPG,只要尺寸相同,资源量在引擎中都会是一样大.所以,可以大胆地采用PNG进行输出, ...

  4. Android中Google地图路径导航,使用mapfragment地图上画出线路(google map api v2)详解

    在这篇里我们只聊怎么在android中google map api v2地图上画出路径导航,用mapfragment而不是mapview,至于怎么去申请key,manifest.xml中加入的权限,系 ...

  5. csharp excel interop programming

    string fileName = "c:\\a.xlsx"; var application = new Application(); application.Visible = ...

  6. 论文阅读(2014-2)----The YouTube Video Recommendation System

    这是谷歌youtube在2010的一篇文章,估计现在的思路有很多升级了,但是里面的知识点还是很不错的.主要讲youtube的个性化推荐思路.下面根据论文的结构我把我理解的思路整理如下,如果有问题,欢迎 ...

  7. Samba出现“您可能没有权限使用网络资源”解决方法

    我最近在Centos6.3上搭建Samba系统,按照配置都已经配置好了,当就是没法在win7下访问,老是弹出以下弹出框: 后来我在网上找资料发现有SELinux这么个东西,然后我就按照配置该了一下就成 ...

  8. ExtJS4.2学习(四)Grid表格中文排序问题(转)

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-07/173.html --------------- ...

  9. URAL 1260 Nudnik Photographer(递推)

    题目链接 题意 : 给你1到n这n个数,排成一排,然后1放在左边最开始,剩下的数进行排列,要求排列出来的数列必须满足任何两个相邻的数之间的差不能超过2,问你有多少种排列 思路 : 对于dp[n], n ...

  10. mac 用 brew

    mac 下用   brew 安装插件, 有重复的不会再次安装,比xmap模式好