创建一个顶部只有一个 QMenuBar 的简单程序,我设法让 Valgring GBD 检测到一个问题。
这是我的程序
主.cpp:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
主窗口.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMenuBar>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QMenuBar *menuBar = new QMenuBar(this);
QMenu *menu = new QMenu(menuBar);
menu->setTitle("test");
menu->addAction("test1", this, SLOT(onTest1()));
menu->addAction("test2", this, SLOT(onTest2()));
menuBar->addMenu(menu);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onTest1()
{
qInfo("TEST1");
}
void MainWindow::onTest2()
{
qInfo("TEST2");
}
当我使用“带有 GBD 的 Valgrind 内存分析器”启动时,单击操作“test1”或“test2”时,检测到以下错误:
==31965== 系统调用参数 writev(vector[...]) 指向未初始化的字节 ==31965== 在 0x6BE040D: ??? (syscall-template.S:84) ==31965== by 0xBF97F28: ??? (在 /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0 中)==31965== 由 0xBF9831C:???(在 /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0 中)==31965== 由 0xBF98A76:???(在 /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0 中)==31965== 通过 0xBF98C43:xcb_flush(在 /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0 ) ==31965== by 0xD573C2F: QXcbWindow::hide() (在 /home/lmartin/Qt/5.7/gcc_64/lib/libQt5XcbQpa.so.5.7.0) ==31965== by 0x578BE64: QWindow::setVisible (bool) (在 /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Gui.so.5.7.0) ==31965== by 0x4FC866E: QWidgetPrivate::hide_sys() (在 /home/lmartin/Qt/5.7 /gcc_64/lib/libQt5Widgets.so.5.7.0) ==31965== by 0x4FCE7AC: QWidgetPrivate:: hide_helper() (在 /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0) ==31965== by 0x4FD37E7: QWidget::setVisible(bool) (在 /home/lmartin/Qt/ 5.7/gcc_64/lib/libQt5Widgets.so.5.7.0) ==31965== by 0x4FCEAE7: QWidgetPrivate::close_helper(QWidgetPrivate::CloseMode) (在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so .5.7.0) ==31965== 由 0x50F3E3A: ??? (在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0)==31965== 0x50F47DE:???(在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0)==31965== 0x50F4AEB:???(在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0)==31965== by 0x50F87C5:QMenu::mouseReleaseEvent(QMouseEvent*)(在/home/lmartin/Qt/5.7/ gcc_64/lib/libQt5Widgets.so.5.7.0) ==31965== by 0x4FD3B77: QWidget::event(QEvent*) (在 /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7. 0) ==31965== by 0x50F91CA: QMenu::event(QEvent*) (in /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0) ==31965== by 0x4F8E52B: QApplicationPrivate ::notify_helper(QObject*, QEvent*) (in /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0) ==31965== by 0x4F95807: QApplication::notify(QObject*, QEvent *) (在 /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0) ==31965== by 0x60A2ADF: QCoreApplication::notifyInternal2(QObject*, QEvent*) (在 /home/lmartin /Qt/5.7/gcc_64/lib/libQt5Core.so.5.7.0) ==31965== by 0x4F947BE: QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer&, bool) (在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0)==31965== 0x4FEF5FA:???(在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0)==31965== 0x4FF1512:???(在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0)==31965== by 0x4F8E52B:QApplicationPrivate::notify_helper(QObject*, QEvent*) (在/home/lmartin/Qt /5.7/gcc_64/lib/libQt5Widgets.so.5.7.0) ==31965== by 0x4F9521F: QApplication::notify(QObject*, QEvent*) (在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets .so.5.7.0) ==31965== 地址 0xcc97941 在大小为 21,152 的块内是 4,545 个字节,分配 ==31965== 在 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.所以)==31965== 通过 0xBF978DB:xcb_connect_to_fd(在 /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0)==31965== 通过 0xBF9B610:xcb_connect_to_display_with_auth_info(在 /usr/lib/x86_64- linux-gnu/libxcb.so.1.1.0) ==31965== by 0xB872809: _XConnectXCB (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0) ==31965== by 0xB863391: XOpenDisplay (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0) ==31965== by 0xD55F095: QXcbConnection::QXcbConnection(QXcbNativeInterface*, bool, unsigned int, char const*) (in / home/lmartin/Qt/5.7/gcc_64/lib/libQt5XcbQpa.so.5.7.0) ==31965== by 0xD562AEA: QXcbIntegration::QXcbIntegration(QStringList const&, int&, char**) (在 /home/lmartin/Qt /5.7/gcc_64/lib/libQt5XcbQpa.so.5.7.0) ==31965== by 0xD31D3EA: ??? (在/home/lmartin/Qt/5.7/gcc_64/plugins/platforms/libqxcb.so)==31965== by 0x577041A:QPlatformIntegrationFactory::create(QString const&, QStringList const&, int&, char**, QString const&) (在 /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Gui.so.5.7.0) ==31965== by 0x577D483: QGuiApplicationPrivate::createPlatformIntegration() (在 /home/lmartin/Qt/5.7/gcc_64/lib /libQt5Gui.so.5.7。
obj:/lib/x86_64-linux-gnu/libc-2.23.so
obj:/usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0
obj:/usr/lib/x86_64-linux-gnu/libxcb .so.1.1.0
obj:/usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0 fun:xcb_flush
fun:_ZN10QXcbWindow4hideEv fun:_ZN7QWindow10setVisibleEb
fun:_ZN14QWidgetPrivate8hide_sysEv
fun:_ZN14QWidgetPrivate11hide_helperEv
fun:_ZN7QWidget10setVisibleEb
fun:_ZN14QWidgetPrivate12close_helperENS_9CloseModeE
obj:/ home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0
obj:/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0
obj:/home/lmartin/Qt/ 5.7/gcc_64/lib/libQt5Widgets.so.5.7.0
乐趣:_ZN5QMenu17mouseReleaseEventEP11QMouseEvent
fun:_ZN7QWidget5eventEP6QEvent fun:_ZN5QMenu5eventEP6QEvent
fun:_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent
fun:_ZN12QApplication6notifyEP7QObjectP6QEvent
fun:_ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent
fun:_ZN19QApplicationPrivate14sendMouseEventEP7QWidgetP11QMouseEventS1_S1_PS1_R8QPointerIS0_Eb obj:/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0
obj:/home/lmartin/Qt/5.7 /gcc_64/lib/libQt5Widgets.so.5.7.0
fun:_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent }
我该如何着手解决这类问题?