Creating custom widgets based on constructors with parameters without default values
-
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/listinfowrote on 16 Sept 2018, 17:35 last edited byI doubt such feature will be added.
🔮 Can improvements be achieved for the tool “user interface compiler” anyhow?
-
I doubt such feature will be added.
🔮 Can improvements be achieved for the tool “user interface compiler” anyhow?
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
-
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
wrote on 16 Sept 2018, 18:16 last edited byIf your improvements look reasonable for the developers, …
Do “Qt users” care any more for the creation of non-default-constructible widgets (including views)?
-
If your improvements look reasonable for the developers, …
Do “Qt users” care any more for the creation of non-default-constructible widgets (including views)?
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 :)
-
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 :)
wrote on 16 Sept 2018, 19:02 last edited by…, 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?
-
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 :)
wrote on 17 Sept 2018, 08:38 last edited byYou 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?
-
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 :)
wrote on 19 Sept 2018, 12:30 last edited by…, 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?
-
…, 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?
@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...
-
@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...
wrote on 20 Sept 2018, 08:42 last edited byYou 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”.
-
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”.
@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.
17/17