1、综述
QT虽然是跨平台的,但不同版本的QT,函数可能是有所不同的;同时我们在编程是肯定会使用系统函数,所以在开发过程中,条件编译是不可或缺的。
2、判断不同的版本的QT
(1)设置编码
QTextCodec::setCodecForLocale(QTextCodec::codecForLocale());
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
#endif
Qt5没有后面两个函数
(2)包含不同头文件
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
#include <QtConcurrentRun>
#else
#include <QtConcurrent>
#endif
3、不同系统
#ifdef _WIN32
#include <Windows.h>
#else
#include <sys/stat.h>
#include <unistd.h>
#endif
4、32位与64位系统
不同操作系统,不同位数的系统,编程时注意数据类型。
32位linux和windows都采用ILP32,64位windows采用LLP64,64位Linux采用的是LP64。
特别是long,我们在编程时在网络报文中很喜欢使用,但是在64位Linux中与所有的windows中是所占字节是不一样的。最好的方法就是不使用long型。
数据类型 | ILP32 | LP32 | ILP64 | LP64 | LLP64 | |
1 | char | 8 | 8 | 8 | 8 | 8 |
2 | short | 16 | 16 | 16 | 16 | 16 |
3 | int | 32 | 32 | 64 | 32 | 32 |
4 | long | 32 | 32 | 64 | 64 | 32 |
5 | long long | 64 | 64 | 64 | 64 | 64 |
6 | pointer | 32 | 32 | 64 | 64 | 64 |
7 | float | 32 | 32 | 32 | 32 | 32 |
8 | double | 64 | 64 | 64 | 64 | 64 |