Results 1 to 4 of 4

Thread: Common import for all qml files

  1. #1
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Common import for all qml files

    Hi all,

    First.qml
    Qt Code:
    1. import QtQuick 2.3
    2. import QtQuick.Controls 1.4
    To copy to clipboard, switch view to plain text mode 

    Second.qml
    Qt Code:
    1. import QtQuick 2.3
    2. import QtQuick.Window 2.2
    3. import QtQuick.Layouts 1.1
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  3. #3
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

Similar Threads

  1. import all files in makefile project
    By ransh in forum Qt Tools
    Replies: 2
    Last Post: 10th November 2014, 18:21
  2. Best approach to keep a set of common functions
    By czdcriacoes in forum Newbie
    Replies: 4
    Last Post: 11th October 2012, 02:56
  3. Replies: 1
    Last Post: 27th September 2011, 06:32
  4. Common question about porting Qt3 to Qt4
    By zlatko in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2007, 10:57
  5. Common slot on some widgets [Qt3]
    By Opilki_Inside in forum Newbie
    Replies: 4
    Last Post: 27th March 2006, 14:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.