Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    Mobile and Embedded
    4
    8
    4663
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      Eric Ruei last edited by

      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

      1 Reply Last reply Reply Quote 0
      • yuvaram
        yuvaram last edited by

        Hi,

        In the slot you can use

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

        Yuvaram Aligeti
        Embedded Qt Developer
        : )

        E 1 Reply Last reply Reply Quote 0
        • E
          Eric Ruei @yuvaram last edited by

          @yuvaram

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

          Best regards,

          Eric

          yuvaram 1 Reply Last reply Reply Quote 0
          • yuvaram
            yuvaram @Eric Ruei last edited by

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

            Yuvaram Aligeti
            Embedded Qt Developer
            : )

            1 Reply Last reply Reply Quote 0
            • M
              mvuori last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • P
                Paul Colby last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • E
                  Eric Ruei last edited by

                  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

                  1 Reply Last reply Reply Quote 0
                  • E
                    Eric Ruei last edited by

                    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

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post