Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt Creator does not support shared_ptr

Qt Creator does not support shared_ptr

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
7 Posts 4 Posters 647 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
    btse
    wrote on 1 Mar 2024, 14:01 last edited by
    #1

    I'm on Qt Creator 12.0.2 on MacOS 13.6.3.

    It doesn't appear that Qt Creator supports std::shared_ptr at all with regards to syntax highlighting, Follow symbol under cursor, etc.

    Am I missing something? I did a bunch of searching but couldn't find any recent issues about this. We commonly use shared_ptrs throughout our code, so it's pretty inconvenient that none of the code smarts works with shared_ptrs.

    Here's a minimal example:

    CMakeLists.txt

    cmake_minimum_required(VERSION 3.14)
    
    project(shared_ptr_demo LANGUAGES CXX)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
    
    add_executable(shared_ptr_demo
      main.cpp
    )
    target_link_libraries(shared_ptr_demo Qt${QT_VERSION_MAJOR}::Core)
    
    include(GNUInstallDirs)
    install(TARGETS shared_ptr_demo
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    
    

    main.cpp

    #include <QCoreApplication>
    #include <QDebug>
    #include <iostream>
    
    class DummyClass
    {
    public:
        int member = 1;
    };
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        std::shared_ptr<DummyClass> dumPtr = std::make_shared<DummyClass>();
        std::cerr << dumPtr->member << std::endl;
    
        return a.exec();
    }
    
    

    Here's a screenshot from my Qt Creator. Note how "member" on line 16 is not highlighted at all. All flavors of "Follow Symbol under..." and related functionality do nothing.

    ea7d90e9-7278-4916-86f4-c223fa10dee4-image.png

    Here's a screenshot when used as a plain old pointer:

    b0249fd6-bce8-4eca-98b2-ec41d8d710d5-image.png

    J 1 Reply Last reply 1 Mar 2024, 15:17
    0
    • B btse
      1 Mar 2024, 14:01

      I'm on Qt Creator 12.0.2 on MacOS 13.6.3.

      It doesn't appear that Qt Creator supports std::shared_ptr at all with regards to syntax highlighting, Follow symbol under cursor, etc.

      Am I missing something? I did a bunch of searching but couldn't find any recent issues about this. We commonly use shared_ptrs throughout our code, so it's pretty inconvenient that none of the code smarts works with shared_ptrs.

      Here's a minimal example:

      CMakeLists.txt

      cmake_minimum_required(VERSION 3.14)
      
      project(shared_ptr_demo LANGUAGES CXX)
      
      set(CMAKE_AUTOUIC ON)
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_AUTORCC ON)
      
      set(CMAKE_CXX_STANDARD 17)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
      find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
      
      add_executable(shared_ptr_demo
        main.cpp
      )
      target_link_libraries(shared_ptr_demo Qt${QT_VERSION_MAJOR}::Core)
      
      include(GNUInstallDirs)
      install(TARGETS shared_ptr_demo
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
          RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
      )
      
      

      main.cpp

      #include <QCoreApplication>
      #include <QDebug>
      #include <iostream>
      
      class DummyClass
      {
      public:
          int member = 1;
      };
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          std::shared_ptr<DummyClass> dumPtr = std::make_shared<DummyClass>();
          std::cerr << dumPtr->member << std::endl;
      
          return a.exec();
      }
      
      

      Here's a screenshot from my Qt Creator. Note how "member" on line 16 is not highlighted at all. All flavors of "Follow Symbol under..." and related functionality do nothing.

      ea7d90e9-7278-4916-86f4-c223fa10dee4-image.png

      Here's a screenshot when used as a plain old pointer:

      b0249fd6-bce8-4eca-98b2-ec41d8d710d5-image.png

      J Offline
      J Offline
      JoeCFD
      wrote on 1 Mar 2024, 15:17 last edited by
      #2

      @btse add
      include <memory>

      B 1 Reply Last reply 1 Mar 2024, 15:42
      2
      • J JoeCFD
        1 Mar 2024, 15:17

        @btse add
        include <memory>

        B Offline
        B Offline
        btse
        wrote on 1 Mar 2024, 15:42 last edited by
        #3

        @JoeCFD That makes no difference, and the minimal example compiles perfectly fine without the include.

        92b73bac-1a00-4a12-a3ea-a64c6f15feec-image.png

        C J S 3 Replies Last reply 1 Mar 2024, 15:52
        0
        • B btse
          1 Mar 2024, 15:42

          @JoeCFD That makes no difference, and the minimal example compiles perfectly fine without the include.

          92b73bac-1a00-4a12-a3ea-a64c6f15feec-image.png

          C Online
          C Online
          cristian-adam
          wrote on 1 Mar 2024, 15:52 last edited by
          #4

          See https://wiki.qt.io/Qt_Creator_Clang_Code_Model for a few tips.

          I assume clangd from Qt Creator is missing something from the system integration.

          B 1 Reply Last reply 1 Mar 2024, 16:20
          1
          • B btse
            1 Mar 2024, 15:42

            @JoeCFD That makes no difference, and the minimal example compiles perfectly fine without the include.

            92b73bac-1a00-4a12-a3ea-a64c6f15feec-image.png

            J Offline
            J Offline
            JoeCFD
            wrote on 1 Mar 2024, 15:56 last edited by JoeCFD 3 Jan 2024, 15:57
            #5

            @btse ignore these warnings if you can compile. Not all warnings make sense in Qt Creator and I have some as well.

            But pay attention to the warnings when you compile your code from command line.

            1 Reply Last reply
            0
            • C cristian-adam
              1 Mar 2024, 15:52

              See https://wiki.qt.io/Qt_Creator_Clang_Code_Model for a few tips.

              I assume clangd from Qt Creator is missing something from the system integration.

              B Offline
              B Offline
              btse
              wrote on 1 Mar 2024, 16:20 last edited by
              #6

              @cristian-adam That put me down the right path. It looks like at some point clangd was disabled from the settings (Preferences -> C++ -> Clangd : "Use clangd" was unchecked). I may have done this in previous Qt Creator versions because clangd performance was pretty bad.

              I re-checked it and it at least fixed it for my minimal example. Testing now on our larger codebase.

              Thanks!

              18d75e11-889c-489d-ab6b-f2cb8c762e44-image.png

              1 Reply Last reply
              2
              • B btse has marked this topic as solved on 1 Mar 2024, 16:30
              • B btse
                1 Mar 2024, 15:42

                @JoeCFD That makes no difference, and the minimal example compiles perfectly fine without the include.

                92b73bac-1a00-4a12-a3ea-a64c6f15feec-image.png

                S Offline
                S Offline
                SimonSchroeder
                wrote on 4 Mar 2024, 07:40 last edited by
                #7

                @btse said in Qt Creator does not support shared_ptr:

                That makes no difference, and the minimal example compiles perfectly fine without the include.

                The Microsoft compiler does not care much about some of the standard includes. However, this is not standard conforming. We use Qt because we want to compile on different platforms. Missing includes is one of the most common errors when compiling on Linux or macOS because we are developing on Windows and it does not catch these kinds of errors. You should really be including <memory> everywhere you are using shared_ptr.

                1 Reply Last reply
                2

                1/7

                1 Mar 2024, 14:01

                • Login

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