Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Create a plugin library of reusable QML files
Forum Updated to NodeBB v4.3 + New Features

Create a plugin library of reusable QML files

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SavageTwinky
    wrote on last edited by
    #1

    Hello, I'm having a hard time finding any specific information about sharing QML files across multiple projects. Currently we have a Common QML project that just pulls qml files in as resources.

    This works fine when you share the resource, but it requires a path to the resource and doesn't work with the syntax highlighting in qtcreator when modifying qml files.

    Is there a better way to make a shared qml library? I think I found some stuff about making a plugin, but the particular document I was reading was overriding the qttypes. It would be nice to make our own plugin or library though.

    Thanks.

    1 Reply Last reply
    1
    • C Offline
      C Offline
      chrisadams
      wrote on last edited by
      #2

      Hi,

      http://qt-project.org/doc/qt-5.0/qtqml/qtqml-modules-topic.html should be what you're looking for. In the module specification file (qmldir) you can define which QML files are exposed as types.

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SavageTwinky
        wrote on last edited by
        #3

        ok i've kind of understand whats going on, i found the plugins project, but I have an issue with knowing all of the paths to the files.

        I think this is more of an issue with me not knowing how to set up a project, we want the qml dir in a subdirectory in some common library, and the project that imports it in another directory.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SavageTwinky
          wrote on last edited by
          #4

          To elaborate on my troubles the example .pro file

          @TEMPLATE = lib
          CONFIG += plugin
          QT += qml

          DESTDIR = imports/TimeExample
          TARGET = qmlqtimeexampleplugin

          SOURCES += plugin.cpp

          pluginfiles.files +=
          imports/TimeExample/qmldir
          imports/TimeExample/center.png
          imports/TimeExample/clock.png
          imports/TimeExample/Clock.qml
          imports/TimeExample/hour.png
          imports/TimeExample/minute.png

          qml.files = plugins.qml
          qml.path += $$[QT_INSTALL_EXAMPLES]/qml/plugins
          target.path += $$[QT_INSTALL_EXAMPLES]/qml/plugins/imports/TimeExample
          pluginfiles.path += $$[QT_INSTALL_EXAMPLES]/qml/plugins/imports/TimeExample

          INSTALLS += target qml pluginfiles@

          I'd like to be able to add the import with out having to point to all of the files, or make a common.pri in the folder that will do this. The QML_IMPORT_PATH i'm not entirely sure of what to do with either.

          Is there any good examples that have an entirely separete plugin project. Also if we have projects with c++ and qml can we make plugins that have c++ back ends?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            chrisadams
            wrote on last edited by
            #5

            I'm not entirely sure what you mean, so maybe my advice won't be useful.

            But, basically: your "QML module" will be installed to a directory (the QML import path). Your application, which imports that module, can reside wherever it likes, it just needs the correct import statement.

            For example, if in your application's QML file you have:
            @
            import com.example.components 1.0
            @

            then the QML engine will look in $QTDIR/qml/com/example/components for the module specification file ("qmldir"). You shouldn't need to include any of the paths to anything, in the .pro/.pri files of the application itself.

            To answer your final question, yes it's absolutely possible to define plugins with C++ defined types - there is a section about that in the documentation. Your plugin cpp should use qmlRegisterType (and related functions) to register the C++-defined types as QML types.

            Cheers,
            Chris.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved