PDA

View Full Version : Widgets reusability/library



Plop
19th May 2014, 15:19
Hello,
I currently have a Qt project build with Visual Studio 2008.
I developped several widgets which are composed of .ui files with a .cpp and .h for each.
I want to be able to re-use these widgets in other apps.
My question is : what's the best way to do this ? Should I turn my project into a dll which will contain only interface elements (and if so, what happens to the .ui file) ? Or should I just copy and paste them in the next project ?
Most of the behavior will stay the same, but some slight changes might occur, especially in the .ui.
Also, is it possible to connect signals to a library ?
Thank you.

Infinity
20th May 2014, 00:45
Should I turn my project into a dll which will contain only interface elements?
If you want to use these interface elements in several other projects, this might be a good idea. You can use a subdirs project to simplify the build process.


and if so, what happens to the .ui file
There are two ways of using UI files. These files can be processed at compile time using uic or at runtime using QUiLoader: http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
If you process them at compile time, the by uic generated C++ files will be compiled of course. Thus the library will contain the user interface classes.


Or should I just copy and paste them in the next project ?
Simply copying and pasting the files, makes applying changes afterwards time-consuming.


Also, is it possible to connect signals to a library ?
You can use the classes of a library in the same way as the classes of your main application. Connecting signals and slots is of course also possible.

You can also store all shared files in one common directory and add these files in the different projects (you might want to use a common pri file for that).

Plop
20th May 2014, 11:42
Thank you for your quick reply.
I started looking at QMake and subdirs project and it seems that I need .pro files in order to configure my app the way I want to.
But, as I said, I'm currently using VS2008 (infortunatly, I can't change that), and the .pro file is replaced by a .vcproj.
I read that it's possible to convert a .pro file to .vcproj, and vice versa, but will it work if I do this ?
Thanks.

Lesiok
20th May 2014, 12:47
Forget qmake and pro files. Download Visual Studio Add In (on this page (http://qt-project.org/downloads) select suitable version) and be happy working with Qt on Visual Studio. Place Your widgets in normal library (static or DLL) and work with them like any other library.

Infinity
20th May 2014, 20:18
As I recommended the use of a subdirs project, I haven't concerned that you're using Visual Studio (and not Qt Creator). I'm not so familiar with Visual Studio so I think you should forget my recommendation about the use of a qmake subdirs project.