Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating custom widgets based on constructors with parameters without default values

Creating custom widgets based on constructors with parameters without default values

Scheduled Pinned Locked Moved Unsolved General and Desktop
custom widgetsconstructorsnon-defaultinitialisationui design
17 Posts 4 Posters 6.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mrjj
    15 Sept 2018, 21:13

    Hi

    I have noticed another software development challenge for this programming interface because I came along the
    need to pass references to specific widget constructors in a hierarchy (and not only to a single widget).

    The normal solution for using RAII (https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization)
    is to avoid using Designer and construct the GUI in code. That way anything is possible.

    I am curious to know how such an approach would look like.

    The basic structure would be like (pseudo code)

        CustomWidget * CreateMyClass(QStandardItemModel &SomeModel) { 
        QUiLoader loader;
        QFile file(":/forms/myform.ui");
        file.open(QFile::ReadOnly);
        QWidget *myWidget = loader.load(&file, this);
       CustomWidget *realOne=qobject_cast<CustomWidget *>(myWidget )
       if ( ! realOne) { reportError();return nullptr;} // safety check
      realOne->setModel(SomeModel); // fixup the data
     return realOne;
    }
    
    

    My concrete use case would be “ResultsView(QStandardItemModel& sim, QWidget* parent)”.

    But to use & would demand that the model would stay alive for the lifespan of ResultsView
    and where should Creator put it? Generate some global variables ?

    Where should Creator get the Mydata from ?

    • The extra data will be passed during the usual control flow by the affected classes.
    • The development tools would need to be extended once more.

    I cannot see this be possible. You would have to register hooks for all classes
    that could specify as text templates how the constructor should look and be generated.

    The only workaround i know is to setup any models/data members after the
    setupUI() call in the constructor.

    Only option would be to default construct one …

    • Can any further software design options be considered?
    • Will parameter packs eventually become relevant here?

    I doubt such feature will be added.
    However we are a user forum and the Qt devs hang out at
    http://lists.qt-project.org/mailman/listinfo

    E Offline
    E Offline
    elfring
    wrote on 16 Sept 2018, 17:35 last edited by
    #8

    I doubt such feature will be added.

    🔮 Can improvements be achieved for the tool “user interface compiler” anyhow?

    A 1 Reply Last reply 16 Sept 2018, 17:58
    0
    • E elfring
      16 Sept 2018, 17:35

      I doubt such feature will be added.

      🔮 Can improvements be achieved for the tool “user interface compiler” anyhow?

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 16 Sept 2018, 17:58 last edited by
      #9

      @elfring

      Can improvements be achieved for the tool “user interface compiler” anyhow?

      Why not? As always with open source, you can modify it according to your need (with respect to the license, of course).

      If your improvements look reasonable for the developers, they might be added to further versions too. If you have such intentions, you should really discuss them with the developers on the Qt development mailing list.

      Regards

      Qt has to stay free or it will die.

      E 1 Reply Last reply 16 Sept 2018, 18:16
      0
      • A aha_1980
        16 Sept 2018, 17:58

        @elfring

        Can improvements be achieved for the tool “user interface compiler” anyhow?

        Why not? As always with open source, you can modify it according to your need (with respect to the license, of course).

        If your improvements look reasonable for the developers, they might be added to further versions too. If you have such intentions, you should really discuss them with the developers on the Qt development mailing list.

        Regards

        E Offline
        E Offline
        elfring
        wrote on 16 Sept 2018, 18:16 last edited by
        #10

        If your improvements look reasonable for the developers, …

        Do “Qt users” care any more for the creation of non-default-constructible widgets (including views)?

        A 1 Reply Last reply 16 Sept 2018, 18:31
        0
        • E elfring
          16 Sept 2018, 18:16

          If your improvements look reasonable for the developers, …

          Do “Qt users” care any more for the creation of non-default-constructible widgets (including views)?

          A Offline
          A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 16 Sept 2018, 18:31 last edited by
          #11

          Hi @elfring,

          Different users have different needs and write different software.

          As said by @mrjj before, all can be done in code without designer. You can even create basic dialogs in Designer and complete them in your code. You can extend Designer with own widgets. You can write your own code generator...

          So much possibilities :)

          Qt has to stay free or it will die.

          E 3 Replies Last reply 16 Sept 2018, 19:02
          1
          • A aha_1980
            16 Sept 2018, 18:31

            Hi @elfring,

            Different users have different needs and write different software.

            As said by @mrjj before, all can be done in code without designer. You can even create basic dialogs in Designer and complete them in your code. You can extend Designer with own widgets. You can write your own code generator...

            So much possibilities :)

            E Offline
            E Offline
            elfring
            wrote on 16 Sept 2018, 19:02 last edited by
            #12

            …, all can be done in code without designer.

            I would appreciate if the visual design tool can work together with available user interface compilers to get the creation of non-default-constructible widgets (including views) working in a safe and convenient way.
            Does this aspect require another update for the Qt program “uic” (or even a replacement)?

            You can even create basic dialogs in Designer and complete them in your code.

            Will any more examples be published where such approaches can be insufficient for safe application object configurations?

            1 Reply Last reply
            0
            • A aha_1980
              16 Sept 2018, 18:31

              Hi @elfring,

              Different users have different needs and write different software.

              As said by @mrjj before, all can be done in code without designer. You can even create basic dialogs in Designer and complete them in your code. You can extend Designer with own widgets. You can write your own code generator...

              So much possibilities :)

              E Offline
              E Offline
              elfring
              wrote on 17 Sept 2018, 08:38 last edited by
              #13

              You can write your own code generator...

              • Have you ever heard about concrete approaches to perform the desired data processing for Qt Designer's UI file format (or the QML file format) by a corresponding C++ class template library?
              • Will source code introspection take the handling of non-default-constructible widgets (including views) better into account then?
              1 Reply Last reply
              0
              • A aha_1980
                16 Sept 2018, 18:31

                Hi @elfring,

                Different users have different needs and write different software.

                As said by @mrjj before, all can be done in code without designer. You can even create basic dialogs in Designer and complete them in your code. You can extend Designer with own widgets. You can write your own code generator...

                So much possibilities :)

                E Offline
                E Offline
                elfring
                wrote on 19 Sept 2018, 12:30 last edited by
                #14

                …, all can be done in code without designer.

                • Can Qt users (or developers) become more interested in the support for object construction without default parameters?
                • Would you like to see extensions for data format descriptions and corresponding development tools?
                J 1 Reply Last reply 20 Sept 2018, 04:48
                0
                • E elfring
                  19 Sept 2018, 12:30

                  …, all can be done in code without designer.

                  • Can Qt users (or developers) become more interested in the support for object construction without default parameters?
                  • Would you like to see extensions for data format descriptions and corresponding development tools?
                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 20 Sept 2018, 04:48 last edited by
                  #15

                  @elfring said in Creating custom widgets based on constructors with parameters without default values:

                  Can Qt users (or developers) become more interested in the support for object construction without default parameters?

                  You should ask Qt developers ( @aha_1980 already gave you the link), not in this user forum...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  E 1 Reply Last reply 20 Sept 2018, 08:42
                  0
                  • J jsulm
                    20 Sept 2018, 04:48

                    @elfring said in Creating custom widgets based on constructors with parameters without default values:

                    Can Qt users (or developers) become more interested in the support for object construction without default parameters?

                    You should ask Qt developers ( @aha_1980 already gave you the link), not in this user forum...

                    E Offline
                    E Offline
                    elfring
                    wrote on 20 Sept 2018, 08:42 last edited by
                    #16

                    You should ask Qt developers …

                    I am curious on how the clarification will evolve for the topic “Support for object creation based on constructors with parameters without default values”.

                    M 1 Reply Last reply 20 Sept 2018, 09:37
                    0
                    • E elfring
                      20 Sept 2018, 08:42

                      You should ask Qt developers …

                      I am curious on how the clarification will evolve for the topic “Support for object creation based on constructors with parameters without default values”.

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 20 Sept 2018, 09:37 last edited by mrjj
                      #17

                      @elfring
                      Hi

                      • I am curious on how the clarification will evolve

                      Me too.
                      As what you wish for - takes a huge amount of code and forces a preconceived structure on the users
                      and its going from very complicated and involving to plain impossible in scope :)

                      In 30 years of programming, i have not seen any WYSIWYG editor that supported adding
                      unknown classes to static code generation for GUI instance construction.

                      1 Reply Last reply
                      2

                      17/17

                      20 Sept 2018, 09:37

                      • Login

                      • Login or register to search.
                      17 out of 17
                      • First post
                        17/17
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved