Common import for all qml files
Hi all,
First.qml
Code:
import QtQuick 2.3
import QtQuick.Controls 1.4
Second.qml
Code:
import QtQuick 2.3
import QtQuick.Window 2.2
import QtQuick.Layouts 1.1
I have a lot of qml files and each file has different imports. Is it possible to have them in one location/file and import that location/file in all the qml files?
Re: Common import for all qml files
No, since there is no include mechanism that works like a code replacement preprocessor.
One could potentially implement something like that using the QQmlEngine's URL interceptor facility or generate combined files during the application's build step.
Cheers,
_
Re: Common import for all qml files
Hi anda_skoa,
Could you provide a example of how to use QQmlEngine's URL interceptor facility?
Kindly advice
Re: Common import for all qml files
You derive from https://code.woboq.org/qt5/qtdeclara...UrlInterceptor and then set it on the QQmlEngine object https://code.woboq.org/qt5/qtdeclara...UrlInterceptor
All URLs used by the engine, QML files, images, JavaScript file, pass through the interceptor.
You could use this to get the actually requested file, generate a new file that has the common imports and the rest of the original file and then return the URL to this file.
Cheers,
_