×
Namespaces

Variants
Actions
(Difference between revisions)

通过qtmobility 获取设备的电量

From Nokia Developer Wiki
Jump to: navigation, search
vipwx (Talk | contribs)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:PIM]][[Category:Python]][[Category:Qt]]
+
{{ArticleMetaData
 +
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|id= <!-- Article Id (Knowledge base articles only) -->
 +
|language=Lang-Chinese
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by=<!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate=20101227
 +
|author=[[User:Vipwx]]
 +
}}
 +
 
 +
[[Category:PIM]][[Category:Qt]][[Category:Lang-Chinese]][[Category:Qt Mobility]]
 
== 概述 ==
 
== 概述 ==
 
qtmobility 提供了QSystemDeviceInfo这个类,我们可以很简单的获得设备的一些信息
 
qtmobility 提供了QSystemDeviceInfo这个类,我们可以很简单的获得设备的一些信息
Line 6: Line 30:
 
== 编辑pro文件 ==
 
== 编辑pro文件 ==
  
<code cpp>
+
<code cpp-qt>
 
CONFIG += mobility
 
CONFIG += mobility
 
MOBILITY = systeminfo
 
MOBILITY = systeminfo
Line 15: Line 39:
 
如果你是在Symbian上的话还需要添加下面信息
 
如果你是在Symbian上的话还需要添加下面信息
  
<code cpp>symbian {
+
<code cpp-qt>symbian {
 
TARGET.UID3 = 0xed0c3660
 
TARGET.UID3 = 0xed0c3660
 
# TARGET.CAPABILITY +=
 
# TARGET.CAPABILITY +=
Line 38: Line 62:
 
==添加代码==
 
==添加代码==
 
首先在.h文件
 
首先在.h文件
<code cpp>#include <QSystemInfo></code>
+
<code cpp-qt>#include <QSystemInfo></code>
 
然后在添加一个mobility name space
 
然后在添加一个mobility name space
<code cpp>QTM_USE_NAMESPACE</code>
+
<code cpp-qt>QTM_USE_NAMESPACE</code>
 
然后在class里面添加一个函数和一个成员
 
然后在class里面添加一个函数和一个成员
<code cpp>void setupGeneral();
+
<code cpp-qt>void setupGeneral();
 
QSystemDeviceInfo *deviceInfo</code>
 
QSystemDeviceInfo *deviceInfo</code>
 
至此头文件改动完毕
 
至此头文件改动完毕
 
CPP文件:
 
CPP文件:
<code cpp>void BatteryIndicator::setupGeneral()
+
<code cpp-qt>void BatteryIndicator::setupGeneral()
 
{
 
{
 
deviceInfo = new QSystemDeviceInfo(this);
 
deviceInfo = new QSystemDeviceInfo(this);
Line 58: Line 82:
 
然后在构造的时候调用这个函数,代码如下
 
然后在构造的时候调用这个函数,代码如下
  
<code cpp>BatteryIndicator::BatteryIndicator(QWidget *parent) :
+
<code cpp-qt>BatteryIndicator::BatteryIndicator(QWidget *parent) :
 
QDialog(parent),
 
QDialog(parent),
 
ui(new Ui::BatteryIndicator),
 
ui(new Ui::BatteryIndicator),
Line 69: Line 93:
 
OK 已经完成了,很简单吧。编译看看效果
 
OK 已经完成了,很简单吧。编译看看效果
  
[[File:Qtmobility2.jpg]]
+
[[File:Qtmobility2.jpg]][[Category:MeeGo Harmattan]] [[Category:Symbian]]

Latest revision as of 04:19, 11 October 2012

Article Metadata

兼容于
平台:
Symbian

文章
vipwx 在 27 Dec 2010 创建
最后由 hamishwillee 在 11 Oct 2012 编辑

Contents

[edit] 概述

qtmobility 提供了QSystemDeviceInfo这个类,我们可以很简单的获得设备的一些信息

然后我们可以利用Qt Creato 的UI编辑器拖动Progress Bar 来展示出来。

[edit] 编辑pro文件

CONFIG += mobility
MOBILITY = systeminfo

MOBILITY = systeminfo 说明我们是想要获取系统的信息

如果你是在Symbian上的话还需要添加下面信息

symbian {
TARGET.UID3 = 0xed0c3660
# TARGET.CAPABILITY +=
TARGET.EPOCSTACKSIZE = 0x14000
TARGET.EPOCHEAPSIZE = 0x020000 0x800000
}

UID3 这些你在创建工程的时候选择 创建mobile工程就会自动生成,当然你需要安装Symbian SDK

[edit] 编辑界面

然后我们可以添加一个进度条来显示当前电量

选中Qt Creator里面你的工程的Edit 然后打开UI设计器


Qtmobility.jpg

如图所示添加一个Progress Bar 设置 objectName 为 batteryLevelBar

简单界面完成

[edit] 添加代码

首先在.h文件

#include <QSystemInfo>

然后在添加一个mobility name space

QTM_USE_NAMESPACE

然后在class里面添加一个函数和一个成员

void setupGeneral();
QSystemDeviceInfo *deviceInfo

至此头文件改动完毕 CPP文件:

void BatteryIndicator::setupGeneral()
{
deviceInfo = new QSystemDeviceInfo(this);
 
ui->batteryLevelBar->setValue(deviceInfo->batteryLevel());
 
connect(deviceInfo, SIGNAL(batteryLevelChanged(int)),
ui->batteryLevelBar, SLOT(setValue(int)));
}

然后在构造的时候调用这个函数,代码如下

BatteryIndicator::BatteryIndicator(QWidget *parent) :
QDialog(parent),
ui(new Ui::BatteryIndicator),
deviceInfo(NULL)
{
ui->setupUi(this);
setupGeneral();
}

[edit] 效果

OK 已经完成了,很简单吧。编译看看效果

Qtmobility2.jpg

This page was last modified on 11 October 2012, at 04:19.
104 page views in the last 30 days.
×