Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting Debug Heap correction from destructor of QStringList
Forum Updated to NodeBB v4.3 + New Features

Getting Debug Heap correction from destructor of QStringList

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 5 Posters 4.2k Views 2 Watching
  • 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.
  • O Offline
    O Offline
    OnkarP
    wrote on last edited by
    #5

    @jsulm : Can you please explain what do you mean by build system ?
    I am using the pre built libraries and dlls (QT6.6.3 MSVC 2019_64bit) which are available in QT installer tool. I am referencing the debug libs (having "d" suffixed) for debug configuration. I am using Visual studio 2022.

    I was successful with building my application(which was 32 bit) with QT5 prebuilt libraries for 32 bit. Same approach I am trying to convert my 32 bit application to 64 bit.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #6

      Please show your CMakeLists.txt.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • O Offline
        O Offline
        OnkarP
        wrote on last edited by
        #7

        @Christian-Ehrlicher
        Which one you want to look from installed folder ?

        image.png

        I have installed from here and not built on my own.
        image.png

        Thanks,
        Onkar

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #8

          The CMakeLists.txt from your project. Or pro file - depending on how you built your project

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • O Offline
            O Offline
            OnkarP
            wrote on last edited by
            #9

            I am using Visual studio. I have used these libs

            image.png

            I have included directories as

            image.png

            The code configuration setting as

            image.png

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by Christian Ehrlicher
              #10

              So you create the solution manually? Does it crash in the debug version or when you execute it in the Release version?
              Minimize your code until it either does no longer crash or is that small that you can post it here (not more than 50 lines should be necessary).

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • O Offline
                O Offline
                OnkarP
                wrote on last edited by OnkarP
                #11

                Yes. In Debug version it crashes and in Release it passes that code but again fails somewhere else.
                This is code from one of my function. When filesList object goes out of scope then I am getting crash and Debug assertion as mentioned in the post.

                ========================================================================

                QStringList filesList ;
                if (!cb->currentText().isEmpty())
                {
                	filesList.append(ConvertFromQtSeparator(cb->currentText()));
                }
                else
                {
                	filesList.append(".");
                }
                
                for (int i = 0, iComboCount = cb->count(); i<iComboCount; ++i)
                {	
                	QString item = ConvertFromQtSeparator(cb->itemText(i));
                	if (!item.isEmpty() && !filesList.contains(item, Qt::CaseInsensitive))
                	{
                		filesList.append(item);
                	}
                }
                
                SettingsGroupInit group("FilesOpeningHistory");
                
                group.settings.setValue(prefix + QString("Files"), filesList);
                if (!cb->currentText().isEmpty())
                {			
                	QString combCurrentTex = cb->currentText();
                	group.settings.setValue(prefix + QString("Directory"), ConvertFromQtSeparator(DIRECTORY::directory(combCurrentTex)));
                }
                

                ==================================================================

                Additional information is that my application has UI and moc files are generated for them. The setting to create moc file is as below

                image.png

                Thanks for looking into this. Appreciated.

                JonBJ 1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by Christian Ehrlicher
                  #12

                  This is no minimal, compileable example but just some piece of unreadable code... Please at least properly format your code.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  1
                  • O OnkarP

                    Yes. In Debug version it crashes and in Release it passes that code but again fails somewhere else.
                    This is code from one of my function. When filesList object goes out of scope then I am getting crash and Debug assertion as mentioned in the post.

                    ========================================================================

                    QStringList filesList ;
                    if (!cb->currentText().isEmpty())
                    {
                    	filesList.append(ConvertFromQtSeparator(cb->currentText()));
                    }
                    else
                    {
                    	filesList.append(".");
                    }
                    
                    for (int i = 0, iComboCount = cb->count(); i<iComboCount; ++i)
                    {	
                    	QString item = ConvertFromQtSeparator(cb->itemText(i));
                    	if (!item.isEmpty() && !filesList.contains(item, Qt::CaseInsensitive))
                    	{
                    		filesList.append(item);
                    	}
                    }
                    
                    SettingsGroupInit group("FilesOpeningHistory");
                    
                    group.settings.setValue(prefix + QString("Files"), filesList);
                    if (!cb->currentText().isEmpty())
                    {			
                    	QString combCurrentTex = cb->currentText();
                    	group.settings.setValue(prefix + QString("Directory"), ConvertFromQtSeparator(DIRECTORY::directory(combCurrentTex)));
                    }
                    

                    ==================================================================

                    Additional information is that my application has UI and moc files are generated for them. The setting to create moc file is as below

                    image.png

                    Thanks for looking into this. Appreciated.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #13

                    @OnkarP
                    As @Christian-Ehrlicher has said. And if your problem arises "When filesList object goes out of scope" then you need to provide code where that happens, yours just declares QStringList filesList ; somewhere and maybe it goes out of scope somewhere else but we don't know.

                    You need to reduce your issue to a 50-line, standalone, single file, compilable reproducer for people to look at (and maybe you will find the issue yourself if you do so). If your problem is to do with a QStringList scope then presumably it does not need any combobox or UI stuff. And if it can "again fails somewhere else." then clearly full context is important.

                    You could also look at/show the stack trace when it crashes from Debug version.

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      OnkarP
                      wrote on last edited by
                      #14

                      Hello, As mentioned in my first post when I tried almost similar code in console application then I am not seeing this error.
                      ====Sample code Starts=================

                      #include <iostream>
                      #include <QtCore/qcoreapplication.h>
                      #include <QtCore/qlist.h>
                      
                      bool DoSomeManipulation()
                      {    
                          // Creating a QStringList
                          QStringList fruits;
                      
                          // Adding items to the list
                          fruits << "Apple" << "Banana" << "Cherry" << "Date";
                      
                          // Accessing elements using index
                          qDebug() << "First fruit:" << fruits.at(0);
                          qDebug() << "Last fruit:" << fruits.last();
                      
                          // Iterating through the list
                          qDebug() << "\nAll fruits:";
                          for (const QString& fruit : fruits) {
                              qDebug() << fruit;
                          }
                      
                          // Checking if list contains a specific item
                          QString searchFruit = "Banana";
                          if (fruits.contains(searchFruit)) {
                              qDebug() << "\nFound" << searchFruit << "in the list.";
                          }
                          else {
                              qDebug() << "\n" << searchFruit << "not found in the list.";
                          }
                      
                          // Sorting the list alphabetically
                          fruits.sort();
                          qDebug() << "\nSorted fruits:";
                          for (const QString& fruit : fruits) {
                              qDebug() << fruit;
                          }
                          return true;
                      }
                      
                      int main(int argc, char* argv[])
                      {
                          QCoreApplication app(argc, argv);
                          bool t = DoSomeManipulation(); 
                          
                          return app.exec();
                         
                      
                      }
                      

                      ===========Sample code ends====================================
                      My function is exact similar which gets called on some windows button action.
                      ====Sample code starts=========================

                      void COpenDlg::SaveSettingFilesList(QComboBox* cb, QString prefix)
                      {	
                      	if (cb->count() == 0)
                      	{
                      		return;
                      	}
                      	QStringList filesList;
                      	if (!cb->currentText().isEmpty())
                      	{		
                      		filesList.append(ConvertFromQtSeparator(cb->currentText()));
                      	}
                      	else
                      	{
                      		filesList.append(".");
                      	}
                      
                      	for (int i = 0, iComboCount = cb->count(); i < iComboCount; ++i)
                      	{
                      		QString item = ConvertFromQtSeparator(cb->itemText(i));
                      		if (!item.isEmpty() && !filesList.contains(item, Qt::CaseInsensitive))
                      		{			
                      			filesList.append(item);
                      		}		
                      	}
                      
                      	SettingsGroupInit group("FilesOpeningHistory");
                      	group.settings.setValue(prefix + QString("Files"), filesList);
                      	if (!cb->currentText().isEmpty())
                      	{
                      		QString combCurrentTex = cb->currentText();
                      		group.settings.setValue(prefix + QString("Directory"), ConvertFromQtSeparator(DIRECTORY::directory(combCurrentTex)));
                      	}	
                      }
                      

                      ====Sample code ends==========================
                      While exiting this function I get crash. The call stack looks like

                      image.png

                      The assert window

                      image.png

                      Please let me know if I can add any additional information.

                      JonBJ 1 Reply Last reply
                      0
                      • O OnkarP

                        Hello, As mentioned in my first post when I tried almost similar code in console application then I am not seeing this error.
                        ====Sample code Starts=================

                        #include <iostream>
                        #include <QtCore/qcoreapplication.h>
                        #include <QtCore/qlist.h>
                        
                        bool DoSomeManipulation()
                        {    
                            // Creating a QStringList
                            QStringList fruits;
                        
                            // Adding items to the list
                            fruits << "Apple" << "Banana" << "Cherry" << "Date";
                        
                            // Accessing elements using index
                            qDebug() << "First fruit:" << fruits.at(0);
                            qDebug() << "Last fruit:" << fruits.last();
                        
                            // Iterating through the list
                            qDebug() << "\nAll fruits:";
                            for (const QString& fruit : fruits) {
                                qDebug() << fruit;
                            }
                        
                            // Checking if list contains a specific item
                            QString searchFruit = "Banana";
                            if (fruits.contains(searchFruit)) {
                                qDebug() << "\nFound" << searchFruit << "in the list.";
                            }
                            else {
                                qDebug() << "\n" << searchFruit << "not found in the list.";
                            }
                        
                            // Sorting the list alphabetically
                            fruits.sort();
                            qDebug() << "\nSorted fruits:";
                            for (const QString& fruit : fruits) {
                                qDebug() << fruit;
                            }
                            return true;
                        }
                        
                        int main(int argc, char* argv[])
                        {
                            QCoreApplication app(argc, argv);
                            bool t = DoSomeManipulation(); 
                            
                            return app.exec();
                           
                        
                        }
                        

                        ===========Sample code ends====================================
                        My function is exact similar which gets called on some windows button action.
                        ====Sample code starts=========================

                        void COpenDlg::SaveSettingFilesList(QComboBox* cb, QString prefix)
                        {	
                        	if (cb->count() == 0)
                        	{
                        		return;
                        	}
                        	QStringList filesList;
                        	if (!cb->currentText().isEmpty())
                        	{		
                        		filesList.append(ConvertFromQtSeparator(cb->currentText()));
                        	}
                        	else
                        	{
                        		filesList.append(".");
                        	}
                        
                        	for (int i = 0, iComboCount = cb->count(); i < iComboCount; ++i)
                        	{
                        		QString item = ConvertFromQtSeparator(cb->itemText(i));
                        		if (!item.isEmpty() && !filesList.contains(item, Qt::CaseInsensitive))
                        		{			
                        			filesList.append(item);
                        		}		
                        	}
                        
                        	SettingsGroupInit group("FilesOpeningHistory");
                        	group.settings.setValue(prefix + QString("Files"), filesList);
                        	if (!cb->currentText().isEmpty())
                        	{
                        		QString combCurrentTex = cb->currentText();
                        		group.settings.setValue(prefix + QString("Directory"), ConvertFromQtSeparator(DIRECTORY::directory(combCurrentTex)));
                        	}	
                        }
                        

                        ====Sample code ends==========================
                        While exiting this function I get crash. The call stack looks like

                        image.png

                        The assert window

                        image.png

                        Please let me know if I can add any additional information.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #15

                        @OnkarP
                        You show a crash on destructing the QStringList filesList passed to a SettingsGroupInit group. But you don't show its code so nobody knows what it does with the parameter, which later goes out of scope. Can you not produce a simple, small, complete example exhibiting the crash?

                        1 Reply Last reply
                        0
                        • O Offline
                          O Offline
                          OnkarP
                          wrote on last edited by
                          #16

                          @JonB : I have spent some time on reproducing this issue outside my application. Here is the code change I done to reproduce the problem. I have called the same function more than once in my sample console application and I am able to reproduce the issue.

                          // TestQT.cpp : This file contains the 'main' function. Program execution begins and ends there.
                          //
                          
                          #include <iostream>
                          #include <QtCore/qcoreapplication.h>
                          #include <QtCore/qlist.h>
                          
                          bool DoSomeManipulation()
                          {    
                              // Creating a QStringList
                              QStringList fruits;
                          
                              // Adding items to the list
                              fruits << "Apple" << "Banana" << "Cherry" << "Date";
                          
                              // Accessing elements using index
                              qDebug() << "First fruit:" << fruits.at(0);
                              qDebug() << "Last fruit:" << fruits.last();
                          
                              // Iterating through the list
                              qDebug() << "\nAll fruits:";
                              for (const QString& fruit : fruits) {
                                  qDebug() << fruit;
                              }
                          
                              // Checking if list contains a specific item
                              QString searchFruit = "Banana";
                              if (fruits.contains(searchFruit)) {
                                  qDebug() << "\nFound" << searchFruit << "in the list.";
                              }
                              else {
                                  qDebug() << "\n" << searchFruit << "not found in the list.";
                              }
                          
                              // Sorting the list alphabetically
                              fruits.sort();
                              qDebug() << "\nSorted fruits:";
                              for (const QString& fruit : fruits) {
                                  qDebug() << fruit;
                              }
                              return true;
                          }
                          
                          int main(int argc, char* argv[])
                          {
                              QCoreApplication app(argc, argv);
                              bool t = DoSomeManipulation(); 
                              bool t1 = DoSomeManipulation();
                              bool t2 = DoSomeManipulation();
                              
                              return app.exec();   
                          
                          }
                          

                          My Dependencies
                          fb38e9ef-1f94-4a40-b694-e54134dfb9d7-image.png

                          Additional include directories
                          ff960015-07ee-4ab1-a77e-f254f820fc7b-image.png

                          Crash stack
                          05333cd2-50a2-4fc4-b20a-3854dbf0ec5c-image.png

                          My QTDIr value
                          8c4b2747-cecf-429a-8bc8-dbe3ff014946-image.png

                          Hope you will also able to see the crash!

                          JonBJ 1 Reply Last reply
                          0
                          • O OnkarP

                            @JonB : I have spent some time on reproducing this issue outside my application. Here is the code change I done to reproduce the problem. I have called the same function more than once in my sample console application and I am able to reproduce the issue.

                            // TestQT.cpp : This file contains the 'main' function. Program execution begins and ends there.
                            //
                            
                            #include <iostream>
                            #include <QtCore/qcoreapplication.h>
                            #include <QtCore/qlist.h>
                            
                            bool DoSomeManipulation()
                            {    
                                // Creating a QStringList
                                QStringList fruits;
                            
                                // Adding items to the list
                                fruits << "Apple" << "Banana" << "Cherry" << "Date";
                            
                                // Accessing elements using index
                                qDebug() << "First fruit:" << fruits.at(0);
                                qDebug() << "Last fruit:" << fruits.last();
                            
                                // Iterating through the list
                                qDebug() << "\nAll fruits:";
                                for (const QString& fruit : fruits) {
                                    qDebug() << fruit;
                                }
                            
                                // Checking if list contains a specific item
                                QString searchFruit = "Banana";
                                if (fruits.contains(searchFruit)) {
                                    qDebug() << "\nFound" << searchFruit << "in the list.";
                                }
                                else {
                                    qDebug() << "\n" << searchFruit << "not found in the list.";
                                }
                            
                                // Sorting the list alphabetically
                                fruits.sort();
                                qDebug() << "\nSorted fruits:";
                                for (const QString& fruit : fruits) {
                                    qDebug() << fruit;
                                }
                                return true;
                            }
                            
                            int main(int argc, char* argv[])
                            {
                                QCoreApplication app(argc, argv);
                                bool t = DoSomeManipulation(); 
                                bool t1 = DoSomeManipulation();
                                bool t2 = DoSomeManipulation();
                                
                                return app.exec();   
                            
                            }
                            

                            My Dependencies
                            fb38e9ef-1f94-4a40-b694-e54134dfb9d7-image.png

                            Additional include directories
                            ff960015-07ee-4ab1-a77e-f254f820fc7b-image.png

                            Crash stack
                            05333cd2-50a2-4fc4-b20a-3854dbf0ec5c-image.png

                            My QTDIr value
                            8c4b2747-cecf-429a-8bc8-dbe3ff014946-image.png

                            Hope you will also able to see the crash!

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #17

                            @OnkarP
                            Your code looks good. The only thing which alters the list (apart from the initial population) is the fruits.sort() so I would try commenting that out to see if different behaviour.

                            You might try with code as simple as:

                            bool DoSomeManipulation()
                            {    
                                // Creating a QStringList
                                QStringList fruits;
                            
                                // Adding items to the list
                                fruits << "Apple" << "Banana" << "Cherry" << "Date";
                                return true;
                            }
                            

                            You call it 3 times, but do not say if (a) this is required to make it go wrong or (b) which iteration it falls over on.

                            The "crash site" indicates that the memory allocation area is corrupted, for whatever reason. Make sure you are consistently compiling for 64-bit and the program depends on the MSVC debug runtime (something like VCRUNTIMED.DLL or MSVCRTD.DLL? note the trailing D), with no sign of a non-debug version.

                            Other than that you will have to await someone with Windows and a similar version of MSVC/Qt to see if happens to them. If you can try a later Qt version than 6.6.3 (e.g. 6.7?) you might test that.

                            1 Reply Last reply
                            0
                            • O Offline
                              O Offline
                              OnkarP
                              wrote on last edited by
                              #18

                              @JonB : Calling 2 times with your suggested change also crashed.

                              1 Reply Last reply
                              0
                              • O Offline
                                O Offline
                                OnkarP
                                wrote on last edited by
                                #19

                                Hello,
                                I investigated further as per your suggestion and have below observations.
                                In my sample application the current runtime setting is

                                image.png

                                If I run the code as mentioned above I was getting heap crash. If I add dependency on msvcrtd.lib in my project properties then
                                the crash is not coming in the same code.

                                image.png

                                Is there anything problem with Qt libraries or these settings are compulsory for Qt6? Because for Qt5 I have not added any such settings when using prebuilt libraries of 32 bit.

                                Can you please check whether if I am missing anything on this?

                                In my project if I add dependencies "msvcrtd.lib VCRUNTIMED.lib" then I am able to fix the problem of crashing. But further I am observing specific APIs are not behaving as it was behaving with Qt5.

                                QtConcurrent::blockingMap(_parts, Movepart(position));
                                

                                Do you have any suggestions for this ?

                                Thanks in advance for help!

                                Regards,
                                Onkar

                                PS : I have checked with QT 6.7.1 and saw similar issue there.

                                1 Reply Last reply
                                0
                                • Christian EhrlicherC Online
                                  Christian EhrlicherC Online
                                  Christian Ehrlicher
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #20

                                  Use a proper build system generator like CMake, qmake or the Qt Visual Studio plugin (which uses CMake) to avoid such problems.

                                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                  Visit the Qt Academy at https://academy.qt.io/catalog

                                  1 Reply Last reply
                                  1
                                  • O Offline
                                    O Offline
                                    OnkarP
                                    wrote on last edited by
                                    #21

                                    The above mentioned code where I need to add explicit dependency on msvcrtd.lib is created using new QT project in Visual studio using QT add-on.

                                    The workaround which is working for me when runtime library is Multi-threaded Debug (/MTd) is adding msvcrtd.lib in additional dependencies. If I don't add this then I was getting exception for code which I shared earlier.

                                    1 Reply Last reply
                                    0
                                    • O Offline
                                      O Offline
                                      OnkarP
                                      wrote on last edited by
                                      #22
                                      1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library 
                                      

                                      In addition to above there is also a warning while building this project. I am looking for confirmation whether there is some issue in my project settings which I missed and which is causing these problems or extra steps to work with QT6MSVC2019_64.

                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        martial
                                        wrote on last edited by martial
                                        #23

                                        If using the visual studio qt addin:
                                        In visual studio project settings : /QtProjectSettings/BuildConfig
                                        Check that it's debug in debug and release in release

                                        1 Reply Last reply
                                        0

                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved