Category Archives: Qt

compiling Qt 4 with msvc.net (obselete)

see this item for latest method

1. unpack qt-win-opensource-4.0.0.zip to c:qt4.0.0
2. open cmd, then locate to c:qt4.0.0

c:
cd qt4.0.0

3. unpack qt4msvc_bcc.zip to the Qt 4.0.0 directory
4. configure Qt 4 with MinGW. This step is necessary, otherwise it will prompt missing of files when do nmake.

configure -platform win32-g++

5. go to the qmake directory, then use Makefile.win32-msvc to recompile qmake.

cd qmake
nmake -f Makefile.win32-msvc
I
am also wondering if there is a makefile for win32-msvc.net.
Unfortunately, there is not such a file due to absence of qmake
generator file specific to msvc.net. However, we can regard qmake using
win32-msvc option is compatible with msvc.net environment, considering
the successful final nmake link result.

6. go back the root directory of Qt 4. Using qmake with recursive
option to produce makefiles in current directory and all its
subdirectories.

cd ..
qmake -recursive -spec win32-msvc.net

7. nmake Qt4. The process will be longer than you expected. Be patient. 🙂

nmake

编译是变态的慢,要有心理准备哦!我在dell c640/2.0G/512M上花了将近6个小时才编译完成

需要qt4msvc_bcc.zip的请留email给我.
If you need qt4msvc_bcc.zip, please leave me a message, or drop me an
Email. You can also download this file from Kde-cygwin maillist. Thank
Andreas Hausladen for sending this zip file to the public maillist.

p.s. It will be better to use makespec files got from the win
evaluation Qt 4 version. Just override the counterparts in
qt4msv_bcc.zip. I have done as this, and comipled successfully.

qt 4推出在windows平台下的GPL版

可惜不支持ms VC++或VC.net,网上已经有一些讨论,看是否将qt opensource版在
MsVc.net环境下编译过去,目前来看,好象有些问题,比如trolltech给出opensourc里
的qmake可能跟商业版的qmake不尽相同。现在没有时间整这些,试目以待。
在这个邮件列表里可以搜索到一些 关于此话题的技术讨论
http://lists.kde.org/?l=kde-cygwin&r=1&w=2
在http://www.qtforum.org/board.php?boardid=45j和
http://www.osnews.com/comment.php?news_id=9675&limit=no里也有一些讨论,很是
热闹!

低级错误

犯了一个十分低级的错误,居然花了我很长时间才找到原因。
const QString& PmKeywords::Keyword()
{
return keywords.toString();
}
而 这里,keywords被定义成QValueVector,toString返回QString。大家明白问题出在哪 了吗?由于toString返回QString,而不是QString&,是局部变量,而Keyword属性返回QString&,是一 个引用,即是将局部变量的引用返出来了,但局部变量在scope出了后,就被销毁,这样返出来的就是一个无效的引用。由于整个代码已经近5000行,查错 查起来很麻烦,好歹还是找着了,前面还一直怀疑是否QSqlCursor有问题,在进行QSqlCursor Update的时候发生错误,但根本在于上面描述。一个教训,轻易不要怀疑这些大公司写的商业代码,只能从自己的代码上找原因,这样也许会更有助于除错。

Qt里的用于文字显示的控件

QLable: 显示文字或图片,不提供用户交互
QSimpleRichText: 用于显示由stylesheet定制的rich text,一但构造完成,不能被修

QTextEdit: 支持修改和显示rich text
QTextBrowser: 支持显示rich text,适合有超文本接连的场合,不能被修改。

关于qt国际化

qt对国际化有很好的支持。但默认的是unicode编码。中文系统下默认的并非unicode,
而是比如gbk或gb2312。所以在进行const char*参数传递和显示时必须特别注意。
比如在默认情况下
QMessageBox::information(this, "Test", "这是一个测试");
中文字符无法正确显式
又如
bool connect(const char * connectString);
你如果输入
QString str("一个测试");
connect((const char*)str);
默认是调用QString.latin1()方法,是直接从Unicode的QString返回latin-1字符表示
集。在中文系统下有时不是你想要的。
解决方案:在main.cpp里增加
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
这时涉及到QString/QCString到const char*的转换将使用本地的编码集。
类似的还有setCodecForTr()方法。

NOTE: 这跟qt使用unicode进行内部通讯、显示并不冲突。当显示一个const char*时,
qt会将const char*再行转成unicode。

关于Qt 4

Qt 4计划在05年第二季度晚发行,现在已经有Beta 2版出来供测试,Beta 2也是最后的一个测试版。Qt 4的几个改进:

1. Qt3向Qt4的移植工作(这当然要做的,是Qt4必须要做的,其实对用户来讲,如果不需要专门的移植则更好。不算改进)

2. Qt Designer差不多重写了,增加了对MDI/SDI模式开发的支持,和对定制widget的更好的支持
2.1 新QT Designer里提供了开发几种模式,如Form Editing Mode;Singal and Slot Editing Mode;Buddy Editing Mode,和Tab Order Mode
2.2 对custom widget的支持更好
(但好象提到designer仅做ui,要去掉project editor和coder editor部分)

3. 设计了一个新的painting system
4. 改进的输入方法框架
5. 对XP和Motif风格的改进

6. 增加了一些新类,如Tulip(模板容量类)、Interview(为item提供model/view框架)、Arthur(新的paiting框架)、Scribe(Unicode文本支持),以及MainWindow(更好的基于action的主窗口)
7. 与Qt 3相比,Qt4库分割成几个小库,比如QtCore、QtGui、QtNetwork、QtOpenGL、QtSql、QtXml、Qt3Support等。这样一个Qt程序可以只连接到一个小库,形成的程序也更小。
7.1 默认的Qt包括与QtCore和QtGui的连接,可以通过在.pro文件里添加
Qt -=gui
来去掉跟QtGui的连接

8. 与3相比,#include的格式变成 #include ,而不是以前的#include 了

9. 全面支持using namesapce Qt命名空间

10. QObject和QWidget构造函数的变化。比如QObject的构造不再需要 const char * name了;QWidget不必在构造里指定WFlags了

11. 动态cast,添加了qObject_cast<>()。如
QPushButton * pushButton = qobject_cast (obj);
if (pushButton){

}

12. QPointer的引进,相当于以前的QGuardedPtr

13. 绘画事件。全部的绘画操作都得在paintEvent()中执行。而不象以前那样可以在paintEvent外执行了。

更详细请阅读http://doc.trolltech.com/4.0/qt4-intro.html