Debug Help: How to find the source of QT SIGNAL?



  • Hi, Experts:

    I am debugging a QT5 issue for QT demo browser at \examples\webkitwidgets\browser.
    The issue is that the webpage loading is terminated before it is completed for some reason.

    Received finished signal while progress is still: 10 Url: QUrl("http://10.4.1.14/")

    WebView::WebView(QWidget* parent)
    {

    connect(this, SIGNAL(loadFinished(bool)),
    this, SLOT(loadFinished()));

    }

    It is clear that someone triggers (emits) the SIGNAL(loadFinished(bool)). If I can find the source, then I shall be able to find out why it is triggered prematurely. But I am not able to find out which code sends this SIGNAL. Is there a way to find out the source of QT signals?

    Best regards,

    Eric Ruei



  • Hi,

    In the slot you can use

    QObject *obj = this->sender();
    qDebug()<<"objName ::"<<obj->objectName()<<endl;



  • @yuvaram

    Thank you so much!
    Unfortunately, the objName is Null.
    objName :: ""

    Best regards,

    Eric



  • @Eric-Ruei
    The signals used for this slot ,try to assign object name using ,
    setObjectName();
    Then try above methods.



  • AFIK the sender() works only if a signal was emitted. It could be that the slot is called by a regular method call. In that case you can use regular debugger techniques.



  • AFIK the sender() works only if a signal was emitted.

    True, but in this case, sender must be working, or the dereference would (most likely) be segfaulting, rather than return an empty QString.

    In my experience, most QObject's have no name unless you set one yourself. However, they should all have a class-name.

    Try adding something like:

    Q_CHECK_PTR(obj);
    qDebug() << "objClass ::" << obj->metaObject()->className();
    qDebug() << "method ::" << obj->metaObject()->method(senderSignalIndex())->methodSignature();
    

    (Error checks omitted for brevity)

    Cheers.



  • Thanks everyone for your help.
    To debug why the webpage load failed, I am trying to find which piece of code trigger the loadFinished() SIGNAL.
    With all your help, I am able to find the class of the sender, which happens to be the one where the slot function runs.

    QPixmap::scaled: Pixmap is a null pixmap
    QPixmap::scaled: Pixmap is a null pixmap
    WebView::setProgress: 74
    WebView::setProgress: 100
    WebView::loadFinished:
    objClass :: WebView

    void WebView::loadFinished()
    {
    QObject *obj = this->sender();

    if (100 != m_progress) {
        qWarning() << "Received finished signal while progress is still:" << progress()
                   << "Url:" << url();
    }
    qWarning() << "WebView::loadFinished:";
    Q_CHECK_PTR(obj);
    qDebug() << "objClass ::" << obj->metaObject()->className();
    //qDebug() << "method ::" << obj->metaObject()->method(senderSignalIndex())->methodSignature();    
    m_progress = 0;
    

    }

    And the signal/slot connection is declared at the class constructor as the followings:
    connect(this, SIGNAL(loadFinished(bool)),
    this, SLOT(loadFinished()));

    Therefore, it make sense that the sender and receiver belong to the same object. And I should test it out by assign an object name.

    I cannot find where the loadFinished SIGNAL is emitted or triggered somehow in this class.
    It will be highly appreciated for any further assistance!
    This is the QT5 standard demo browser example at qt5\examples\webkitwidgets\browser, not our own code.

    Best regards,

    Eric



  • Thank you so much for the kind assistance from all of you!
    I finally find the place where loadFinished() Signal is emitted.

    "QWebFramePrivate::emitLoadFinished call loadFinished with: false"

    I realized that the signal loadFinished() is not defined at WebView, but QWebView and the signal should be emitted.
    With a search and a few QDebug() trace, I am able to find the interesting code section.

    Best regards,

    Eric Ruei


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.