Import Qml components from other project (old name: Cross formfactor similar UI)
-
Hello,
Note: this question could have been in "mobile" or "tools" forum as well but it is about mobile, desktop and tools.
I'm developping an application that will be used on all form factor (smartphone, tablet, desktop). I want the layout of the application to be similar on all devices, but the same will be impossible.
e.g. on a tablet or PC you could have a main view with a sidebar (think about a settings or calendar app on android/iOS), on a smartphone this would be two different views in a stack based model.
I think there are two options for this:
A) Put all bussines logic (and maybe some reusable grapical componets) in a separate library and create different apps for the different form factors.
B) Create one application and decide at runtime how to visualise the data (of course business logic can still be in separate library).The first option has the advantage of being a 'clean', 'straight forward' solution, but maintaining the different frontends, builds is more work. This is also harder for the non-tech user, on google play you regularly see two version of the same app: 'appX' and 'appX tablet edition' (now which one should he choose for his 6 inch phablet)
With the second option is easier for the user, less version to maintain for me,... But how can this be done? And what are the downsides to this (Writing the code to decide how to visualise the code is an obvious one).
Any thoughts / experiences (positive or negative) on this matter?
P.S. Recourses are limited, I work for a company that produces devices and this software is intented to display info comming from them. So the UI is rather limited but I (and I alone) have just a few weeks to complete it. But experiences on larger project is also welcome as this app is a Qt testcase for us and we may use it for larger projects in the future.
-
Well, I'm not an expert, but the first option appeals to me because it's clean.
The core is ofcourse the business logic.In my own projects I always try to separate the ui from the data. In other words, MainWindow only contains all that is necessary for the user interface.
Looking at your question, I myself would do the following:
- create the business logic
- create the views/widgets to work with the data
- create the window to layout the views/widgets, one for every device
In my opinion, although you still have to create different frontends, the last step would be the smallest and every frontend uses the same widget in a layout which is best suited for that platform.
-
Hello thanks for your opinion (I was thinking largely along the same line).
One question though to create the views/widgets would a Qt2 Extension Pluging be the rights choice?
-
I don't know what you mean with a Qt2 Extension Plugin.
Although I never worked with it myself, I have seen several projects working with pri-files, which are actually the same as pro-files. But pri-files can be included in a pro-file.
In other words, if you have three different devices, you could create four projects. One for every device and one for the business logic and views/widgets. Create a pri-file for the last project an include the pri-file in the other projects.
In QtCreater, if you change the business logic or views/widgets, by pressing Rebuild All, the packages for all devices will be recreated with the same changes. If you change something to one of the frontends, by building it you will have a changed interface while the business logic stays the same as for the other devices.
-
Hello again,
Qt Extesion Plugin is a project type in qt creator is description is: 'Creates a c++ plugin to load extensions dynamically into apllications using the QQmlEngine class."
So this sounds like what I need (for all the visual components) but if I create a Qml components in such a class I can not load it from the other projects.
The documentation on how to export a Qt Quick component in C++ is available at "Your text to link here...":http://qt-project.org/doc/qt-5/qtqml-cppintegration-definetypes.html But I have a compoment fully declared in Qml and this will not work than
-
Hello again,
Qt Extesion Plugin is a project type in qt creator is description is: 'Creates a c++ plugin to load extensions dynamically into apllications using the QQmlEngine class."
So this sounds like what I need (for all the visual components) but if I create a Qml components in such a class I can not load it from the other projects.
The documentation on how to export a Qt Quick component in C++ is available "here...":http://qt-project.org/doc/qt-5/qtqml-cppintegration-definetypes.html But I have a compoment fully declared in Qml and this will not work than.
-
Update:
I have the following projects setup in Qt creator:
-A SubDirs project: MyCrossPlatFormApp
-A Qt Quick Application project: MyPcApp
-A library project: MyLibraryProject.The subdirs project is just a easy way to link the library project to the appliction (this works as I can access business logic defined in the library.
As I would also create MyTabletApp and MyPhoneApp in the future I also want to define Qml components in the library but I can't get this to work
on the main.qml i can add the import
@import "../MyLibraryProject" as MyLib@I can than add an Item
@MyLib.MyItem{
}@With intellisense help from Qt creator (so it finds the Qml files defined in the library). Howerver when I try the run the application i get an error on that import line (../MyLibraryProject: no such directory).
This is not really surprising as this path is not correct seen from the "debug folder of my application" but how to fix this?I have added the ../MyLibraryProject to the QML_IMPORT_PATH of the MyPcApp but this doesn't help.
Please help.
-
Sorry, I don't work with QML.
Maybe in the future, but for now Widgets-only.
Succes though, seems like an interesting project.PS: Just read something about qmlregistertype, perhaps it has something to do with it.