创建一个只有QMenuBar的简单程序,我设法通过Valgring GBD检测到问题。
这是我的程序
main.cpp中:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.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");
}
当我使用&#34; Valgrind Memory Analyzer with GBD&#34;启动时,点击动作&#34; test1&#34;或者&#34; test2&#34;,检测到以下错误:
== 31965 == Syscall param writev(vector [...])指向未初始化的字节 == 31965 ==在0x6BE040D:??? (系统调用-template.S:84) == 31965 == by 0xBF97F28:??? (在/usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0中) == 31965 == by 0xBF9831C:??? (在/usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0中) == 31965 == by 0xBF98A76:??? (在/usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0中) == 31965 == by 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)(in /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0) == 31965 == by 0x50F3E3A:??? (在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0中) == 31965 == by 0x50F47DE:??? (在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0中) == 31965 == by 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 *)(在/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&amp;,bool)(in /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0) == 31965 == by 0x4FEF5FA:??? (在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0中) == 31965 == by 0x4FF1512:??? (在/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 0x4F9521F:QApplication :: notify(QObject *,QEvent *)(在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0中) == 31965 ==地址0xcc97941是一个大小为21,152的块内的4,545字节alloc&#39; d == 31965 ==在0x4C2FB55:calloc(在/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so中) == 31965 == by 0xBF978DB:xcb_connect_to_fd(在/usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0中) == 31965 == by 0xBF9B610:xcb_connect_to_display_with_auth_info(在/usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0中) == 31965 == by 0xB872809:_XConnectXCB(在/usr/lib/x86_64-linux-gnu/libX11.so.6.3.0中) == 31965 == by 0xB863391:XOpenDisplay(在/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&amp;,int&amp;,char **)(in /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&amp;,QStringList const&amp;,int&amp;,char **,QString const&amp;)(in /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Gui.so.5.7.0) == 31965 == by 0x577D483:QGuiApplicationPrivate :: createPlatformIntegration()(in /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Gui.so.5.7.0) == 31965 == by 0x577DF4C:QGuiApplicationPrivate :: createEventDispatcher()(in /home/lmartin/Qt/5.7/gcc_64/lib/libQt5Gui.so.5.7.0) == 31965 == by 0x60A89CC:QCoreApplicationPrivate :: init()(在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Core.so.5.7.0中) == 31965 == by 0x577E8EB:QGuiApplicationPrivate :: init()(在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Gui.so.5.7.0中) == 31965 == by 0x4F92988:QApplicationPrivate :: init()(在/home/lmartin/Qt/5.7/gcc_64/lib/libQt5Widgets.so.5.7.0中) == 31965 == by 0x402B8D:main(main.cpp:6) == 31965 ==未初始化的值是由堆栈分配创建的 == 31965 ==在0xD575DB0:非虚拟thunk到QXcbWindow :: setVisible(bool)(在 /home/lmartin/Qt/5.7/gcc_64/lib/libQt5XcbQpa.so.5.7.0) == == 31965 == 31965 ==(对错误采取行动)vgdb me ... == 31965 ==继续...... {Memcheck:Param writev(vector [...])
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
乐趣:_ZN10QXcbWindow4hideEv乐趣:_ZN7QWindow10setVisibleEb
有趣的:_ZN14QWidgetPrivate8hide_sysEv
有趣的:_ZN14QWidgetPrivate11hide_helperEv
有趣的:_ZN7QWidget10setVisibleEb
有趣的:_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
乐趣:_ZN7QWidget5eventEP6QEvent乐趣:_ZN5QMenu5eventEP6QEvent
有趣的:_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent
有趣的:_ZN12QApplication6notifyEP7QObjectP6QEvent
有趣的:_ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent
好玩的:_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
好玩:_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent}
我怎样才能解决这类问题?