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. Does C++17 -> "std::any" conflict with QT's control class?
Forum Updated to NodeBB v4.3 + New Features

Does C++17 -> "std::any" conflict with QT's control class?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 5 Posters 1.8k 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.
  • X Offline
    X Offline
    X-Crack
    wrote on last edited by
    #1
    • Std::any var = std::make_any<QPushButton>("123123", Q_NULLPTR);
      As the example above, no matter how I write, the compiler will report an error as follows:
    1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\any(471): error C2440: "Initialization": Unable to convert from "initializer list" Is "std::any"
    1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\any(470): note: no constructor can accept source types, or constructor weights Uncertain decision
    Note: See the reference to the function template being compiled. "std::any std::make_any<QPushButton, const char(&)[7], nullptr>(const char (&)[7], nullptr &&)"
    
    • May I ask how to solve it, thank you very much for your international friends.
    aha_1980A J.HilkJ 2 Replies Last reply
    0
    • X X-Crack
      • Std::any var = std::make_any<QPushButton>("123123", Q_NULLPTR);
        As the example above, no matter how I write, the compiler will report an error as follows:
      1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\any(471): error C2440: "Initialization": Unable to convert from "initializer list" Is "std::any"
      1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\any(470): note: no constructor can accept source types, or constructor weights Uncertain decision
      Note: See the reference to the function template being compiled. "std::any std::make_any<QPushButton, const char(&)[7], nullptr>(const char (&)[7], nullptr &&)"
      
      • May I ask how to solve it, thank you very much for your international friends.
      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @X-Crack, welcome

      • which compiler is this? is it C++17 capable?
      • do you have CONFIG+=C++1z in your .pro file?

      Regards

      Qt has to stay free or it will die.

      X 1 Reply Last reply
      0
      • aha_1980A aha_1980

        Hi @X-Crack, welcome

        • which compiler is this? is it C++17 capable?
        • do you have CONFIG+=C++1z in your .pro file?

        Regards

        X Offline
        X Offline
        X-Crack
        wrote on last edited by
        #3

        @aha_1980
        My development environment:Visual Studio 2017 15.9.3
        fully supported C++17 is used.
        Sorry, forgive me for being a newcomer, only 600 seconds to post a topic.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Based on this Visual C++ Team Blog post, std::any requires a copyable type which QObject based classes are not.

          Furthermore, QPushButton doesn't have a constructor which takes an initialiser list.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          X 1 Reply Last reply
          4
          • X X-Crack
            • Std::any var = std::make_any<QPushButton>("123123", Q_NULLPTR);
              As the example above, no matter how I write, the compiler will report an error as follows:
            1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\any(471): error C2440: "Initialization": Unable to convert from "initializer list" Is "std::any"
            1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\any(470): note: no constructor can accept source types, or constructor weights Uncertain decision
            Note: See the reference to the function template being compiled. "std::any std::make_any<QPushButton, const char(&)[7], nullptr>(const char (&)[7], nullptr &&)"
            
            • May I ask how to solve it, thank you very much for your international friends.
            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @X-Crack well, the template is template< class T, class... Args >

            therefore shouldn't that be

            Std::any var = std::make_any<QPushButton, QString, QObject>("123123", Q_NULLPTR);

            ?


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              Based on this Visual C++ Team Blog post, std::any requires a copyable type which QObject based classes are not.

              Furthermore, QPushButton doesn't have a constructor which takes an initialiser list.

              X Offline
              X Offline
              X-Crack
              wrote on last edited by
              #6

              @SGaist
              I understand, thank you very much.
              But I am now experiencing a new situation.
              Cause: After using the smart pointer in the standard library, the program crashed when it exited. I think it might have been "delete" twice.

              Std::unordered_map<std::string, std::shared_ptr<QObject>>

              This is what I wrote. I want to add more control classes to the map and then manage it.
              The reality is cruel, and the problems come one after another.
              I am very upset now.

              JKSHJ 1 Reply Last reply
              0
              • X X-Crack

                @SGaist
                I understand, thank you very much.
                But I am now experiencing a new situation.
                Cause: After using the smart pointer in the standard library, the program crashed when it exited. I think it might have been "delete" twice.

                Std::unordered_map<std::string, std::shared_ptr<QObject>>

                This is what I wrote. I want to add more control classes to the map and then manage it.
                The reality is cruel, and the problems come one after another.
                I am very upset now.

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                @X-Crack said in Does C++17 -> "std::any" conflict with QT's control class?:

                Cause: After using the smart pointer in the standard library, the program crashed when it exited. I think it might have been "delete" twice.

                ... std::shared_ptr<QObject>

                This is what I wrote. I want to add more control classes to the map and then manage it.

                QObject already does some automatic memory management: https://doc.qt.io/qt-5/objecttrees.html

                It is dangerous to use std::shared_ptr with QObject because double deletions can happen very easily. It is safer to store raw pointers (QObject*) in your map -- remember to delete the top-level object when you have finished.

                The reality is cruel, and the problems come one after another.
                I am very upset now.

                加油!

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                X 1 Reply Last reply
                5
                • JKSHJ JKSH

                  @X-Crack said in Does C++17 -> "std::any" conflict with QT's control class?:

                  Cause: After using the smart pointer in the standard library, the program crashed when it exited. I think it might have been "delete" twice.

                  ... std::shared_ptr<QObject>

                  This is what I wrote. I want to add more control classes to the map and then manage it.

                  QObject already does some automatic memory management: https://doc.qt.io/qt-5/objecttrees.html

                  It is dangerous to use std::shared_ptr with QObject because double deletions can happen very easily. It is safer to store raw pointers (QObject*) in your map -- remember to delete the top-level object when you have finished.

                  The reality is cruel, and the problems come one after another.
                  I am very upset now.

                  加油!

                  X Offline
                  X Offline
                  X-Crack
                  wrote on last edited by
                  #8

                  @JKSH

                  thank you very much.
                  Sincerely thank the foreign friends.
                  Although I can only rely on "GOOGLE" translation to communicate with you.
                  But some words are not standard and you can understand.
                  I have basically understood the memory and pointer characteristics in QT.

                  JKSHJ 1 Reply Last reply
                  0
                  • X X-Crack

                    @JKSH

                    thank you very much.
                    Sincerely thank the foreign friends.
                    Although I can only rely on "GOOGLE" translation to communicate with you.
                    But some words are not standard and you can understand.
                    I have basically understood the memory and pointer characteristics in QT.

                    JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #9

                    @X-Crack You're welcome. If we say something that you don't understand, just ask us to explain more.

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    X 1 Reply Last reply
                    0
                    • JKSHJ JKSH

                      @X-Crack You're welcome. If we say something that you don't understand, just ask us to explain more.

                      X Offline
                      X Offline
                      X-Crack
                      wrote on last edited by
                      #10

                      @JKSH

                      I understand, thank you.
                      I changed the way I realized the previous idea.
                      Just redesigned

                      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