Qt Creator 安装 VLD
2015-04-14 16:52:55 你好L 阅读数 2325更多
分类专栏: qt
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/lin_jianbin/article/details/45044459
一、环境说明
1、VLD 内存检测工具,只能检测使用VC++编译器,不能用于检测MinGW编译器
所以要检测 Qt内存泄露问题编译器一定要是MSVC。
环境要求:
1、VLD 版本要2.X以上 不能使用1.X的版本。否则检测不准确,Qt检测会提示很多内存泄露。(本人使用vld-2.3-setup.exe)
2、VC++编译器 即MSVC 如果有安装VS则就有这编译器
D:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat
二、下载VLD
(1) http://vld.codeplex.com/releases
(2)
三、安装VLD
双击 vld-2.3-setup.exe
安装过程会弹出如下对话框,
选择是
安装完成
本人安装的路径是 D:\VLD
新的版本解决了path问题,所以我们无需做过多的设置
四、配置Qt Creator
在 工具->选项
构建和运行 --> 编译器
是否有vc++编译器 MSVC 如果没有 点击添加
构建和运行 --> 构建套件(Kit)
编译器选择
配置完成
五、VLD使用
1、创建测试项目:使用QtCreator创建一个Qt GUI项目
修改.pro文件,添加如下内容:
win32{
CONFIG(debug, debug|release) {
INCLUDEPATH += D:/VLD/include
DEPENDPATH += D:/VLD/include
LIBS += -LD:/VLD/lib/Win32 -lvld
}
}
注:D:/VLD 为本人安装的路径
2、在main函数上面添加以下代码:
#ifdef _DEBUG
#include "vld.h"
#endif
六、测试
#include "widget.h"
#include <QApplication>
#ifdef _DEBUG
#include "vld.h"
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
Widget *pWid= new Widget;
//delete pWid;
return a.exec();
}
测试结果:
Visual Leak Detector Version 2.3 installed.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 2 at 0x00D8EEB0: 24 bytes ----------
Call Stack:
e:\qttest\vldvstest\main.cpp (14): VLDVSTest.exe!main + 0x7 bytes
D:\Qt4.8ToVs2008\4.8.0\src\winmain\qtmain_win.cpp (131): VLDVSTest.exe!WinMain + 0x12 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (574): VLDVSTest.exe!__tmainCRTStartup + 0x35 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): VLDVSTest.exe!WinMainCRTStartup
0x7C81776F (File and line number not available): kernel32.dll!RegisterWaitForInputIdle + 0x49 bytes
Data:
14 7A 40 00 F8 EE D8 00 F0 79 40 00 00 00 CD CD .z@..... .y@.....
AC EF D8 00 F0 F0 D8 00 ........ ........
---------- Block 3 at 0x00D8F0F0: 1 bytes ----------
Call Stack:
e:\qttest\vldvstest\widget.cpp (7): VLDVSTest.exe!Widget::Widget + 0x63 bytes
e:\qttest\vldvstest\main.cpp (14): VLDVSTest.exe!main + 0x21 bytes
D:\Qt4.8ToVs2008\4.8.0\src\winmain\qtmain_win.cpp (131): VLDVSTest.exe!WinMain + 0x12 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (574): VLDVSTest.exe!__tmainCRTStartup + 0x35 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): VLDVSTest.exe!WinMainCRTStartup
0x7C81776F (File and line number not available): kernel32.dll!RegisterWaitForInputIdle + 0x49 bytes
Data:
CD ........ ........
Visual Leak Detector detected 2 memory leaks (97 bytes).
Largest number used: 134 bytes.
Total allocations: 134 bytes.
Visual Leak Detector is now exiting.
Visual Leak Detector Version 2.3 installed.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 2 at 0x00D8EEB0: 24 bytes ----------
Call Stack:
e:\qttest\vldvstest\main.cpp (14): VLDVSTest.exe!main + 0x7 bytes
D:\Qt4.8ToVs2008\4.8.0\src\winmain\qtmain_win.cpp (131): VLDVSTest.exe!WinMain + 0x12 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (574): VLDVSTest.exe!__tmainCRTStartup + 0x35 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): VLDVSTest.exe!WinMainCRTStartup
0x7C81776F (File and line number not available): kernel32.dll!RegisterWaitForInputIdle + 0x49 bytes
Data:
14 7A 40 00 F8 EE D8 00 F0 79 40 00 00 00 CD CD .z@..... .y@.....
AC EF D8 00 F0 F0 D8 00 ........ ........
---------- Block 3 at 0x00D8F0F0: 1 bytes ----------
Call Stack:
e:\qttest\vldvstest\widget.cpp (7): VLDVSTest.exe!Widget::Widget + 0x63 bytes
e:\qttest\vldvstest\main.cpp (14): VLDVSTest.exe!main + 0x21 bytes
D:\Qt4.8ToVs2008\4.8.0\src\winmain\qtmain_win.cpp (131): VLDVSTest.exe!WinMain + 0x12 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (574): VLDVSTest.exe!__tmainCRTStartup + 0x35 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): VLDVSTest.exe!WinMainCRTStartup
0x7C81776F (File and line number not available): kernel32.dll!RegisterWaitForInputIdle + 0x49 bytes
Data:
CD ........ ........
Visual Leak Detector detected 2 memory leaks (97 bytes).
Largest number used: 134 bytes.
Total allocations: 134 bytes.
Visual Leak Detector is now exiting.