PDA

View Full Version : Share header file between projects



davethomaspilot
1st April 2015, 00:26
What's the right way to share a header file between projects using Qt creator?

Should I add the file to BOTH projects and just leave it one or the other's directory structure?

I'm using svn. Will the file commit if I commit either project?

Thanks!

jefftee
1st April 2015, 02:21
I am assuming you have source that goes with that header you'd like to share. I would add the header/source as a subproject to both projects which would allow you to share bug fixes or checkout different versions for each project, etc.

I would not include the header file directly in both projects. If you did that, you'd have to manually keep your other project in sync if you fixed a bug, etc.

Make sense?

BTW, I switched to git years ago, it really is better IMHO, so you might want to jump on the bandwagon too!

anda_skoa
1st April 2015, 07:57
What's the right way to share a header file between projects using Qt creator?

A common approach is to have a .pri file at the location of the code you want to share and include that in your .pro file.
The .pri file then takes care of adding paths to the respective qmake variables.

Whether the code gets built into each application or is built as a library and linked to the applications is a different choice.



I'm using svn. Will the file commit if I commit either project?


SVN commits anything that is in or below the directory the commit is triggered in.
Anything outside that subtree is ignored.

Cheers,
_

davethomaspilot
1st April 2015, 12:45
By "subproject", you mean just another project?

The header file is in a completely different subdirectory? Then put that directory in the include path, or reference them with a relative path from source files in either porject?

I've heard git is better, but I can't imagine what would matter enough to bother with learning something new. Just one person is working on the source (me), so it doesn't seem worth the bother to switch.

I wasn't aware of a ".pri" file. So, I'll have to read about that.

Thanks.

jefftee
1st April 2015, 17:14
By "subproject", you mean just another project?
I mean subproject as in an external SVN subproject as described here:

http://svnbook.red-bean.com/en/1.7/svn.advanced.externals.html