Solved Dynamically exchange component implementations
-
Hi,
first of all, sorry for the confusing thread title.
As the Qt 5.8 Beta is now out, I want to try to exchange some of my own implementations with built in components. For example: Until 5.8, there wasn't a rounded button available, so I created my own
RoundedButton.qml
, but as Qt 5.8 has now aRoundButton
, I want to use that. However, as Qt5.8 is still Beta, I want to have the possibility to easily switch back to Qt 5.7, if something doesn't work.If it would be C++, I would be doing something like this in my
RoundedButton.qml
:#if QT_BUILD_VERSION > 5.7 import QtQuick.Controls 2.1 #else import QtQuick.Controls 2.0 #endif #if QT_BUILD_VERSION > 5.7 // use the RoundButton implementation from Qt 5.8 #else // use my own implementation #endif
Is that also somehow possible in QML?
-
@Schluchti
actually the QML versioning system is perfect for such cases.
Create a 2.0 version of your button. For 2.0 the minimum requirement simply is Qt 5.8 then. -
@raven-worx many thanks for your answer!
If I understand you correctly, I need to do the following:
- create a new version (2.0) of my component that depends on Qt5.8
- import version 2.0 of my component, whenever I want to use the component. If the application is built with Qt5.7, it automatically falls back to the 1.0 implementation, as the requirements are not met.
Is that correct?
And another question: How can I make my component depend on Qt5.8?
Thanks a lot!
Have a nice day,
Bernhard -
@Schluchti said in Dynamically exchange component implementations:
it automatically falls back to the 1.0 implementation, as the requirements are not met.
no, in that case you would get a QML error that the type is not available.
What are you exactly trying to do?
-
Ah, I see.
Ideally it would be great, if Qt takes care of which component is going to be used. So if I use the Qt 5.7 Kit, it would be great, if my own implementation of the
RoundedButton
is used. If I create a Qt application with the Qt 5.8 Kit, it would be great if theRoundButton
of Qt 5.8 is used. -
@Schluchti
whats the use case with switching Qt versions? -
@raven-worx My use case would be to test features of alpha/beta releases, without breaking the functionality of the existing application. I really like the idea of testing a new Qt release early, but I want to avoid that I exchange a lot of self written components with built in components and then find out that something doesn't work as expected. In that case it would be great to switch back to the stable release, without manually changing the relevant code parts. I know, that I could also accomplish this by creating a new branch of my application, but I am curious if I can accomplish this also somehow with Qt directly.
-
@Schluchti
ok when it's just for testing then you could do the switch in C++ when creating the QQmlEngine and load a 1.0 and 2.0 base file for example -
@raven-worx Many thanks, I'll look into this.