PDA

View Full Version : Proper way to store personnal classes



maxilase
2nd April 2015, 14:41
Hello Qt Center !

I am kind of new to Qt but I manage to program a nice application with lots of classes subclassing QGraphicalsItems' children.

Now I want to use thoses classes in another project.
I would prefer not having to copy/paste everything and start typing all those path into que ".pro" again.

As a newbie, what would you recommend to store my classes to be reusable later ? (note that I might want to do some changes again on those classes, as my program keep evolving...)

I have hear about libraries, so that i could have some dll's ?
I also read that some people are using templates ?
I was thinking about storing all my classes into a new Qt project, but then I am not really sure how to reuse it...

Regards,
Max

yeye_olive
2nd April 2015, 14:55
You can take some of your classes and make a library out of them. Qt Creator has some templates to help you do that. If you prefer to write the .pro file manually, see http://doc.qt.io/qt-5/qmake-common-projects.html#building-a-library.

You can choose whether to make a static library, whose binary code will be included in each application binary using it, or a dynamic library (DLL), which will need to be deployed along the applications linked to it.

jefftee
2nd April 2015, 16:08
It is also typical to store your source code in some type of source code control system, like git, svn, etc. Your shared code can then be checked out in other projects as a git (or svn) subproject. You can still make changes and commit/share those changes with other projects or you can keep checked out versions different between projects if you desire.

maxilase
2nd April 2015, 16:35
Thank you very much for your answers.

I have been looking for a step by step procedure on "How to create a library out of my project" and then "how to use the created library in my new project".
But I got to say that I am struggling a bit. I never created a library before and the tutorial I have been looking at are pretty complicated...

I was thinking about including my project as a subproject in my new project. Is that having any chance to work ? I just want to carry on my application and adapt a few changes in my class storage for time to time.

jefftee
2nd April 2015, 17:19
If by project you mean Qt *.pro projects, then yes you can do this, but your top level project needs to be a Qt subdirs project. You would organize your projects like this:

application (subdirs project)
- subproject (Qt subproject that includes a .pro and builds your dynamic or static library, tools, etc)
- src (Qt project that includes a .pro and builds your application, etc)

You can even nest subdir projects if needed:

application (subdirs project)
- libraries (subdirs project)

- library1 (Qt dynamic library project, etc)

- library2 (Qt static library project, etc)
- src (your app, etc)

Hope that helps.

maxilase
3rd April 2015, 08:58
Exactly what I was looking for, thank you !