Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Support std::shared_ptr<>
Forum Updated to NodeBB v4.3 + New Features

Support std::shared_ptr<>

Scheduled Pinned Locked Moved C++ Gurus
18 Posts 9 Posters 16.2k Views 1 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.
  • Y Offline
    Y Offline
    yura-vel
    wrote on last edited by
    #1

    Hello C++ Gurus! I'm new in qt programming, and have next problem.
    I have c++ library, that I want to use in qt application. This library was created in VS2010 and uses in another applications. But there is problem in qt application when I use it, because one of the imported classes contains std::shared_ptr<> member. When compiling header of this class I get next errors( build in qt-creator, Qt 4.7.4):

    ISO C++ forbids declaration of 'shared_ptr' with no type
    invalid use of '::'
    expected ';' before '<' token

    I was checked a support of std::shared_ptr directly in qt application, and got same errors.

    Is a way to support using std::shared_ptr in current or future version of qt creator?
    What you can suggest to solve this problem: build qt application with c++11x features?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Not an issue of Creator, but it seems you're missing

      @
      #include <memory>
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yura-vel
        wrote on last edited by
        #3

        Unfortunately, do not missed.
        As I said, this code builds and works fine in another application.
        I think, the problem in the compiler, and will be greate if somebody will tell me what exactly is wrong.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          std::shared_ptr is only available in compilers that support the C++ 11 standard. If it is the same compiler as the other application, it's likely that you need to enable the C++ 11 features with a compiler switch or project setting.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            yura-vel
            wrote on last edited by
            #5

            How can I enable C++ 11 features in the Creator, and its compiler? Mingw 4.4 as I think...

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              To enable C++11 support for MinGW 4.4 add <code>QMAKE_CXXFLAGS += -std=gnu++0x</code> to your .pro file.

              Be aware that you usually cannot mix different compilers resp. compiler versions. If your library is compiled using MSVC2010 you will have to use MSVC2010 for your application as well.

              1 Reply Last reply
              0
              • Y Offline
                Y Offline
                yura-vel
                wrote on last edited by
                #7

                Lukas Geyer - thanks, i'll try.
                I saw this method, but thought, that it is not native.

                Can you give a link to a really WORKING tutorial, how to create/build qt application, using VS2010.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #8

                  The same way you build applications with MinGW. Make sure you've installed the Qt libraries for MSVC2010 (using the SDK maintenance utility) and the MSVC2010 compiler itself (by either installing the Windows SDK or VisualStudio 2010, which comes with the latest version of MSVC2010) and select the MSVC2010 toolchain in Qt Creator instead of the MinGW toolchain.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    Kretikus
                    wrote on last edited by
                    #9

                    Why not use QSharedPointer instead? That will compile at least even without C++11 support...

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Sergey I.
                      wrote on last edited by
                      #10

                      I use shared_ptr in qt creator. and it works fine.
                      but qt creator doesn't recognize the identifier in the editor.
                      so no highlights, no hints.
                      I guess its because it doesn't understand what is @QMAKE_CXXFLAGS += -std=c++11@ and thereby doesn't define @__GXX_EXPERIMENTAL_CXX0X__@ in its internal parser.

                      PS I don't use QSharedPointer in this particular case because I need library w/o qt dependencies.

                      [Edit: Wrapped in @ tags to prevent incorrect formatting; mlong]

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        Sergey I.
                        wrote on last edited by
                        #11

                        oops underscores are converted to formatting ))

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          Saul
                          wrote on last edited by
                          #12

                          The syntax highlighter finds std::shared_ptr if I add

                          @DEFINES += GXX_EXPERIMENTAL_CXX0X@

                          to my .pro file.

                          I am using the latest build (2.6.0-rc), but this may still work for older builds?

                          1 Reply Last reply
                          0
                          • JKSHJ Offline
                            JKSHJ Offline
                            JKSH
                            Moderators
                            wrote on last edited by
                            #13

                            [quote author="Sergey I." date="1338983415"]qt creator doesn't recognize the identifier in the editor.
                            so no highlights, no hints.
                            I guess its because it doesn't understand what is @QMAKE_CXXFLAGS += -std=c++11@ and thereby doesn't define @__GXX_EXPERIMENTAL_CXX0X__@ in its internal parser.[/quote]

                            [quote author="Saul" date="1352166263"]The syntax highlighter finds std::shared_ptr if I add

                            @DEFINES += GXX_EXPERIMENTAL_CXX0X@

                            to my .pro file.[/quote]

                            This sounds like a bug or missing feature in Qt Creator. You can report it at https://bugreports.qt-project.org/secure/Dashboard.jspa , so that the Qt Creator team can fix it.

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

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              Saul
                              wrote on last edited by
                              #14

                              [quote author="JKSH" date="1352201290"]
                              This sounds like a bug or missing feature in Qt Creator. You can report it at https://bugreports.qt-project.org/secure/Dashboard.jspa , so that the Qt Creator team can fix it.[/quote]

                              There appears to be an existing bug report on exactly this problem, created 05/Oct/11: https://bugreports.qt-project.org/browse/QTCREATORBUG-6239

                              It also notes the same workaround to allow auto-completion to work properly. The same problem exists in the latest eclipse IDE (juno), which is why I knew the solution.

                              1 Reply Last reply
                              0
                              • T Offline
                                T Offline
                                tobias.hunger
                                wrote on last edited by
                                #15

                                Thanks for bringing that issue to my attention: I fixed that a while back and thus resolved the issue:-)

                                We do take compiler flags into account for a while now (incl. -std=Whatever) when querying the compiler for its defines. std::shared_ptr<int> is highlighted for me out of the box.

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

                                  That's strange, because I am using the latest build, 2.6.0-rc, and no highlighting of std::shared_ptr was working, even though it compiled correctly i.e. I did have -std=c++11 set. I am using Ununtu 12.10, g++ 4.7.2.

                                  ...

                                  Actually, just tested by creating a new project from template and added -std=c++11, all works, highlighting and accessing members through arrow access on the shared_ptr.

                                  Never mind, my bad.

                                  Not sure then why I had trouble when I first started my other projects (I am new to Qt Creator) -- perhaps needed to restart, or perhaps it takes a while to parse the full project to allow access to members?

                                  Thanks.

                                  1 Reply Last reply
                                  0
                                  • T Offline
                                    T Offline
                                    tobias.hunger
                                    wrote on last edited by
                                    #17

                                    Maybe it is the @DEFINES += GXX_EXPERIMENTAL_CXX0X@ workaround?

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      maximus
                                      wrote on last edited by
                                      #18

                                      sorry to revive this old post, but I'm having the same problem with
                                      std::shared_ptr

                                      the syntax is not recognized by QtCreator, alltought the code compiles fine
                                      and std::unique_ptr works fine.
                                      what is weird is if I press f2 on unique_ptr, I can see the code for shared_ptr in the same class <memory> but still the syntax is not recognized,
                                      it's kind of irritating because the indenting is all messed up whenever I used shared_ptr

                                      Using QtCreator 5.1.2 with MSVC2010


                                      Free Indoor Cycling Software - https://maximumtrainer.com

                                      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