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. Problem in QVariantList in Qt 5.12?
Qt 6.11 is out! See what's new in the release blog

Problem in QVariantList in Qt 5.12?

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 6 Posters 3.1k Views 3 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.
  • M Offline
    M Offline
    Maxxximo
    wrote on last edited by
    #1

    The following code snippet used to work fine on Qt 5.4, but on 5.12 it triggers a breakpoint inside QVariant's destructor.

    int main(int argc, char *argv[])
    {
    	QApplication a(argc, argv);
    
    	if (true)
    	{
    		QVariant res;
    
    		QVariantList list;
    		list.append(QVariant(true));
    		res = list;
    	}
    	qDebug() << "App started";
    
    	int result = a.exec();
    	return result;
    }
    
    

    If you change the code in order to use a QVariantMap instead of a QVariantList, it does work. Anybody can tell me why?

    int main(int argc, char *argv[])
    {
    	QApplication a(argc, argv);
    
    	if (true)
    	{
    		QVariant res;
    
    		QVariantMap map;
    		map.insert("1", QVariant(true));
    		res = map;
    
    	}
    	qDebug() << "App started";
    
    	int result = a.exec();
    	return result;
    }
    
    

    Compiled for x86 using Qt 5.12 with VS2017 on Win 10.

    artwawA 1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      No problem here on MacOS and Qt 5.12.10

      {
      QVariant res;
      
      QVariantMap map;
      map.insert("1", QVariant(true));
      map.insert("2", QVariant(true));
      res = map;
      qDebug()<<res.value<QVariantMap>();
      }
      

      output log: QMap(("1", QVariant(bool, true))("2", QVariant(bool, true)))

      JonBJ 1 Reply Last reply
      0
      • M mpergand

        No problem here on MacOS and Qt 5.12.10

        {
        QVariant res;
        
        QVariantMap map;
        map.insert("1", QVariant(true));
        map.insert("2", QVariant(true));
        res = map;
        qDebug()<<res.value<QVariantMap>();
        }
        

        output log: QMap(("1", QVariant(bool, true))("2", QVariant(bool, true)))

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

        @mpergand
        You mis-read :) OP is saying QVariantMap does work for him, but QVariantList instead does not....

        M 1 Reply Last reply
        0
        • JonBJ JonB

          @mpergand
          You mis-read :) OP is saying QVariantMap does work for him, but QVariantList instead does not....

          M Offline
          M Offline
          mpergand
          wrote on last edited by mpergand
          #4

          @JonB Yeah you're right :)

          but no problem with QVariantList either.

          1 Reply Last reply
          1
          • M Maxxximo

            The following code snippet used to work fine on Qt 5.4, but on 5.12 it triggers a breakpoint inside QVariant's destructor.

            int main(int argc, char *argv[])
            {
            	QApplication a(argc, argv);
            
            	if (true)
            	{
            		QVariant res;
            
            		QVariantList list;
            		list.append(QVariant(true));
            		res = list;
            	}
            	qDebug() << "App started";
            
            	int result = a.exec();
            	return result;
            }
            
            

            If you change the code in order to use a QVariantMap instead of a QVariantList, it does work. Anybody can tell me why?

            int main(int argc, char *argv[])
            {
            	QApplication a(argc, argv);
            
            	if (true)
            	{
            		QVariant res;
            
            		QVariantMap map;
            		map.insert("1", QVariant(true));
            		res = map;
            
            	}
            	qDebug() << "App started";
            
            	int result = a.exec();
            	return result;
            }
            
            

            Compiled for x86 using Qt 5.12 with VS2017 on Win 10.

            artwawA Offline
            artwawA Offline
            artwaw
            wrote on last edited by
            #5

            @Maxxximo Simple console app on macOS (Qt 6.2.1) proves it works with QVariantList:

            #include <QCoreApplication>
            
            int main(int argc, char *argv[])
            {
                QCoreApplication a(argc, argv);
                if (true)
                {
                    QVariant res;
            
                    QVariantList list;
                    list.append(QVariant(true));
                    res = list;
                }
                qDebug() << "App started";
            
                return a.exec();
            }
            

            3a81e78f-c420-4fd8-9089-6c89295e120a-image.png

            For more information please re-read.

            Kind Regards,
            Artur

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mchinand
              wrote on last edited by
              #6

              Is this perhaps a too simplified example of your actual code? It seems that your if(true) block will probably be removed (optimized out) entirely when compiled in Release mode.

              artwawA M 2 Replies Last reply
              0
              • M mchinand

                Is this perhaps a too simplified example of your actual code? It seems that your if(true) block will probably be removed (optimized out) entirely when compiled in Release mode.

                artwawA Offline
                artwawA Offline
                artwaw
                wrote on last edited by artwaw
                #7

                @mchinand If I remove the if block it gets properly executed both in debug and release. At any rate it works in 6.2.1.

                For more information please re-read.

                Kind Regards,
                Artur

                1 Reply Last reply
                1
                • M mchinand

                  Is this perhaps a too simplified example of your actual code? It seems that your if(true) block will probably be removed (optimized out) entirely when compiled in Release mode.

                  M Offline
                  M Offline
                  Maxxximo
                  wrote on last edited by
                  #8

                  @mchinand With my configuration the code faults in both Release and Debug mode. I noticed the problem because I had to upgrade to Qt 5.12 from 5.4

                  M 1 Reply Last reply
                  0
                  • M Maxxximo

                    @mchinand With my configuration the code faults in both Release and Debug mode. I noticed the problem because I had to upgrade to Qt 5.12 from 5.4

                    M Offline
                    M Offline
                    mchinand
                    wrote on last edited by
                    #9

                    @Maxxximo Looking at the stack trace, which line of code of yours does it break on?

                    M 1 Reply Last reply
                    0
                    • M mchinand

                      @Maxxximo Looking at the stack trace, which line of code of yours does it break on?

                      M Offline
                      M Offline
                      Maxxximo
                      wrote on last edited by
                      #10

                      @mchinand Here:
                      Breakpoint.png

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

                        Are you sure you don't mix binaries compiled with different MSVC versions? See e.g. here: https://bugreports.qt.io/browse/QTBUG-30009

                        Also compile your code in debug mode (and against Qt debug libs) to see where exactly inside Qt it is crashing.

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

                        M 1 Reply Last reply
                        2
                        • Christian EhrlicherC Christian Ehrlicher

                          Are you sure you don't mix binaries compiled with different MSVC versions? See e.g. here: https://bugreports.qt.io/browse/QTBUG-30009

                          Also compile your code in debug mode (and against Qt debug libs) to see where exactly inside Qt it is crashing.

                          M Offline
                          M Offline
                          Maxxximo
                          wrote on last edited by
                          #12

                          @Christian-Ehrlicher I am using a Qt version that has been supplied together with a commercial system, therefore I only have the release version of Qt.
                          I checked the dependencies, and my app depends only on Qt5Core.dll, which in turn depends on msvcp140.dll and vcruntime140.dll, so it shouldn't be a problem.

                          Christian EhrlicherC 1 Reply Last reply
                          0
                          • M Maxxximo

                            @Christian-Ehrlicher I am using a Qt version that has been supplied together with a commercial system, therefore I only have the release version of Qt.
                            I checked the dependencies, and my app depends only on Qt5Core.dll, which in turn depends on msvcp140.dll and vcruntime140.dll, so it shouldn't be a problem.

                            Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @Maxxximo said in Problem in QVariantList in Qt 5.12?:

                            I am using a Qt version that has been supplied together with a commercial system, therefore I only have the release version of Qt.

                            Then ask for the debug libraries then - otherwise a useful development is imo not really possible. You can't even create your own app as debug version without the Qt debug libs.

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

                            M 1 Reply Last reply
                            2
                            • Christian EhrlicherC Christian Ehrlicher

                              @Maxxximo said in Problem in QVariantList in Qt 5.12?:

                              I am using a Qt version that has been supplied together with a commercial system, therefore I only have the release version of Qt.

                              Then ask for the debug libraries then - otherwise a useful development is imo not really possible. You can't even create your own app as debug version without the Qt debug libs.

                              M Offline
                              M Offline
                              Maxxximo
                              wrote on last edited by
                              #14

                              @Christian-Ehrlicher said in Problem in QVariantList in Qt 5.12?:

                              You can't even create your own app as debug version without the Qt debug libs.

                              This sounds strange to me, why shouldn't it be possible? It's rather common using release libraries and the only constraint is not being able to debug them!

                              M Christian EhrlicherC 2 Replies Last reply
                              0
                              • M Maxxximo

                                @Christian-Ehrlicher said in Problem in QVariantList in Qt 5.12?:

                                You can't even create your own app as debug version without the Qt debug libs.

                                This sounds strange to me, why shouldn't it be possible? It's rather common using release libraries and the only constraint is not being able to debug them!

                                M Offline
                                M Offline
                                mchinand
                                wrote on last edited by
                                #15

                                @Maxxximo This would work fine if you always write bug-free code and use bug-free libraries.

                                1 Reply Last reply
                                1
                                • M Maxxximo

                                  @Christian-Ehrlicher said in Problem in QVariantList in Qt 5.12?:

                                  You can't even create your own app as debug version without the Qt debug libs.

                                  This sounds strange to me, why shouldn't it be possible? It's rather common using release libraries and the only constraint is not being able to debug them!

                                  Christian EhrlicherC Offline
                                  Christian EhrlicherC Offline
                                  Christian Ehrlicher
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @Maxxximo said in Problem in QVariantList in Qt 5.12?:

                                  why shouldn't it be possible?

                                  Because you must not mix debug and release libraries on windows since debug libs are using msvcrtd.dll and release ones msvcrt.dll which are not compatible.

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

                                  M 1 Reply Last reply
                                  1
                                  • Christian EhrlicherC Christian Ehrlicher

                                    @Maxxximo said in Problem in QVariantList in Qt 5.12?:

                                    why shouldn't it be possible?

                                    Because you must not mix debug and release libraries on windows since debug libs are using msvcrtd.dll and release ones msvcrt.dll which are not compatible.

                                    M Offline
                                    M Offline
                                    Maxxximo
                                    wrote on last edited by
                                    #17

                                    @Christian-Ehrlicher Ok, just to make it clear: Qt is built as a dynamic library, i.e. Qt5Core.lib is the import library for Qt5Core.dll. This way I definitely can build my app in debug mode and use Qt5Core.dll compiled in release.
                                    I can set breakpoints and step into my code and watch variables, actually I've been doing this for about 7 years on this same application.
                                    I still don't get why it does work with QVariantMap, and doesn't with QVariantList....there must be some other reason, imho.

                                    JonBJ 1 Reply Last reply
                                    0
                                    • M Maxxximo

                                      @Christian-Ehrlicher Ok, just to make it clear: Qt is built as a dynamic library, i.e. Qt5Core.lib is the import library for Qt5Core.dll. This way I definitely can build my app in debug mode and use Qt5Core.dll compiled in release.
                                      I can set breakpoints and step into my code and watch variables, actually I've been doing this for about 7 years on this same application.
                                      I still don't get why it does work with QVariantMap, and doesn't with QVariantList....there must be some other reason, imho.

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

                                      @Maxxximo
                                      I agree we do not know whether this is related to your issue.

                                      But this is not a question of .lib files. At runtime you are not supposed to have some parts of your code --- DLLs or not --- compiled for debug mixed with some for release, because they call for two incompatible versions of the MS runtime (MSVCRT/MSVCRTD.DLL). If you are able to compile/link only one or the other and see if this affects your problem it would be a good idea.

                                      1 Reply Last reply
                                      1
                                      • Christian EhrlicherC Offline
                                        Christian EhrlicherC Offline
                                        Christian Ehrlicher
                                        Lifetime Qt Champion
                                        wrote on last edited by Christian Ehrlicher
                                        #19

                                        As I said above - you must not mix debug and release libraries. It may work but may break suddenly due to the different msvc rntimes used. And this may also be the problem here.

                                        /edit: you can compile your app in debug mode and use release-only libraries but only when you use the same MSVC runtime -> /MD instead /MDd

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

                                        M 1 Reply Last reply
                                        3
                                        • Christian EhrlicherC Christian Ehrlicher

                                          As I said above - you must not mix debug and release libraries. It may work but may break suddenly due to the different msvc rntimes used. And this may also be the problem here.

                                          /edit: you can compile your app in debug mode and use release-only libraries but only when you use the same MSVC runtime -> /MD instead /MDd

                                          M Offline
                                          M Offline
                                          Maxxximo
                                          wrote on last edited by
                                          #20

                                          @Christian-Ehrlicher My mistake: I could not use the right runtime library switch because I had "Ignore specific default libraries" set! Now I recompiled in debug with /MT and it works! Thanks a lot.

                                          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