QQmlApplicationEngine中的内存泄漏

时间:2017-11-12 10:46:35

标签: c++ qt memory-leaks

当我开发qml应用程序时,我在内存分析中发现了以下错误

32 bytes in 1 blocks are possibly lost in loss record 3,755 of 9,076
  in main in /home/m/Qt5.9.1/Examples/Qt-5.9.1/location/minimal_map/main.cpp:64
  1: operator new(unsigned long) in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
  2: QQmlEnginePrivate::QQmlEnginePrivate(QQmlEngine*) in /home/m/Qt5.9.1/5.9.1/gcc_64/lib/libQt5Qml.so.5.9.1
  3: QQmlApplicationEnginePrivate::QQmlApplicationEnginePrivate(QQmlEngine*) in /home/m/Qt5.9.1/5.9.1/gcc_64/lib/libQt5Qml.so.5.9.1
  4: QQmlApplicationEngine::QQmlApplicationEngine(QObject*) in /home/m/Qt5.9.1/5.9.1/gcc_64/lib/libQt5Qml.so.5.9.1
  5: main in /home/m/Qt5.9.1/Examples/Qt-5.9.1/location/minimal_map/main.cpp:64

这是我的main.cpp类,错误引用此行QQmlApplicationEngine engine;我无法弄清楚如何解决它?它没有给我任何线索如何释放它。

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "gcppoint_.h"
#include "gcppointobject.h"
#include "georefobject_.h"
#include <qdebug.h>
#include <qquickitem.h>
#include <QQuickView>
#include <QObject>
#include "gcppointobject.h"
#include "gcppoint_.h"
#include "georefobject_.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);


    //qmlRegisterType<gcppointobject>("gcppointobject", 1, 0, "gcppointobject");
    qmlRegisterType<georefobject_>("georefobject_", 1, 0, "Georefobject");
    qmlRegisterType<gcppoint_>("gcppoint_", 1, 0, "Gcppoint");


    QQmlApplicationEngine engine;

    engine.addImportPath("/home/m/Qt5.9.1/Examples/Qt-5.9.1/location/minimal_map/imports");

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
}

0 个答案:

没有答案