Important: Please read the Qt Code of Conduct -

Debugging a Qt-library

  • Hi!

    How do I make changes to a qt-library's source-code for debugging purposes?

    I am currently using the Q3DScatter of the Data Visualization library to visualize a point-cloud, and it seems that every time I update the point-cloud with new data there is a memory leak. I have analyzed my method for loading the point-cloud data and the problem seems to be elsewhere, which has made me look to the library itself. I have attempted to edit and rebuild the library-code, but it doesn't seem to work. So my question is how to do this? I would prefer to avoid building from the open-source code until I know that the problem is in the library and that a change is necessary.

  • Lifetime Qt Champion

    @Rasmunis You don't need to build from sources to be able to debug Qt. Install Qt sources (same version of Qt you're using) and tell QtCreator where it is. Then you should be able to step into Qt code.

  • Yes, I am able to step into it in debug-mode, but I want to make changes to it so I can test if there's an actual bug there. Sorry if I phrased myself a bit confusingly.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Might be a silly question but after building the module, did you install it ?

  • @SGaist Thank you :)

    If I understand you correctly, yes. I have been using it for the past couple of months.

  • I'll be a bit more concrete. This is what I am attempting:


    The fullLoad-method is called on every update of the scatter-graph and seems to be handling the buffers. But m_meshDataLoaded is set to false, and is not changed until it is checked for true (which would delete the old buffers). I suspect this might be the cause of the memory leak.

    void ScatterObjectBufferHelper::fullLoad(ScatterSeriesRenderCache *cache, qreal dotScale)
        m_meshDataLoaded = false; <-- set to false
        m_indexCount = 0;
        ObjectHelper *dotObj = cache->object();
        const ScatterRenderItemArray &renderArray = cache->renderArray();
        const uint renderArraySize = renderArray.size();
        if (renderArraySize == 0)
            return;  // No use to go forward
        uint itemCount = 0;
        QQuaternion seriesRotation(cache->meshRotation());
        if (m_meshDataLoaded) { <-- checked to be true
            // Delete old data
            glDeleteBuffers(1, &m_vertexbuffer);
            glDeleteBuffers(1, &m_uvbuffer);
            glDeleteBuffers(1, &m_normalbuffer);
            glDeleteBuffers(1, &m_elementbuffer);
            m_vertexbuffer = 0;
            m_uvbuffer = 0;
            m_normalbuffer = 0;
            m_elementbuffer = 0;

  • Lifetime Qt Champion

    Then I am a bit lost with your question.

    So you successfully built and used the custom version of the module yet it seems that your modifications are not taken into account ?

  • @SGaist No. I've been using the standard module for two months and now I wanted to change it, so I made some changes and rebuilt it and then my changes are not taken into account.

  • Lifetime Qt Champion

    Hence my question: did you install your custom built module ? Just building it is not enough.

  • @SGaist I see. I thought you meant if I had ever installed it. Then no, I did not install it.

  • @SGaist So how do I install it? I have only changed a single line of code, so I just want to sort of "update" the standard module.

  • @Rasmunis
    So you have built it but not installed it anywhere that your application will pick up from. You either need to do a full build and go through the installation process for Qt for building from source, or if you are sure you have built exactly the same version of Qt as you presently have in all its shared libraries you could identify the single shared library (.so or .dll) this source file contributes to and just (temporarily) replace that with your newly compiled version. If you intend to debug-step into your new code, you will also have to ensure that your source file is found by the debugger.

  • Lifetime Qt Champion

    @Rasmunis said in Debugging a Qt-library:

    So how do I install it?

    make install

  • Lifetime Qt Champion

    @JonB you don't need a full Qt build to build one module for the Qt version you are currently using however you are right about making a backup of the files related to the module you are going to hack on if you don't have your own build.

  • @SGaist said in Debugging a Qt-library:

    @JonB you don't need a full Qt build to build one module for the Qt version you are currently using

    Indeed not, but do you wish to guarantee that the user is rebuilding one library against an existing build/system-supplied which is deffo, deffo the same version, compiled in the same way etc.? :) Because I can hear "version mis-match" in the distance... ;)

  • I tried @JonB 's approach and it worked for me. And I did manage to remove the memory-leak, which makes me think that this is a bug in the library. How do you suggest to move forward with this?

    @jsulm Where do you execute the make-commands? I have yet to find any makefiles.

    Edit: I found the makefile in the build-folder.

  • Lifetime Qt Champion

    @Rasmunis said in Debugging a Qt-library:

    How do you suggest to move forward with this?

    File a bug in Qt bug tracker:

    "Where do you execute the make-commands?" - where you build Qt.

    configure ...
    make install

  • Lifetime Qt Champion

    After the bug report, since you have a fix, you can submit a patch for inclusion :-)

Log in to reply