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. How to add existing files to a CMake project?
Forum Updated to NodeBB v4.3 + New Features

How to add existing files to a CMake project?

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
6 Posts 4 Posters 4.4k 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.
  • I Offline
    I Offline
    idlefrog
    wrote on 11 Feb 2022, 11:02 last edited by idlefrog
    #1

    Having converted to CMake. Does QtCreator allow you to add existing files to 'Sources'? This option is always greyed out from the project view context menu.
    Or should we always manually edit our CMakeLists.txt files?

    [QtCreator 4.15]

    C 1 Reply Last reply 14 Jun 2023, 16:37
    1
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 11 Feb 2022, 11:11 last edited by
      #2

      @idlefrog said in How to add exiting files to a CMake project?:

      Or should we always manually edit our CMakeLists.txt files?

      You have to add them manually. Adding them automatically isn't really possible since the list of sources can be gathered from everywhere.

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

      I 1 Reply Last reply 11 Feb 2022, 11:29
      1
      • C Christian Ehrlicher
        11 Feb 2022, 11:11

        @idlefrog said in How to add exiting files to a CMake project?:

        Or should we always manually edit our CMakeLists.txt files?

        You have to add them manually. Adding them automatically isn't really possible since the list of sources can be gathered from everywhere.

        I Offline
        I Offline
        idlefrog
        wrote on 11 Feb 2022, 11:29 last edited by
        #3

        @Christian-Ehrlicher Thank you for the help & quick response!
        Now I've just got to understand why (after converting to cmake) I get the dreaded 'undefined reference to vtable for ...'
        I did think just run 'cmake'... but no change...any ideas?
        Sorry.. am a CMake beginner!

        J 1 Reply Last reply 11 Feb 2022, 11:31
        0
        • I idlefrog
          11 Feb 2022, 11:29

          @Christian-Ehrlicher Thank you for the help & quick response!
          Now I've just got to understand why (after converting to cmake) I get the dreaded 'undefined reference to vtable for ...'
          I did think just run 'cmake'... but no change...any ideas?
          Sorry.. am a CMake beginner!

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 11 Feb 2022, 11:31 last edited by
          #4

          @idlefrog Did you set AUTOMOC as suggested here: https://cmake.org/cmake/help/latest/prop_tgt/AUTOMOC.html ?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          I 1 Reply Last reply 11 Feb 2022, 11:44
          3
          • J jsulm
            11 Feb 2022, 11:31

            @idlefrog Did you set AUTOMOC as suggested here: https://cmake.org/cmake/help/latest/prop_tgt/AUTOMOC.html ?

            I Offline
            I Offline
            idlefrog
            wrote on 11 Feb 2022, 11:44 last edited by
            #5

            @jsulm Arrr!... Yes, sorry. Sometimes its probably best stepping back & having a coffee-break, (rather than stressing and staring wildly at the screen!).
            Many thanks!

            1 Reply Last reply
            0
            • I idlefrog
              11 Feb 2022, 11:02

              Having converted to CMake. Does QtCreator allow you to add existing files to 'Sources'? This option is always greyed out from the project view context menu.
              Or should we always manually edit our CMakeLists.txt files?

              [QtCreator 4.15]

              C Offline
              C Offline
              cristian-adam
              wrote on 14 Jun 2023, 16:37 last edited by
              #6

              Qt Creator 11 will add the source files to the CMakeLists.txt. See below an example of a Widgets application:

              alt text

              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