8

我想使用 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 中有设置调试模式):

$ 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 
$

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

4

1 回答 1

6

如果 Qt 库本身没有在调试模式下编译,这是可以预料的。医生

该函数对调试很有用,但如果库已在发布模式下编译(即没有调试信息),则不会执行任何操作。

为了完成这项工作,您可以从源代码自编译 Qt,而不是(或除此之外)使用预编译的包。

于 2012-08-29T01:06:34.937 回答