这篇是在10年测试QT过程中遇到的问题:
1、中文显示问题:
#include <QApplication>
#include <QLabel>
#include <QTextCodec>
int main(int argc, char* argv[])
{
QApplication app(argc,argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
QLabel *label = new QLabel(tr("这里是中文"));
label->Show();
return app.exec();
}
编译代码,得到的错误是: 'tr'在此作用域中尚未声明。
昨天为什么没有出现这种错误呢?因为昨天的代码是从qt creator生成的MainWindow中挑出来的,tr被声明为QObject的一个static方法,因此在MainWindow中使用tr不会有问题。
把上面的
QLabel *label=new QLabel(tr("这里是中文"));
改为
QLabel *label=new QLabel(QObject::tr("这里是中文"));
2、中文问题:
使用sqlite数据库显示乱码的问题
mingw32-make: *** No rule to make target `http://www.cnblogs.com/http://www.cnblogs.com/Qt/4.3.3/mkspecs/default/qmake.conf', needed by `makefile'. Stop.
make[2]: Entering directory `/home/lzy/tps2/rplan/super'
make[2]: *** No rule to make target `/home/lzy/qt/qt-3.3.2/mkspecs/default/qmake.conf', needed by `Makefile'. Stop.
make[2]: Leaving directory `/home/lzy/tps2/rplan/super'
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wangya216/archive/2009/06/08/4252689.aspx
5、mingw32\bin\ld.exe: cannot find -lqtmaind错误
这个错误是缺少某些库,将mingw重新下载安装即可。
6、编译时可能会遇到如下错误:previous declaration 'long int InterlockedIncrement(long int*)' here
此为qt的bug需要修改源代码 (Qt\4.4.3\src\corelib\arch\qatomic_windows.h),
原文件如下:
Solution:
(1) Qt\4.4.3\src\corelib\arch\qatomic_windows.h:
#if !(defined Q_CC_BOR) || (__BORLANDC__ < 0x560)
extern "C" {
__declspec(dllimport) long __stdcall InterlockedCompareExchange(long *, long, long);
__declspec(dllimport) long __stdcall InterlockedIncrement(long *);
__declspec(dllimport) long __stdcall InterlockedDecrement(long *); __declspec(dllimport) long __stdcall InterlockedExchange(long *, long);
__declspec(dllimport) long __stdcall InterlockedExchangeAdd(long *, long);
}
#else
extern "C" {
__declspec(dllimport) long __stdcall InterlockedCompareExchange(long volatile*, long, long);
__declspec(dllimport) long __stdcall InterlockedIncrement(long volatile*);
__declspec(dllimport) long __stdcall InterlockedDecrement(long volatile*);
__declspec(dllimport) long __stdcall InterlockedExchange(long volatile*, long);
__declspec(dllimport) long __stdcall InterlockedExchangeAdd(long volatile*, long);
}
#endif
you will see above code in Qt\4.4.3\src\corelib\arch\qatomic_windows.h: file. I modified like below and it works.
/*#if !(defined Q_CC_BOR) || (__BORLANDC__ < 0x560)
extern "C" {
__declspec(dllimport) long __stdcall InterlockedCompareExchange(long *, long, long);
__declspec(dllimport) long __stdcall InterlockedIncrement(long *);
__declspec(dllimport) long __stdcall InterlockedDecrement(long *); __declspec(dllimport) long __stdcall InterlockedExchange(long *, long);
__declspec(dllimport) long __stdcall InterlockedExchangeAdd(long *, long);
}
#else */
extern "C" {
__declspec(dllimport) long __stdcall InterlockedCompareExchange(long volatile*, long, long);
__declspec(dllimport) long __stdcall InterlockedIncrement(long volatile*);
__declspec(dllimport) long __stdcall InterlockedDecrement(long volatile*);
__declspec(dllimport) long __stdcall InterlockedExchange(long volatile*, long);
__declspec(dllimport) long __stdcall InterlockedExchangeAdd(long volatile*, long);
}
// #endif
7、编译错误,显示 can not find -lqtmaind。
这是qt的debug库,安装完成后需要再自己编译这个库。在Qt的开始菜单中,你可以找到一个程序 Qt 4.4.0 (Build Debug Libraries),运行这个程序就能编译Qt的Debug库了。