c++ - 如何使 dumpObjectInfo 打印调试信息?

标签 c++ qt

我想使用 dumpObjectInfo 函数打印对象信息的转储,但没有打印任何内容。

下面是一个使用Qt的C++程序:

$ cat main1.cpp
#include <QObject>
#include <QString>
#include <QDebug>
#include "a.h"

int main() {
    A a;
    B b;
    QObject::connect(&b, SIGNAL(sendText(QString)), &a, SLOT(printText(QString)));
    b.sendSignal();
    qDebug() << "print object dump";
    a.dumpObjectInfo();
    return 0;
}

有如下.pro文件(在CONFIG中设置 Debug模式):

$ cat qt.pro
######################################################################
# Automatically generated by qmake (2.01a) Tue Aug 28 17:41:22 2012
######################################################################

TEMPLATE = app
TARGET = 
DEPENDPATH += .
INCLUDEPATH += . 

# Input
CONFIG += debug
HEADERS += a.h
SOURCES += main1.cpp 

编译:

$ qmake qt.pro && make clean && make
rm -f moc_a.cpp
rm -f main1.o moc_a.o
rm -f *~ core *.core
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o main1.o main1.cpp
/usr/bin/moc-qt4 -DQT_WEBKIT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. a.h -o moc_a.cpp
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o moc_a.o moc_a.cpp
g++  -o qt main1.o moc_a.o    -L/usr/lib/i386-linux-gnu -lQtGui -lQtCore -lpthread 
{ test -n "" && DESTDIR="" || DESTDIR=.; } && test $(gdb --version | sed -e 's,[^0-9]\+\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $DESTDIR" -ex quit 'qt' && test -f qt.gdb-index && objcopy --add-section '.gdb_index=qt.gdb-index' --set-section-flags '.gdb_index=readonly' 'qt' 'qt' && rm -f qt.gdb-index || true

程序运行:

$ ./qt
Signal text!

print object dump 
$

尽管在 .pro 文件中设置了 Debug模式,但 dumpObjectInfo 不会打印任何内容。如何让函数dumpObjectInfo打印对象信息?

最佳答案

如果 Qt 库本身没有在 Debug模式下编译,这是可以预料的。 doc说:

This function is useful for debugging, but does nothing if the library has been compiled in release mode (i.e. without debugging information).

要实现此功能,您可以从源代码自行编译 Qt,而不是(或除此之外)使用预编译包。

关于c++ - 如何使 dumpObjectInfo 打印调试信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12163695/

相关文章:

c++ - Qt raw 与 std::shared_ptr

C++ WIN32 : Running a program without a command prompt window

c++ - 为什么必须在哪里放置 “template”和 “typename”关键字?

c++ - 将 gcc 可执行文件与 Visual C++ 库链接是否安全?

c++ - 热键、快捷键和加速键有什么区别?

c++ - 多个 QApplication 实例

C++/WIN32 一个看起来很专业的应用程序——真的可能吗?

c++ - 如何调整 QMessageBox 按钮的大小以适应翻译后的文本?

c++ - 如果代码中的任何地方都没有连接插槽,是否有理由发出 Qt 信号?

c++ - 将 "Qt5Widgets"的安装前缀添加到CMAKE_PREFIX_PATH