Results 1 to 6 of 6

Thread: How to create a component

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How to create a component

    Hello!

    I want to create a gui component to be used in Qt programming (just a subclass of QTabWidget, btw). At first thought I imagined that I just had to create an independent Qt Designer Form Class, but as soon as I saw the interface I noticed that doing so I'ld have something slighty different from what I want...

    As far as I know, if just create the .ui, the .cpp and .hpp files, I'l have to add all the 3 files to my project and then start using them. But rather I'ld like to make it more like traditional gui Qt components, even including my component in Qt Designer (more precisely, in the Designer embbed in Qt Creator).

    So how do I do this?

    Instead of creating the files and including them in the project, create them in such a way I can add my component to QtDesigner and use them in my project just by adding #include <xxx> in the appropriate place.


    I hope I was clear enough

    Thanks,

    Momergil

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to create a component

    See http://qt-project.org/doc/qt-4.8/des...getplugin.html It covers all your questions. After creating a library you can simply use #include <###> or you integrate the new class in a local Qt repository.

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

    Momergil (4th August 2013)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to create a component

    If you class does not change the resize behavior of the base class or any such fundamental change then it is often easier to just use the "promote widget" functionality in designer.

    Basically you add a QTabWidget and the promote it to you class. The generated code will then create an instance of your class instead of QTabWidget.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    Momergil (4th August 2013)

  6. #4
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to create a component

    Thanks for the link, Lykurg. I managed to do it all fine till the " Q_EXPORT_PLUGIN2" macro; the tutorial doesn't say where to put this macro (and all parts of the code where I inserted, it always returned with the same failure:
    Sem título.png
    )

    Could you please tell me how to solve this?

    Thanks,

    Momergil

    ---
    Thanks anda_skoa. I tested this solution as well, but it seems to bring the limitation that I'ld have to create a new class for each new app I develop, and that wasn't my intention
    Last edited by Momergil; 4th August 2013 at 17:46.

  7. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to create a component

    The tutorial shows you exactly where the macro goes. Did you look at the example code?

    As for your error message, we have no idea what your code actually looks like. My guess is you have not #included something you should have.

  8. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to create a component

    Quote Originally Posted by Momergil View Post
    Thanks anda_skoa. I tested this solution as well, but it seems to bring the limitation that I'ld have to create a new class for each new app I develop, and that wasn't my intention
    Not if you put it into a library.

    Cheers,
    _

Similar Threads

  1. using component's id in another QML
    By amitpatel22 in forum Qt Quick
    Replies: 2
    Last Post: 22nd May 2013, 16:01
  2. Add new QML component when binding with C++
    By alenn.masic in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2013, 15:59
  3. Software Component
    By mickey in forum General Discussion
    Replies: 0
    Last Post: 20th July 2009, 22:51
  4. Is there a QIpAddrLineEdit component ?
    By lovelypp in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2008, 14:10
  5. Is there an Led component for qt ?
    By lovelypp in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2008, 17:36

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.