gpt4 book ai didi

c++ - QQuickView 新删除类型不匹配

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:37:40 30 4
gpt4 key购买 nike

当使用 g++ -fsanitize=address 编译时,我得到一个新的删除类型不匹配。这段代码有错吗?或者这是一个 Qt 错误?

我在一个大型应用程序中发现了这个并将其分解为以下代码。我想用 QQuickView 显示来自 C++ 的 QML 项目。但是QQuickView的Destructor好像有问题。

测试.pro:

TEMPLATE = app
TARGET = test
QT += core gui widgets quick

SOURCES += test.cpp

QMAKE_CXXFLAGS += -fsanitize=address
QMAKE_LFLAGS += -fsanitize=address

测试.cpp:

#include <QApplication>
#include <QQuickView>
#include <QQuickItem>

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

QQuickView view;
view.setSource(QUrl::fromLocalFile("test.qml"));
view.show();

return app.exec();
}

测试.qml:

import QtQuick 2.4

Item {
id: item1
anchors.fill: parent

Rectangle {
id: rectangle
color: "#fba4e3"
anchors.fill: parent
}
}

编译:

$ qmake-qt5 test.pro
$ make

g++ -c -pipe -fsanitize=address -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtWidgets -isystem /usr/include/qt5/QtQuick -isystem /usr/include/qt5/QtGui -isystem /usr/include/qt5/QtQml -isystem /usr/include/qt5/QtNetwork -isystem /usr/include/qt5/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib64/qt5/mkspecs/linux-g++ -o test.o test.cpp
g++ -fsanitize=address -Wl,-O1 -o test test.o -lQt5Widgets -lQt5Quick -lQt5Gui -lQt5Qml -lQt5Network -lQt5Core -lGL -lpthread

运行:

$ ./test

=================================================================
==6822==ERROR: AddressSanitizer: new-delete-type-mismatch on 0x60f000034de0 in thread T0:
object passed to delete has wrong type:
size of the allocated type: 168 bytes;
size of the deallocated type: 32 bytes.
#0 0x7fc304be16d8 in operator delete(void*, unsigned long) (/lib64/libasan.so.4+0xe16d8)
#1 0x7fc303547e07 in QObjectPrivate::deleteChildren() (/lib64/libQt5Core.so.5+0x27fe07)
#2 0x7fc303548ce1 in QObject::~QObject() (/lib64/libQt5Core.so.5+0x280ce1)
#3 0x7fc304234e44 in QQuickItem::~QQuickItem() (/lib64/libQt5Quick.so.5+0x1ece44)
#4 0x7fc3042501a4 (/lib64/libQt5Quick.so.5+0x2081a4)
#5 0x7fc3042d30f9 in QQuickView::~QQuickView() (/lib64/libQt5Quick.so.5+0x28b0f9)
#6 0x40102d in main (/home/lukas/Programmieren/C++/Qt/test/test+0x40102d)
#7 0x7fc3021a0889 in __libc_start_main (/lib64/libc.so.6+0x20889)
#8 0x401199 in _start (/home/lukas/Programmieren/C++/Qt/test/test+0x401199)

0x60f000034de0 is located 0 bytes inside of 168-byte region [0x60f000034de0,0x60f000034e88)
allocated by thread T0 here:
#0 0x7fc304be0158 in operator new(unsigned long) (/lib64/libasan.so.4+0xe0158)
#1 0x7fc3039ddbf1 in QQmlType::create(QObject**, void**, unsigned long) const (/lib64/libQt5Qml.so.5+0x265bf1)
#2 0x60f00003d2ff (<unknown module>)

SUMMARY: AddressSanitizer: new-delete-type-mismatch (/lib64/libasan.so.4+0xe16d8) in operator delete(void*, unsigned long)
==6822==HINT: if you don't care about these errors you may set ASAN_OPTIONS=new_delete_type_mismatch=0
==6822==ABORTING

最佳答案

这确实是 QtQuick 中的一个已知错误,但仍未解决,请查看 bug report .

其中一条评论给出了一些关于原因的提示,这些提示显然与 QML 引擎使用 newplacement 目的地的事实有关,其大小大于当前正在构建的对象。这可能是出于优化原因而完成的,因此不知道是否会修复此问题,但它看起来无害。

关于c++ - QQuickView 新删除类型不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50409165/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com