61

Is there a way to change a .pro , .ui and .h names if the project is done? How to do it?

4 Answers 4

43

Names for .ui, .h and .cpp files can just be changed inside Qt Creator.

The name of the .pro file is a bit more involved. The simplest is probably to copy the project, rename the .pro file, and reopen.

Qt Creator also uses its own config file, .pro.user, for changes you do in the project and build settings. You can just delete the .pro.user-file, and it'll generate a new one. If you've made changes to the settings and the build process, you can rename that file as well, but remember to read through it and check build paths etc.

Edit by anonymous: Run qmake to generate a new Makefile with updated references to the project name

3
  • thx. what about a form name and it's .h and cpp files from this .pro project
    – sunset
    Jul 29, 2011 at 14:16
  • 1
    And what about if the project is also bound to a local (and maybe remote) Git repository or other version control? Jul 1, 2015 at 23:03
  • could you please explain how to run qmake to generate a new makefile ? @gund May 13, 2017 at 8:31
19
  • Open the terminal or folder structure where the current project is stored; e.g. in Linux you may right click on .pro file and "open in terminal"
  • Close the Qt creator completely
  • Rename the containing folder also to new_name
  • Rename the old_name.pro to new_name.pro
  • Inside the new_name.pro, rename the TARGET = new_name
  • You may delete the debug & release folders of old_name project which were stored in parallel to the old_name folder
  • Restart the Qt creator; Open the project new_name.pro

This answer is inspired from this answer.

2
  • 2
    Very useful, I'd also suggest deleting the .pro.user cache files since they won't be used after changing the project's name. Jan 18, 2020 at 1:08
  • 1
    This works perfectly with QtCreator 4.8.2. Only thing to do after this is to set the default kit for the project again. Aug 24, 2020 at 20:11
2

go to folder there is your project

cp current_name.pro new_name.pro && rm current_name.pro

qt will show you warning message , ignore

with qt(open project) reopen your folder, open new_name.pro

0

This worked for me I am on Fedora 35 running QT5. Close QT then run this script. I didn't find any .pro files. and I didn't get any error messages after running this and doing the rebuild.

  #/bin/bash
  #Wed Aug 10 10:30:12 AM EDT 2022
  # how to copy a QT project to a new name
  set -x

  echo -n enter oldname
  read oldName

  echo -n enter newname
  read newName

  cp -a "$oldName" "$newName"

  mv "$newName/$oldName.pro" "$newName/$newName.pro"
  mv "$newName/$oldName.pro.user" "$newName/$newName.pro.user"

  sed -i "s/$oldName/$newName/g" "$newName/$newName.pro.user"

  echo "Now startup Qt and open existing file    $newName/$newName.pro"
  echo "and run a build all configurations"

------end of bash script------------

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.