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 658 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.
  • btseB Offline
    btseB Offline
    btse
    wrote on 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

    JoeCFDJ 1 Reply Last reply
    0
    • btseB btse

      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

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

      @btse add
      include <memory>

      btseB 1 Reply Last reply
      2
      • JoeCFDJ JoeCFD

        @btse add
        include <memory>

        btseB Offline
        btseB Offline
        btse
        wrote on 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

        cristian-adamC JoeCFDJ S 3 Replies Last reply
        0
        • btseB btse

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

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

          cristian-adamC Online
          cristian-adamC Online
          cristian-adam
          wrote on 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.

          btseB 1 Reply Last reply
          1
          • btseB btse

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

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

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #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
            • cristian-adamC cristian-adam

              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.

              btseB Offline
              btseB Offline
              btse
              wrote on 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
              • btseB btse has marked this topic as solved on
              • btseB btse

                @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 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

                • Login

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