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. Importance of understanding C++ features of 11, 17, and beyond
QtWS25 Last Chance

Importance of understanding C++ features of 11, 17, and beyond

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 9 Posters 1.2k Views
  • 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.
  • B Offline
    B Offline
    brainchild
    wrote on last edited by
    #1

    Compared to the classic form of the C++, how important are the new features included in C++11 and successors, in terms of understanding how to write an application in Qt that would tend to approach general standards of code quality and best practices?

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

      @brainchild said in Importance of understanding C++ features of 11, 17, and beyond:

      Compared to the classic form of the C++, how important are the new features included in C++11 and successors

      If you're stuck with pre- C++11 nowadys then you will have a hard time to understand any new c++ code - no matter if it's in the Qt library or somewhere else. Don't understand what you want to know here...

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

      B 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        @brainchild said in Importance of understanding C++ features of 11, 17, and beyond:

        Compared to the classic form of the C++, how important are the new features included in C++11 and successors

        If you're stuck with pre- C++11 nowadys then you will have a hard time to understand any new c++ code - no matter if it's in the Qt library or somewhere else. Don't understand what you want to know here...

        B Offline
        B Offline
        brainchild
        wrote on last edited by
        #3

        @Christian-Ehrlicher

        How prominently do design patterns in Qt overlap features added in the more recent version of C++? I have understood many to be related to more flexible use of templates, and more efficient passing of references. Perhaps such constructs are less important in a typical Qt application than in certain others. Such background was the motivation for my question.

        Christian EhrlicherC 1 Reply Last reply
        0
        • B brainchild

          @Christian-Ehrlicher

          How prominently do design patterns in Qt overlap features added in the more recent version of C++? I have understood many to be related to more flexible use of templates, and more efficient passing of references. Perhaps such constructs are less important in a typical Qt application than in certain others. Such background was the motivation for my question.

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

          @brainchild said in Importance of understanding C++ features of 11, 17, and beyond:

          Perhaps such constructs are less important in a typical Qt application than in certain others

          Still don't understand what you mean - templates are used in C++ code (again - look in the sources) and also const references are no new c++11 feature and are used since Qt1 times to avoid copying data.

          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
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #5

            Qt6 requires C++17 features to build, so understanding these is essential if you are going to hack Qt itself.
            For programs using Qt nullptr, initializer lists, and lambdas in connect() calls from C++11 are quite useful.

            I do not think that Qt presently requires any of these new language features of C++17 in user code. Happy to be corrected though.

            What passes for "code quality" and "best practice" is, to some degree, in the eye of the beholder.

            B 1 Reply Last reply
            0
            • C ChrisW67

              Qt6 requires C++17 features to build, so understanding these is essential if you are going to hack Qt itself.
              For programs using Qt nullptr, initializer lists, and lambdas in connect() calls from C++11 are quite useful.

              I do not think that Qt presently requires any of these new language features of C++17 in user code. Happy to be corrected though.

              What passes for "code quality" and "best practice" is, to some degree, in the eye of the beholder.

              B Offline
              B Offline
              brainchild
              wrote on last edited by
              #6

              @ChrisW67

              First, to clarify, I am not referring to the tool chain or code compatibility.

              Some of the recent enhancements have been oriented around very abstract and perhaps obtuse problems of efficiency remaining from the early language design. An example of such an enhancement is perfect forwarding. It is necessary to be up to speed with these nuances to avoid writing code in a Qt application that peers may consider below standards?

              Christian EhrlicherC 1 Reply Last reply
              0
              • B brainchild

                @ChrisW67

                First, to clarify, I am not referring to the tool chain or code compatibility.

                Some of the recent enhancements have been oriented around very abstract and perhaps obtuse problems of efficiency remaining from the early language design. An example of such an enhancement is perfect forwarding. It is necessary to be up to speed with these nuances to avoid writing code in a Qt application that peers may consider below standards?

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

                @brainchild said in Importance of understanding C++ features of 11, 17, and beyond:

                . It is necessary to be up to speed with these nuances to avoid writing code in a Qt application that peers may consider below standards?

                It depends on your peers.
                I would expect that you understand such stuff when you want to be a c++ programmer. But this has nothing to do with Qt.
                If you don't want to use a language feature then don't use it.

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

                B 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @brainchild said in Importance of understanding C++ features of 11, 17, and beyond:

                  . It is necessary to be up to speed with these nuances to avoid writing code in a Qt application that peers may consider below standards?

                  It depends on your peers.
                  I would expect that you understand such stuff when you want to be a c++ programmer. But this has nothing to do with Qt.
                  If you don't want to use a language feature then don't use it.

                  B Offline
                  B Offline
                  brainchild
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher

                  I understand. The kind of answers I was seeking would be ones based on practical experience from writing in Qt.

                  Christian EhrlicherC JoeCFDJ 2 Replies Last reply
                  0
                  • B brainchild

                    @Christian-Ehrlicher

                    I understand. The kind of answers I was seeking would be ones based on practical experience from writing in Qt.

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

                    @brainchild said in Importance of understanding C++ features of 11, 17, and beyond:

                    The kind of answers I was seeking would be ones based on practical experience from writing in Qt.

                    ?

                    If you want to use a c++ library you should know the language features used by this library. Not that you should be able to write such stuff by your own to perfection.

                    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
                    • B brainchild

                      @Christian-Ehrlicher

                      I understand. The kind of answers I was seeking would be ones based on practical experience from writing in Qt.

                      JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by JoeCFD
                      #10

                      @brainchild Qt 6 requires only C++17 and is well behind C++ development. For example, on Ubuntu 22.04, you can mix C++20 or 23 features into your Qt app. It is up to you. I will definitely do it.

                      SGaistS 1 Reply Last reply
                      0
                      • fcarneyF Offline
                        fcarneyF Offline
                        fcarney
                        wrote on last edited by
                        #11

                        When confronted with code I don't understand in C++. I go to cppreference.com. I usually get a basic understanding of what it is supposed to be doing. Say to myself, "that is neat". Then, if it is useful, I might use that in my new code if it solves a problem. Most of the time it is a detail that I might need in specific circumstances. So the next time I might need it I usually have to look it up again to get the syntax right. But at least I know the concept of why it exists. A good example of this is forcing a class to no longer do a virtual lookup for a virtual function. I "might" need this in an embedded context. Most of the time I don't and any speedup is not worth using that feature.

                        As for basic knowledge to use with Qt. I would say at least a good familiarity with C++ 11. Being able to use and understand what templates are doing is important. Understanding the differences between Qt and std objects is important as well. Not knowing when a Qt object might detach could have performance impacts. But a lot of this you pickup as you learn both C++ and Qt.

                        C++ is a perfectly valid school of magic.

                        1 Reply Last reply
                        0
                        • mzimmersM Offline
                          mzimmersM Offline
                          mzimmers
                          wrote on last edited by
                          #12

                          @brainchild your question really has multiple answers: one for C++11, one for 17 and one for beyond. As a relatively late adopter of most programming advancements, I can vouch for the value of learning C++11. In the several Qt applications I've developed and delivered, I've relied to varying degrees on 11. I think it's safe to say that it's quite "mainstream," both as a tool for Qt programming as well as the overall coding community.

                          I can't speak authoritatively to C++17 or beyond. As a rule of thumb, though, when the Qt developers adopt a new technology, they're not doing so because it's cool -- they're doing so because in their opinions it makes for better code. I'm in no position to disagree with them.

                          1 Reply Last reply
                          0
                          • JoeCFDJ JoeCFD

                            @brainchild Qt 6 requires only C++17 and is well behind C++ development. For example, on Ubuntu 22.04, you can mix C++20 or 23 features into your Qt app. It is up to you. I will definitely do it.

                            SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @JoeCFD said in Importance of understanding C++ features of 11, 17, and beyond:

                            @brainchild Qt 6 requires only C++17 and is well behind C++ development.

                            The first part is correct, the second is plain wrong.

                            The minimal C++ standard is raised rarely so as to allow recent versions of Qt to run on older systems and as the name suggests, it's only a minimal. You can use whichever higher version of the standard your compiler supports.

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

                            1 Reply Last reply
                            1
                            • B brainchild

                              Compared to the classic form of the C++, how important are the new features included in C++11 and successors, in terms of understanding how to write an application in Qt that would tend to approach general standards of code quality and best practices?

                              W Offline
                              W Offline
                              wrosecrans
                              wrote on last edited by
                              #14

                              @brainchild If you are writing C++ software in 2022, it is probably helpful to understand C++ as it exists in 2022. I'm not sure how any other answer could really arise. There's no specific reason to write code as if it was 20 years ago unless you are doing a retrocomputing project as a hobby.

                              This answer applies broadly to all languages/frameworks/API's/libraries. You wouldn't write Python 1.X today, nor JavaScript for Netscape Navigator 3.

                              1 Reply Last reply
                              0
                              • B Offline
                                B Offline
                                brainchild
                                wrote on last edited by
                                #15

                                Thanks for the answers so far. Many have been helpful.

                                I realize it has been unhelpful that I have not provided more texture concerning the reason for asking the question.

                                One approach for building software is to write whatever works first, then fix it later. Another is to understand common pitfalls first, and then at least try to avoid ones that may be anticipated. Many experienced developers prefer the first, but many of them also have enough background in any particular language, platform, or toolchain, that they need not fear the most basic mistakes.

                                In C++, I have often found many approaches occur for the same problem, but most of the ones that work are still rejected by experts. With the recent enhancements, I think the situation is exacerbated, with so many ways, for example, to copy an object too many times, even though there is no detectable problem, because a copy looks the same as the original at runtime, and the copy operation is implicit in the language semantics.

                                It is always undesirable to write code that peers reject due to its being dated or incorrect.

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SimonSchroeder
                                  wrote on last edited by
                                  #16

                                  In todays' world you probably don't get around lambda functions, move and rvalue reference, and the for-each loop. E.g., lambda functions can be used as slots in connect statements. This is back from C++11 which is already 11 years old. You should also know about return value optimization and copy elision because this heavily influences modern code style (returning a large value object was kind of forbidden in classic C++). Maybe this is all you need to know when interfacing with Qt's API. However, most source code has a lot more code that is not Qt-specific. For all your logic and so on you should try to keep up with modern C++. For example, you should use concepts whenever you can, if you use the appropriate standard already. We are still at C++17 for now, but there are a few features of newer standards that we really would like to use. std::map::contains() and std::string::contains() would be wonderful...

                                  B 1 Reply Last reply
                                  0
                                  • S SimonSchroeder

                                    In todays' world you probably don't get around lambda functions, move and rvalue reference, and the for-each loop. E.g., lambda functions can be used as slots in connect statements. This is back from C++11 which is already 11 years old. You should also know about return value optimization and copy elision because this heavily influences modern code style (returning a large value object was kind of forbidden in classic C++). Maybe this is all you need to know when interfacing with Qt's API. However, most source code has a lot more code that is not Qt-specific. For all your logic and so on you should try to keep up with modern C++. For example, you should use concepts whenever you can, if you use the appropriate standard already. We are still at C++17 for now, but there are a few features of newer standards that we really would like to use. std::map::contains() and std::string::contains() would be wonderful...

                                    B Offline
                                    B Offline
                                    brainchild
                                    wrote on last edited by
                                    #17

                                    @SimonSchroeder

                                    Thanks. Now I have some very clear details on what to make a priority.

                                    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