Expression _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

Table of Contents

    用新的visual studio 2017或者2019来编译老代码(vs2013),Debug的时候发现QString的toStdString和toStdWString方法触发以上错误(Release没有问题),换成下面两个转换函数就没问题了:

    std::wstring towstring(const QString& str)
    	{
    		std::wstring result;
    		result.reserve(str.size());
    		for (int i = 0; i < str.size(); i++) {
    			result.push_back(str.at(i).unicode());
    		}
    		return result;
    	}
    
    	std::string tostring(const QString& str)
    	{
    		QByteArray b = str.toLocal8Bit();
    		std::string result;
    		result.reserve(b.size());
    		for (int i = 0; i < b.size(); i++) {
    			result.push_back(b[i]);
    		}
    		return result;
    	}
    

    具体原因需要分析QString源码,应该是跟内存有关。