What is the best way to implement a custom widget in an application?



  • Hello,

    I was wondering what the best way to use a custom plugin in an application is? I have created a custom IP Editor plugin. I built my plugin, which created a .dll. I have added the .dll to the Qt/plugins/designer folder. In my application .pro I have include(ipeditor.pri) In my application .cpp file, I am creating the widget by doing something like:

    IPEditor *ipeditor = new IPEditor(this);
    

    I then add the widget to a layout and continue on with other parts of the project. This seems to work fine, if it's the only widget being added to the application. I seem to have crash issues if I try adding it to an application that contains pages, stacked widgets, etc. But that's another issue for another day. I was wondering if there was a better way to add a custom plugin? I've read about the UILoader, but I am confused of how that works exactly. Can anyone shed some light on this? Thanks.


  • Qt Champions 2016

    Hi
    For a designer plugin, using a .pri file is the way to go.
    But if you are not adding it via Designer, why did you make it a plugin ?

    When im not needing design time editing of a custom widget, i just use promotion.
    http://doc.qt.io/qt-4.8/designer-using-custom-widgets.html
    That way i dont have to make plugin/dll and all that stuff and can simply use the custom widget.

    If you crash with other combinations of widgets , you most likely have some sort of bug.



  • Hello @mrjj

    Adding it within the code is a requirement for testing where I work, but I also need to be able to add it via designer which is why I make it a plugin. We ultimately don't know which route the end user is going to go with it, so we give them the option.

    I will make another topic post about the crash and go ahead and mark this as solved. Thanks!


  • Qt Champions 2016

    @Sh1gs
    Just as a note.
    There is no difference adding widgets in code or adding via Designer.
    The setupUI() as seen in mainwindow ctor creates the Designer widgets as code.

    So the only true difference is handwritten versus generated from UI file.
    Also adding via Designer, gives easier translations as the translate function is generated for the user.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.