How can I pin-point the location of the call in my code that triggered QObject::connect: Cannot queue arguments of type in Qt5?

本秂侑毒 提交于 2019-12-25 01:00:09

问题


In my Qt5 application, I am receiving a log message at run time from Qt itself that looks like this:

QObject::connect: Cannot queue arguments of type 'QHostAddress'

I know how to fix the cause of this message using Q_DECLARE_METATYPE(QHostAddress) macro or qRegisterMetaType<QHostAddress>("QHostAddress") class, that is not what this question is about.

What I want to know is, how can I pin-point the exact location of the call in my code that triggered this message?

Since the message does not come with a file/line number and since I seem to be unable to set debugger break-points inside Qt5 itself I can't find out what causes this message.


回答1:


I create a message handler to catch the messages:

void myMessageHandler(QtMsgType type, const QMessageLogContext & logContext, const QString & msg)
{
    Q_UNUSED(logContext);

    switch (type) {
    case QtDebugMsg:
        std::cerr << qPrintable(QString("qDebug: %1").arg(msg)) << std::endl;
        break;
    case QtWarningMsg:
        std::cerr << qPrintable(msg) << std::endl;
        break;
    case QtCriticalMsg:
        std::cerr << qPrintable(QString("qCritical: %1").arg(msg)) << std::endl;
        break;
    case QtFatalMsg:
        std::cerr << qPrintable( QString("qFatal: %1").arg(msg) ) << std::end;
            abort();

    }
}

Then in main install the message handler:

int main() 
{
   qInstallMessageHandler(myMessageHandler);

// rest of main
}

Then I set a breakpoint on the warning case. When the breakpoint is hit I walk up the callstack to the line of code that triggered the warning. On some of my applications I have put an assert(false) instead so I don't forget to set the breakpoint.



来源:https://stackoverflow.com/questions/47624731/how-can-i-pin-point-the-location-of-the-call-in-my-code-that-triggered-qobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!