今天犯了一个非常2的错误!

为了将面板参数保存起来,选择用QDomDocument构造Dom树,然后用doc.toString()方法返回符合xml格式的QString。如:

QString CutFaceFilter::saveParamsXML(CutFaceParams& para)
{
QDomDocument doc; QDomElement root = doc.createElement("parameters");
doc.appendChild(root); QDomElement element1 = doc.createElement("para");
element1.setAttribute("name", "center");
element1.setAttribute("x", para.center[]);
element1.setAttribute("y", para.center[]);
element1.setAttribute("z", para.center[]);
root.appendChild(element1); QDomElement element2 = doc.createElement("para");
element2.setAttribute("name", "normal");
element2.setAttribute("x", para.normal[]);
element2.setAttribute("y", para.normal[]);
element2.setAttribute("z", para.normal[]);
root.appendChild(element2); return doc.toString();
}

此方法在本地运行正常,但将其封装导出为一个DLL文件,再次调用时,一直报错:“Access violation writing location”。跟踪代码,发现出了这个函数,在return后就会报错,即使将这个doc.toString()拷贝出来,甚至使用QString的deep copy:

  QString str(doc.toString().toLocal8Bit ());
return str;

仍报错这个错。Google了好久,也没发现原因。

JL之前说QDomElement递归调用时会各种出错,于是感觉是否QDomDocument这个方法不靠谱。。。

(1) 换用QxmlStreamWriter, 直接返回时,是bad prt,用QString 的deep copy后,可以得到正确的结果。但换用这个方法,工程中用到QDomDocument的地方都要改,改动太大,太麻烦。

(2) 继续搜,猛然发现一帖,说也在使用QDom时出现了violation的问题,结果是由于引用的lib不是Debug版的QtXmld4.lib。而是QtXml4.lib。 醍醐灌顶,一查我的工程,果然也是这个lib错写成Release版的了。改为QtXmld4.lib后,问题得解!!

这个错误太2了,以后吸取教训,出现violation错误时, 要记得看看是否是导入的lib库Debug 、Release搞混了。Mark~

QDomDocument Access violation writing location的更多相关文章

  1. 使用scanf_s报错:0xC0000005: Access violation writing location 0x00000000

    在vs2010中写了一行scanf("%s",name); 调式时 提示warning , 提示修改为scanf()使用可能会存在不安全,建议使用scanf_s() 但是我修改成s ...

  2. VS2010程序崩溃,报错Unhandled exception at **.exe:0xC0000005: Access violation reading location 0x000000008899.

    最近被派到另外一个组支援,从而从Linux下开发暂转到Windows下开发,个人觉得Windows自己搞的一套并不那么完美,坑多. 网文可能出现的原因: 未处理的异常: 0xC0000005: 读取位 ...

  3. std::vector push_back报错Access violation

    C/C++ code   ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #include < ...

  4. STM32 KEIL不能输入仿真引脚端口error 65: access violation at 0x40021000 : no 'read' permission

    使用MDK自己创建一个STM32F103ZE核的项目 加入源码后编译,正常,在线仿真单步执行出现如下问题 error 65: access violation at 0x40021000 : no ' ...

  5. 如何捕获access violation异常

    文章目录 access violation的由来 access violation的实例 Win32 exception SEH异常与C++标准异常 捕获方法 1.access violation的由 ...

  6. 动态调用DLL函数有时正常,有时报Access violation的异常

    动态调用DLL函数有时正常,有时报Access violation的异常 typedef int (add *)(int a,int b); void test() {     hInst=LoadL ...

  7. Access Violation at address 00000000.Read of address 00000000 解决办法

    是数组越标或没有初始化某个对象之类的问题,搂住细细检查一下代码, 使用指针前未做检查,而这个指针未初始化. 可能是new后没有delete,这样出现溢出的可能性比较大     检查代码或者跟踪试试 使 ...

  8. u-boot TFTP: &#39;Access violation&#39; (2)

    今天做tftp下载时间会遇到以下问题. --->8--- Load address: 0x20000000 Loading: * TFTP error: 'Access violation' ( ...

  9. laravel migrate时报错:Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

    今天在学习laravel的路由模型绑定时,在按照文档执行php artisan migrate时报错. In Connection.php line 664: SQLSTATE[42000]: Syn ...

随机推荐

  1. 那些年,我们一起学WCF--(8)Single实例行为

    Single实例行为,类似于单件设计模式,所有可以客户端共享一个服务实例,这个服务实例是一个全局变量,该实例第一次被调用的时候初始化,到服务器关闭的时候停止. 设置服务为Single实例行为,只要设置 ...

  2. power desinger 学习笔记<五>

    怎样才能在修改表的字段Name的时候,Code不自动跟着变 tools-> General   Options-> Dialog:Operation   Modes: 去掉 NameToC ...

  3. IOS 多线程,线程同步的三种方式

    本文主要是讲述 IOS 多线程,线程同步的三种方式,更多IOS技术知识,请登陆疯狂软件教育官网. 一般情况下我们使用线程,在多个线程共同访问同一块资源.为保护线程资源的安全和线程访问的正确性. 在IO ...

  4. [转]PHP取整函数:ceil,floor,round,intval的区别详细解析

    我们经常用到的PHP取整函数,主要是:ceil,floor,round,intval. 1.ceil -- 进一法取整 说明float ceil ( float value ) 返回不小于 value ...

  5. Git 基础再学习之:git checkout -- file

    首先明白一下基本概念和用法,这段话是从前在看廖雪峰的git教程的时候摘到OneNote的 准备工作: 新建了一个learngit文件夹,在bash中cd进入文件夹,用以下命令创建一个仓库. $ git ...

  6. 【HDU4348】【主席树】To the moon

    Problem Description BackgroundTo The Moon is a independent game released in November 2011, it is a r ...

  7. Python自动化运维之30、Flask框架

    Flask 官网:http://flask.pocoo.org/ flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是 ...

  8. Python 的“+”和append在添加字符串时候的区别

    对于一个空的Python列表,往后添加内容有很多种,其中两种一个是用“+”直接添加内容,另外一种是Listname.append(x)来添加内容 其中,如果处理字符串 在使用“+”的时候,会将字符串拆 ...

  9. Zookeeper的设计模式之观察者模式(十)

    Watcher是Zookeeper用来实现distribute lock, distribute configure, distribute queue等应用的主要手段.要监控data_tree上的任 ...

  10. C# 改变图片尺寸(压缩),Image Resize

    /// <summary> /// Resize image with a directory as source /// </summary> /// <param n ...