Chinaunix首页 | 论坛 | 博客
  • 博客访问: 210356
  • 博文数量: 145
  • 博客积分: 3000
  • 博客等级: 中校
  • 技术积分: 1720
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-14 18:42
文章分类

全部博文(145)

文章存档

2011年(1)

2009年(144)

我的朋友

分类: LINUX

2009-07-22 19:01:47

by tangke <> 2009-06-02

1.pro文件中添加宏定义,可用于版本控制等等

DEFINES += SOFTWARE_VERSION=\\\"字符串\\\"

这是一种很有用的方法,避免了直接修改Makefile文件,也了却了我对如何进行版本定义的麻烦。

2.指定父窗口加快运行速度

I have solved this problem. The slow speed is due to creating widgets without parents before attaching them to layouts, e.g.

Qt Code:

  1.     QLabel* label = new QLabel; // SLOW!!!
  2.    
  3.     QLabel* label = new QLabel(this); // FAST!!
  4.
   


The speed difference is huge. Also if you do too many constructions without parents, Qt seems to bog down and freeze up due perhaps to some resource issue. The surprising thing here is that many Qt examples create widgets without parents for use in layouts. This is a definite no-no! I'm going back and fixing this everywhere in my code. Things are going much faster now.

3.QSettings 如何读取中文字符串
如果 QT_VERSION > 4.5的话
修改main.cpp,加入
   QTextCodec *codec = QTextCodec::codecForName("UTF-8");
   QTextCodec::setCodecForLocale(codec);
   QTextCodec::setCodecForCStrings(codec);
   QTextCodec::setCodecForTr(codec);
并且调用
settings.setIniCodec(QTextCodec::codecForName("UTF-8"));
如果QT_VERSION < 4.5的话
   QByteArray myArray = settings.value(localeName, "").toByteArray();
   QString name = QString::fromLocal8Bit(myArray);

可见QT 4.5版本开始对这方面进行了优化。


阅读(366) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~