Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ qt std:string Qstring内存崩溃_C++_Qt - Fatal编程技术网

C++ qt std:string Qstring内存崩溃

C++ qt std:string Qstring内存崩溃,c++,qt,C++,Qt,1.发展环境 1) WIN7 64位 2) VS2013 3) qt-opensource-windows-x86-msvc2013_opengl-5.4.0 4) qt-vs-addin-1.2.4-开源 PS:vs2013使用多线程dll调试(/MDd) 2.testQT项目包括3个文件,Form.cpp、testString.h和testString.cpp //... void TestString::printClassComFunc(QString name1, QObject*

1.发展环境

1) WIN7 64位

2) VS2013

3) qt-opensource-windows-x86-msvc2013_opengl-5.4.0

4) qt-vs-addin-1.2.4-开源

PS:vs2013使用多线程dll调试(/MDd)

2.testQT项目包括3个文件,Form.cpp、testString.h和testString.cpp

//...

void TestString::printClassComFunc(QString name1, QObject* observer, void(QObject::*func)(), QString name)
{
    printf("printClassComFunc name=%s\n", name.toStdString().c_str());
    return;
}
1) Form.cpp

2) testString.h

#ifndef TestString_H
#define TestString_H

#include <string>
#include <map>
#include <vector>

#include <QString>

class QWidget;
class QObject;

using namespace std;

typedef void (QObject::*NotifySelector1)();

#define notify_selector1(selector) (NotifySelector1)(&selector)

class TestString;

struct NotifyItem1
{
    QObject* observer;
    void (QObject::*selector)();
    string selectorName;
};

class TestString
{
private:
    TestString();
    static TestString* _instance;
    map<string, vector<NotifyItem1>* > notifymap;
public:
    static TestString* Instance();
    virtual ~TestString();
    void printClassComFunc(QString name1, QObject* observer, void(QObject::*func)(), QString name);
};

#endif // TestString_H
  • 我的问题
  • 在函数printClassComFunc中,参数名称1为“aa”,但名称为“?”,内存崩溃

    当我从中注释成员函数指针时

    struct NotifyItem1
    {
        QObject* observer;
        void (QObject::*selector)();
        string selectorName;
    };
    

    这个问题没有发生,但它是随机的,我认为这不是问题的关键

    4.我的分析

    1) 问题的背景

    我将我的另一个项目从mac(10.9.0)传输到windows win7(64位),std:string内存崩溃,无堆,我想可能是std库的不同实现,windows使用xstring和mac使用string,所以我将std:string替换为QString,问题也存在

    2) 我用谷歌搜索了很多,有人说也许你加载了很多不同的c运行时库, 我使用dependency walker,发现我只使用msvcr120d.dll和msvcp120d.dll,qt5corder.dll的old32.dll中的qt构建使用msvcrt.dll,但我认为这不是关键问题

    3) 有些人说,也许你们在exe应用程序上分配内存,然后在dll端释放内存。 链接是

    我想这是最关键的一点,但我也不能解决我的问题

    所以你的帮助是我的感激

    struct NotifyItem1
    {
        QObject* observer;
        void (QObject::*selector)();
        string selectorName;
    };
    
    struct NotifyItem1
    {
        QObject* observer;
        //void (QObject::*selector)();
        string selectorName;
    };