Results 1 to 5 of 5

Thread: Widgets reusability/library

  1. #1
    Join Date
    May 2014
    Posts
    2
    Thanks
    1

    Default Widgets reusability/library

    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.

  2. #2
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Widgets reusability/library

    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/des...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).
    Last edited by Infinity; 20th May 2014 at 00:52.

  3. The following user says thank you to Infinity for this useful post:

    Plop (20th May 2014)

  4. #3
    Join Date
    May 2014
    Posts
    2
    Thanks
    1

    Default Re: Widgets reusability/library

    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.

  5. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Widgets reusability/library

    Forget qmake and pro files. Download Visual Studio Add In (on this page 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.

  6. #5
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Widgets reusability/library

    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.

Similar Threads

  1. Replies: 3
    Last Post: 20th December 2012, 12:48
  2. Replies: 0
    Last Post: 30th April 2012, 15:17
  3. QSint Widgets Library
    By Sintegrial in forum Qt-based Software
    Replies: 1
    Last Post: 20th March 2011, 22:34
  4. Replies: 2
    Last Post: 19th February 2011, 11:26
  5. Replies: 5
    Last Post: 18th April 2010, 23:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.