Evgenii Legotckoi
March 22, 2019, 9:34 p.m.

Qt - Undocumented QMake - Copying Files

Qt is quite a large framework and it constantly introduces functionality, which unfortunately either do not have time to document or forget to document.

For example, besides the QQuickItem documentation, I highly recommend watching the sources, or at least the header files. Wonder how many public methods are there that are not described in the documentation, but can be successfully applied, and are very useful in a word.

But now the talk will be about copying files using the functionality that was implemented in Qt 5.6, but at the same time almost nothing is known about it.


Preamble

I already implemented copying files using QMAKE_EXTRA_TARGETS when developing an installer project on QtIFW , which is often advised in various forums.

And this is how the code for copying files looked.

  1. INSTALLER_OFFLINE = $$OUT_PWD/../../InstallerRelease/Hello.offline
  2. INSTALLER_ONLINE = $$OUT_PWD/../../InstallerRelease/Hello.online
  3.  
  4. # Set a variable that should contain the path to the data folder
  5. DESTDIR_WIN = $$PWD/packages/ru.evileg.helloinstaller/data
  6. DESTDIR_WIN ~= s,/,\\,g
  7. # We set the path from where all the application with DLLs will need to be copied
  8. PWD_WIN = $$OUT_PWD/../../HelloRelease
  9. PWD_WIN ~= s,/,\\,g
  10.  
  11. # Before assembling the installers, you must copy the files from the project's output folder along with all the DLLs to the data folder that belongs to the package you are building.
  12. copydata.commands = $(COPY_DIR) $$PWD_WIN $$DESTDIR_WIN
  13. first.depends = $(first) copydata
  14. export(first.depends)
  15. export(copydata.commands)
  16. # we set a custom build target, in which we first perform file compiling and then the rest, which follows the QMake script
  17. QMAKE_EXTRA_TARGETS += first copydata

Quite a monstrous solution, especially if you consider that the syntax of QMake itself is so-so. In addition, setting up copying files using this functionality is also a non-trivial task.

Implementation using the undocumented file_copies module

But the undocumented file_copies module makes everything somewhat simpler and, in terms of setting, looks like the INSTALLS setting.

  1. # Add the file_copies module
  2. CONFIG += file_copies
  3. # Add a variable that describes the copied files.
  4. COPIES += translations
  5.  
  6. # Determine with which extension we need to copy the files and in what way they are located
  7. translations.files = $$files($$PATH_SRC_ROOT/*.qm)
  8.  
  9. # Specify the path where to copy files
  10. translations.path = $$DESTDIR

In this case, we do not need to call the build with the install argument to copy the files as needed for INSTALLS.

That is, we can copy, for example, translation files into the build directory of an exe file to check if the translations work correctly, or something else like that, without full application deployment.

Notes

If desired, you can specify the base path to be trimmed from the source path.

  1. translations.base = $$PWD/target_path

Copying one file did not work, that is, if you write like this

  1. translations.files = $$files($$PATH_SRC_ROOT/application_es.qm)

That file was simply not copied. Perhaps on the most recent versions of Qt, it works stably, but with 5.9.3, on which I tested it, did not work.

Recommended articles on this topic

By article asked0question(s)

1

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
  • Last comments
  • Evgenii Legotckoi
    March 9, 2025, 9:02 p.m.
    К сожалению, я этого подсказать не могу, поскольку у меня нет необходимости в обходе блокировок и т.д. Поэтому я и не задавался решением этой проблемы. Ну выглядит так, что вам действитель…
  • VP
    March 9, 2025, 4:14 p.m.
    Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…
  • ИМ
    Nov. 22, 2024, 9:51 p.m.
    Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
  • Evgenii Legotckoi
    Oct. 31, 2024, 11:37 p.m.
    Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
  • A
    Oct. 19, 2024, 5:19 p.m.
    Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html