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. QtCreator : rename a source file from a CMake project
Forum Update on Monday, May 27th 2025

QtCreator : rename a source file from a CMake project

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
6 Posts 4 Posters 1.4k 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.
  • K Offline
    K Offline
    Kiruahxh
    wrote on last edited by
    #1

    Hello,
    It seems that source file renaming isn't supported by QtCreator for CMake projects (on my computer the context menu entry is grayed out).
    Is it on the roadmap?
    Is there any reason to have it unsupported today while QtCreator focuses more and more on CMake?
    I see no ticket about it in the bug tracker.

    aha_1980A 1 Reply Last reply
    0
    • K Kiruahxh

      Hello,
      It seems that source file renaming isn't supported by QtCreator for CMake projects (on my computer the context menu entry is grayed out).
      Is it on the roadmap?
      Is there any reason to have it unsupported today while QtCreator focuses more and more on CMake?
      I see no ticket about it in the bug tracker.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @Kiruahxh,

      you are fully right, the CMake support is underrated, compared to e.g. qmake.

      There might be no ticket for renaming, but at least tickets for adding files to the CMake project do exist.

      The last discussion I'm aware of is this one, and the outcome was, a support from CMake side is needed to implement the CMake project file editing.

      I cannot tell if that is really the only possible solution, but I tend to agree that having support for project file handling would be nice.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      1
      • K Offline
        K Offline
        Kiruahxh
        wrote on last edited by
        #3

        For now, I only have a little project with GLOB. In my case, the menu entry "Add new" > "class" works fine.
        With a manual list of sources, I don't know if it works well too.

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

          Don't use GLOB for source file 'search' for add_executable() or add_library() - it may not work well and will for sure not work when you simply add a new source file without running cmake afterwards.

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

            Yeah I know it is not recommended. For a small project, it works fine ; and CONFIGURE_DEPENDS helps to detect new files.
            Once the project grows we will for sure list the files.

            Still, Qt not supporting file renaming is bad news.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jhuels20
              wrote on last edited by
              #6

              You can easily rename the source files that represent classes by right clicking on the class name in the header -> Refactor -> Rename Symbol Under Cursor. In the rename window at the bottom there is a "Rename 2 files" checkbox.

              After you refactor, make sure you update the CMake and run CMake to refresh the code model. Sometimes the "Rename X files" options is not available if the code model is stale.

              Nice productivity boost for me when I found this.

              I do think it should be part of the context menu under the project view though. Potentially have "Refactor -> Rename Class" in the context menu in project view.

              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