<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Qt on Rebel Zhang&#39;s Blog</title>
        <link>https://rebel1725.codeberg.page/blog/en/tags/qt/</link>
        <description>Recent content in Qt on Rebel Zhang&#39;s Blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-GB</language>
        <managingEditor>rebel1725@tilde.club (Rebel Zhang)</managingEditor>
        <webMaster>rebel1725@tilde.club (Rebel Zhang)</webMaster>
        <lastBuildDate>Sun, 09 Aug 2026 20:49:33 +0800</lastBuildDate><atom:link href="https://rebel1725.codeberg.page/blog/en/tags/qt/index.xml" rel="self" type="application/rss+xml" /><item>
            <title>Finding the Implementation of a Functionality in a QtWidgets Application Using GammaRay</title>
            <link>https://rebel1725.codeberg.page/blog/en/post/find-the-implementation-of-a-function-in-a-qtwidgets-application-using-gammaray/</link>
            <pubDate>Sun, 09 Aug 2026 20:49:33 +0800</pubDate><author>rebel1725@tilde.club (Rebel Zhang)</author>
            <guid>https://rebel1725.codeberg.page/blog/en/post/find-the-implementation-of-a-function-in-a-qtwidgets-application-using-gammaray/</guid>
            <description>&lt;p&gt;To exercise Freedom 1 and Freedom 3 of free software, and/or contribute to the free software community, we need to change the source code related to a functionality to make the software do something different. However, because we are not familiar with a project, we often do not know where the source code we need to change is. You may be lucky enough to find it by trying &lt;code&gt;grep -R &amp;lt;some-user-facing-string&amp;gt; .&lt;/code&gt;; however, sometimes that will not work (see &lt;a class=&#34;link&#34; href=&#34;../the-very-beginning-of-my-journey-contributing-to-the-free-software-community-existing-projects&#34; &gt;the previous post&lt;/a&gt;). In that case, we will need some advanced software introspection tools. For software developed with Qt, a powerful utility is &lt;a class=&#34;link&#34; href=&#34;https://www.kdab.com/software-technologies/developer-tools/gammaray/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;GammaRay&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;To use GammaRay, you first need to install it. If you want to introspect software installed from your distribution&amp;rsquo;s official repository, then install GammaRay from there too:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# apt install gammaray&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you are using &lt;code&gt;kde-builder&lt;/code&gt; to develop KDE applications, add these lines to your &lt;code&gt;~/.config/kde-builder.yaml&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;project gammaray:&#xA;  repository: https://github.com/KDAB/GammaRay.git&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and build it into your working directory:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ kde-builder gammaray&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To use GammaRay, you need to have the application you want to introspect running. Then, fire up GammaRay and choose your application in the list.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s take finding the slideshow logic in Gwenview as an example. Open Gwenview and then open an image, where you will see the &lt;code&gt;Start Slideshow&lt;/code&gt; option in the menu:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img alt=&#34;a screenshot of Gwenview&#34; class=&#34;gallery-image&#34; data-flex-basis=&#34;390px&#34; data-flex-grow=&#34;162&#34; height=&#34;952&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px&#34; src=&#34;https://rebel1725.codeberg.page/images/pic_20260809_001.png&#34; srcset=&#34;https://rebel1725.codeberg.page/blog/pic_20260809_001_9260183633641420788_hu_365916c355e33157.png 800w, https://rebel1725.codeberg.page/images/pic_20260809_001.png 1548w&#34; width=&#34;1548&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;By going through the list of widgets one by one, you will see that &lt;code&gt;0x13bda470&lt;/code&gt; is the menu we want to introspect, which contains the &lt;code&gt;Start Slideshow&lt;/code&gt; option:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img alt=&#34;GammaRay QtWidgets introspection&#34; class=&#34;gallery-image&#34; data-flex-basis=&#34;402px&#34; data-flex-grow=&#34;167&#34; height=&#34;1002&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px&#34; src=&#34;https://rebel1725.codeberg.page/images/pic_20260809_002.png&#34; srcset=&#34;https://rebel1725.codeberg.page/blog/pic_20260809_002_4293608996693979957_hu_43bd5ee0e43f111b.png 800w, https://rebel1725.codeberg.page/blog/pic_20260809_002_4293608996693979957_hu_c573a96130bd048e.png 1600w, https://rebel1725.codeberg.page/images/pic_20260809_002.png 1681w&#34; width=&#34;1681&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;And we will see a &lt;code&gt;toggle_slideshow&lt;/code&gt; QAction in the Connections tab:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img alt=&#34;Connections&#34; class=&#34;gallery-image&#34; data-flex-basis=&#34;304px&#34; data-flex-grow=&#34;126&#34; height=&#34;604&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px&#34; src=&#34;https://rebel1725.codeberg.page/images/pic_20260809_003.png&#34; width=&#34;767&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;grep&lt;/code&gt; will tell us where such a QAction is:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;~/kde/src/gwenview$ grep -R toggle_slideshow&#xA;app/fullscreencontent.cpp:    addAction(QStringLiteral(&amp;#34;toggle_slideshow&amp;#34;));&#xA;app/gwenviewui.rc:        &amp;lt;Action name=&amp;#34;toggle_slideshow&amp;#34; /&amp;gt;&#xA;app/mainwindow.cpp:        mToggleSlideShowAction = view-&amp;gt;addAction(QStringLiteral(&amp;#34;toggle_slideshow&amp;#34;), q, &amp;amp;MainWindow::toggleSlideShow);&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Open the project in your favourite IDE, for example Qt Creator, and search for the string in &lt;code&gt;app/mainwindow.cpp&lt;/code&gt;. We will find &lt;code&gt;toggle_slideshow&lt;/code&gt; here:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;        mToggleSlideShowAction = view-&amp;gt;addAction(QStringLiteral(&amp;#34;toggle_slideshow&amp;#34;), q, &amp;amp;MainWindow::toggleSlideShow);&#xA;        q-&amp;gt;updateSlideShowAction();&#xA;        connect(mSlideShow, &amp;amp;SlideShow::stateChanged, q, &amp;amp;MainWindow::updateSlideShowAction);&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now let us search for &lt;code&gt;toggleSlideShow&lt;/code&gt; here, which will lead us to this function:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;void MainWindow::toggleSlideShow()&#xA;{&#xA;    if (d-&amp;gt;mSlideShow-&amp;gt;isRunning()) {&#xA;        d-&amp;gt;mSlideShow-&amp;gt;pause();&#xA;    } else {&#xA;        if (!d-&amp;gt;mViewAction-&amp;gt;isChecked()) {&#xA;            d-&amp;gt;mViewAction-&amp;gt;trigger();&#xA;        }&#xA;        if (!d-&amp;gt;mFullScreenAction-&amp;gt;isChecked()) {&#xA;            d-&amp;gt;mFullScreenAction-&amp;gt;trigger();&#xA;        }&#xA;        QList&amp;lt;QUrl&amp;gt; list;&#xA;        for (int pos = 0; pos &amp;lt; d-&amp;gt;mDirModel-&amp;gt;rowCount(); ++pos) {&#xA;            QModelIndex index = d-&amp;gt;mDirModel-&amp;gt;index(pos, 0);&#xA;            KFileItem item = d-&amp;gt;mDirModel-&amp;gt;itemForIndex(index);&#xA;            MimeTypeUtils::Kind kind = MimeTypeUtils::fileItemKind(item);&#xA;            switch (kind) {&#xA;            case MimeTypeUtils::KIND_SVG_IMAGE:&#xA;            case MimeTypeUtils::KIND_RASTER_IMAGE:&#xA;            case MimeTypeUtils::KIND_VIDEO:&#xA;                list &amp;lt;&amp;lt; item.url();&#xA;                break;&#xA;            default:&#xA;                break;&#xA;            }&#xA;        }&#xA;        d-&amp;gt;mSlideShow-&amp;gt;start(list);&#xA;    }&#xA;    updateSlideShowAction();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Continue searching for &lt;code&gt;mSlideShow&lt;/code&gt;, and you will land here:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;struct MainWindow::Private {&#xA;    ...&#xA;    SlideShow *mSlideShow = nullptr;&#xA;    ...&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can now see that &lt;code&gt;d-&amp;gt;mSlideShow&lt;/code&gt; is of type &lt;code&gt;SlideShow *&lt;/code&gt;. Hovering over the &lt;code&gt;SlideShow&lt;/code&gt; name with the mouse will tell us that the type is provided by &lt;code&gt;lib/slideshow.h&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img alt=&#34;Qt Creator&#34; class=&#34;gallery-image&#34; data-flex-basis=&#34;271px&#34; data-flex-grow=&#34;112&#34; height=&#34;363&#34; loading=&#34;lazy&#34; sizes=&#34;(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px&#34; src=&#34;https://rebel1725.codeberg.page/images/pic_20260809_004.png&#34; width=&#34;410&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now open &lt;code&gt;lib/slideshow.cpp&lt;/code&gt; and &lt;code&gt;lib/slideshow.h&lt;/code&gt;, and you are ready to go.&lt;/p&gt;&#xA;</description>
        </item></channel>
</rss>
