Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6324367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:41:23+00:00 2026-05-24T16:41:23+00:00

How can I detect memory leaks in QtCreator on Windows? On the doc, they

  • 0

How can I detect memory leaks in QtCreator on Windows? On the doc, they recommend Memcheck but it only works on Mac and Linux. Any suggestion for Windows?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:41:24+00:00Added an answer on May 24, 2026 at 4:41 pm

    After many tries I finally found a method to detect the memory leaks of a Qt project on Windows:

    1) First, it cannot be done directly in Qt Creator so you need to create a Visual C++ project to do the memory leak detection. Thankfully, qmake makes this easy. Open the Qt SDK command line tool and run:

    qmake -spec win32-msvc2008 -tp vc
    

    This will convert your project to a .vcproj.

    2) Open this project and add the necessary code for memory leak detection:

    To your main.cpp file:

    // Necessary includes and defines for memory leak detection:
    #ifdef _MSC_VER
    #define _CRTDBG_MAP_ALLOC
    #include <crtdbg.h>
    #endif // _MSC_VER
    
    
    #if defined(_MSC_VER)
    
    // Code to display the memory leak report
    // We use a custom report hook to filter out Qt's own memory leaks
    // Credit to Andreas Schmidts - http://www.schmidt-web-berlin.de/winfig/blog/?p=154
    
    _CRT_REPORT_HOOK prevHook;
    
    int customReportHook(int /* reportType */, char* message, int* /* returnValue */) {
      // This function is called several times for each memory leak.
      // Each time a part of the error message is supplied.
      // This holds number of subsequent detail messages after
      // a leak was reported
      const int numFollowupDebugMsgParts = 2;
      static bool ignoreMessage = false;
      static int debugMsgPartsCount = 0;
    
      // check if the memory leak reporting starts
      if ((strncmp(message,"Detected memory leaks!\n", 10) == 0)
        || ignoreMessage)
      {
        // check if the memory leak reporting ends
        if (strncmp(message,"Object dump complete.\n", 10) == 0)
        {
          _CrtSetReportHook(prevHook);
          ignoreMessage = false;
        } else
          ignoreMessage = true;
    
        // something from our own code?
        if(strstr(message, ".cpp") == NULL)
        {
          if(debugMsgPartsCount++ < numFollowupDebugMsgParts)
            // give it back to _CrtDbgReport() to be printed to the console
            return FALSE;
          else
            return TRUE;  // ignore it
        } else
        {
          debugMsgPartsCount = 0;
          // give it back to _CrtDbgReport() to be printed to the console
          return FALSE;
        }
      } else
        // give it back to _CrtDbgReport() to be printed to the console
        return FALSE;
    }
    
    #endif
    
    
    
    int main(int argc, char *argv[]) {
        #if defined(_MSC_VER)
        _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
        prevHook = _CrtSetReportHook(customReportHook);
        // _CrtSetBreakAlloc(157); // Use this line to break at the nth memory allocation
        #endif
    
        QApplication* app = new QApplication(argc, argv);   
        int appError = app->exec();
        delete app;
    
        #if defined(_MSC_VER)
        // Once the app has finished running and has been deleted,
        // we run this command to view the memory leaks:
        _CrtDumpMemoryLeaks();
        #endif 
    
        return appError;
    }
    

    3) With this, your project should now be able to detect memory leaks. Note the _MSC_VER defines so that this code is only executed when your run it from Visual C++ (not from Qt Creator). It means you can still do the development with Qt Creator and just re-run step 1 whenever you need to check for memory leaks.

    4) To break at a particular memory allocation, use _CrtSetBreakAlloc() More information memory leak detection on Microsoft’s website: http://msdn.microsoft.com/en-us/library/e5ewb1h3%28v=vs.80%29.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How I can detect memory leaks of C++ application in Linux (Ubuntu OS) ?
How can I automatically detect memory leaks in C++ in a portable way? I
Is there any good visual tool which can be used to detect memory leaks
Can I use task manager to detect huge memory leaks? I have a small
Has anybody used Eclipse memory manager to detect memory leak in java codes? Can
I'm trying to determine how I can detect when the user changes the Windows
I am using Visual Leak Detector to detect memory leaks in my program. When
Here's a dead-simple webpage that leaks memory in IE8 using jQuery (I detect memory
Am looking for tools to detect Memory Leaks, File open issues in Java based
I'm trying to use mtrace to detect memory leaks in a fortran program. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.