Solved How do I delete the current QTreeWidget element correctly?
-
Here is a part of the text where there may be an error:
SelectPreset::SelectPreset(QWidget *parent) : QDialog(parent), ui_selectpreset(new Ui::SelectPreset) { ui_selectpreset->setupUi(this); ui_selectpreset->treeWidget->clear(); int n = _preset_table[0].size(); int m = _preset_table.size(); QString type; QColor color; color.setRgba(qRgb(120, 120, 150)); QFont font; font.setBold(true); QTreeWidgetItem *item = new QTreeWidgetItem(); // line 28 - deleted this line for (int i = 0; i < n; i++) { type = _preset_table[23][i]; if (type == "TopLewelItem") { QTreeWidgetItem *root = new QTreeWidgetItem(); root->setText(0, _preset_table[0][i]); ui_selectpreset->treeWidget->addTopLevelItem(root); ui_selectpreset->treeWidget->setCurrentItem(root); root->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable); root->setFont(0, font); root->setForeground(0, color); }; if (type == "ChildItem") { item = ui_selectpreset->treeWidget->currentItem(); // replaced with: QTreeWidgetItem *item = .... QTreeWidgetItem *child = new QTreeWidgetItem(); for (int j = 0; j < 23; j++) { child->setText(j, _preset_table[j][i]); }; child->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable); item->addChild(child); }; }; item = ui_selectpreset->treeWidget->topLevelItem(pos_top)->child(pos_cld); // replaced with: QTreeWidgetItem *item = .... ui_selectpreset->treeWidget->setCurrentItem(item); std::cout << n << " x " << m << std::endl; // Table size ui_selectpreset->treeWidget->expandAll(); for (int i=1; i<=24; i++) { ui_selectpreset->treeWidget->hideColumn(i); }; QAction *addsection = new QAction(tr("Add section"), this); QAction *addpreset = new QAction(tr("Add new preset"), this); connect(addsection, &QAction::triggered, this, &SelectPreset::add_section); connect(addpreset, &QAction::triggered, this, &SelectPreset::add_preset); QMenu* menu = new QMenu(this); menu->addAction(addsection); menu->addAction(addpreset); menu->setStyleSheet("QMenu {background-color: rgb(5, 20, 25);} " "QMenu::item {background-color: transparent;} " "QMenu::item:selected {background-color: rgb(5, 40, 45);}"); ui_selectpreset->actionAdd_preset->setMenu(menu); }
-
@Helg1980 said in How do I delete the current QTreeWidget element correctly?:
QTreeWidgetItem *item = new QTreeWidgetItem(); // line 28
So, as the
valgrind
tells you, in all cases you do not use/overwrite thisnew
editem
without using it. Hence the leak. -
This post is deleted! -
@Helg1980
So I see. So now has that leak gone away? That's all you are looking to resolve. -
It looks like the error has disappeared. I don't work very well with valgrind yet. So I understand that I only need to search for lines where there are links to my files.
==7099== HEAP SUMMARY: ==7099== in use at exit: 571,790 bytes in 7,682 blocks ==7099== total heap usage: 833,977 allocs, 826,295 frees, 5,575,110,174 bytes allocated ==7099== ==7099== 24 bytes in 1 blocks are definitely lost in loss record 94 of 561 ==7099== at 0x483A77F: malloc (vg_replace_malloc.c:307) ==7099== by 0xDE61E5E: XextCreateExtension (in /usr/lib/libXext.so.6.4.0) ==7099== by 0x1074014B: ??? ==7099== by 0x1073775C: ??? ==7099== by 0x10662091: ??? (in /usr/lib/qt/plugins/xcbglintegrations/libqxcb-glx-integration.so) ==7099== by 0xA28C084: QXcbWindow::create() (in /usr/lib/libQt5XcbQpa.so.5.15.1) ==7099== by 0xA27A746: QXcbIntegration::createPlatformWindow(QWindow*) const (in /usr/lib/libQt5XcbQpa.so.5.15.1) ==7099== by 0x5842F26: QWindowPrivate::create(bool, unsigned long long) (in /usr/lib/libQt5Gui.so.5.15.1) ==7099== by 0x51F78A7: QWidgetPrivate::create() (in /usr/lib/libQt5Widgets.so.5.15.1) ==7099== by 0x51F7E20: QWidget::create(unsigned long long, bool, bool) (in /usr/lib/libQt5Widgets.so.5.15.1) ==7099== by 0x520551B: QWidgetPrivate::setVisible(bool) (in /usr/lib/libQt5Widgets.so.5.15.1) ==7099== by 0x117E3F: main (main.cpp:10) ==7099== ==7099== 160 bytes in 1 blocks are possibly lost in loss record 372 of 561 ==7099== at 0x483A77F: malloc (vg_replace_malloc.c:307) ==7099== by 0x60A8595: QObjectPrivate::addConnection(int, QObjectPrivate::Connection*) (in /usr/lib/libQt5Core.so.5.15.1) ==7099== by 0x60AC9DE: QObjectPrivate::connectImpl(QObject const*, int, QObject const*, void**, QtPrivate::QSlotObjectBase*, Qt::ConnectionType, int const*, QMetaObject const*) (in /usr/lib/libQt5Core.so.5.15.1) ==7099== by 0x60ACEB5: QObject::connectImpl(QObject const*, void**, QObject const*, void**, QtPrivate::QSlotObjectBase*, Qt::ConnectionType, int const*, QMetaObject const*) (in /usr/lib/libQt5Core.so.5.15.1) ==7099== by 0xA3D1BBD: QDBusConnectionInterface::QDBusConnectionInterface(QDBusConnection const&, QObject*) (in /usr/lib/libQt5DBus.so.5.15.1) ==7099== by 0xA3CEB3A: ??? (in /usr/lib/libQt5DBus.so.5.15.1) ==7099== by 0xA3CFD13: ??? (in /usr/lib/libQt5DBus.so.5.15.1) ==7099== by 0x60AB7E1: QObject::event(QEvent*) (in /usr/lib/libQt5Core.so.5.15.1) ==7099== by 0x607ECAF: QCoreApplication::notifyInternal2(QObject*, QEvent*) (in /usr/lib/libQt5Core.so.5.15.1) ==7099== by 0x60817D2: QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (in /usr/lib/libQt5Core.so.5.15.1) ==7099== by 0x60D8303: ??? (in /usr/lib/libQt5Core.so.5.15.1) ==7099== by 0x6A2CBFB: g_main_context_dispatch (in /usr/lib/libglib-2.0.so.0.6600.0) ==7099== ==7099== 302 (256 direct, 46 indirect) bytes in 1 blocks are definitely lost in loss record 414 of 561 ==7099== at 0x483A77F: malloc (vg_replace_malloc.c:307) ==7099== by 0xA38F9E2: ??? (in /usr/lib/libfontconfig.so.1.12.0) ==7099== by 0xA3902E4: ??? (in /usr/lib/libfontconfig.so.1.12.0) ==7099== by 0xA391BEB: ??? (in /usr/lib/libfontconfig.so.1.12.0) ==7099== by 0xA399E59: ??? (in /usr/lib/libfontconfig.so.1.12.0) ==7099== by 0xA5309E7: ??? (in /usr/lib/libexpat.so.1.6.11) ==7099== by 0xA52EDDC: ??? (in /usr/lib/libexpat.so.1.6.11) ==7099== by 0xA532620: ??? (in /usr/lib/libexpat.so.1.6.11) ==7099== by 0xA5348CB: XML_ParseBuffer (in /usr/lib/libexpat.so.1.6.11) ==7099== by 0xA397024: ??? (in /usr/lib/libfontconfig.so.1.12.0) ==7099== by 0xA397657: ??? (in /usr/lib/libfontconfig.so.1.12.0) ==7099== by 0xA397713: ??? (in /usr/lib/libfontconfig.so.1.12.0) ==7099== ==7099== LEAK SUMMARY: ==7099== definitely lost: 280 bytes in 2 blocks ==7099== indirectly lost: 46 bytes in 2 blocks ==7099== possibly lost: 160 bytes in 1 blocks ==7099== still reachable: 571,284 bytes in 7,675 blocks ==7099== of which reachable via heuristic: ==7099== newarray : 4,264 bytes in 1 blocks ==7099== suppressed: 20 bytes in 2 blocks ==7099== Reachable blocks (those to which a pointer was found) are not shown. ==7099== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==7099== ==7099== Use --track-origins=yes to see where uninitialised values come from ==7099== For lists of detected and suppressed errors, rerun with: -s ==7099== ERROR SUMMARY: 80 errors from 80 contexts (suppressed: 0 from 0)
-
@Helg1980
Are you runningvalgrind
yourself with those command-line arguments? I run it from inside Qt Creator, from the menu item. I (Ubuntu 20.04) always get exactly 32 leaks, which with the default of the checkbox which says something about "don't report system ones" being checked, are always suppressed, so I don't see them. Any genuine ones from my own code are then the only ones reported. -
This post is deleted! -
Here's what valgrind QtCreator gives me. There are 35 errors in total.
160 bytes in 1 blocks are possibly lost in loss record 6,742 of 8,837 in Ui_MainWindow::setupUi(QMainWindow*) in /run/media/helg/GOODRAM-SDB/QtCreatorProjects/CineEncoder/build-cine_encoder-Desktop-Debug/ui_mainwindow.h:556 1: malloc in /build/valgrind/src/valgrind-3.16.1/coregrind/m_replacemalloc/vg_replace_malloc.c:307 2: QObjectPrivate::addConnection(int, QObjectPrivate::Connection*) in /usr/lib/libQt5Core.so.5.15.1 3: /usr/lib/libQt5Core.so.5.15.1 4: QObject::connect(QObject const*, char const*, QObject const*, char const*, Qt::ConnectionType) in /usr/lib/libQt5Core.so.5.15.1 5: /usr/lib/libQt5Widgets.so.5.15.1 6: Ui_MainWindow::setupUi(QMainWindow*) in /run/media/helg/GOODRAM-SDB/QtCreatorProjects/CineEncoder/build-cine_encoder-Desktop-Debug/ui_mainwindow.h:556 7: MainWindow::MainWindow(QWidget*) in /run/media/helg/GOODRAM-SDB/QtCreatorProjects/CineEncoder/cine-encoder-3.0/app/mainwindow.cpp:71 8: main in /run/media/helg/GOODRAM-SDB/QtCreatorProjects/CineEncoder/cine-encoder-3.0/app/main.cpp:9 288 bytes in 1 blocks are possibly lost in loss record 7,317 of 8,837 in Ui_MainWindow::setupUi(QMainWindow*) in /run/media/helg/GOODRAM-SDB/QtCreatorProjects/CineEncoder/build-cine_encoder-Desktop-Debug/ui_mainwindow.h:556 1: malloc in /build/valgrind/src/valgrind-3.16.1/coregrind/m_replacemalloc/vg_replace_malloc.c:307 2: QObjectPrivate::addConnection(int, QObjectPrivate::Connection*) in /usr/lib/libQt5Core.so.5.15.1 3: /usr/lib/libQt5Core.so.5.15.1 4: QObject::connect(QObject const*, char const*, QObject const*, char const*, Qt::ConnectionType) in /usr/lib/libQt5Core.so.5.15.1 5: /usr/lib/libQt5Widgets.so.5.15.1 6: Ui_MainWindow::setupUi(QMainWindow*) in /run/media/helg/GOODRAM-SDB/QtCreatorProjects/CineEncoder/build-cine_encoder-Desktop-Debug/ui_mainwindow.h:556 7: MainWindow::MainWindow(QWidget*) in /run/media/helg/GOODRAM-SDB/QtCreatorProjects/CineEncoder/cine-encoder-3.0/app/mainwindow.cpp:71 8: main in /run/media/helg/GOODRAM-SDB/QtCreatorProjects/CineEncoder/cine-encoder-3.0/app/main.cpp:9
-
All looks good to me, only false positives left
-
Thanks!
I'm still confused by these lines, I don't know what to do with it:
QCssParser::parseColorValue: Specified color without alpha value but alpha given: 'rgb 27, 29, 35, 0' QCssParser::parseColorValue: Specified color without alpha value but alpha given: 'rgb 27, 29, 35, 0' kf.kio.core: We got some errors while running testparm "Error loading services." kf.kio.core: We got some errors while running 'net usershare info' kf.kio.core: "Can't load /etc/samba/smb.conf - run testparm to debug it\n" kf.kio.widgets.kdirmodel: No node found for item that was just removed: QUrl("file:///run/media/helg/GOODRAM-SDB/QtCreatorProjects/CineEncoder/build-cine_encoder-Desktop-Debug/Makefile")
-
@Helg1980 said in How do I delete the current QTreeWidget element correctly?:
QCssParser::parseColorValue: Specified color without alpha value but alpha given: 'rgb 27, 29, 35, 0'
You have a css somewhere which defines a wrong color rgb value.