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. Registering .pragma singleton libraries in custom plugins

Registering .pragma singleton libraries in custom plugins

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 881 Views
  • 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.
  • IzowiuzI Offline
    IzowiuzI Offline
    Izowiuz
    wrote on last edited by Izowiuz
    #1

    Hello :)

    I'm trying to change a way I register .js libraries in my custom QML plugins.
    Till now, when I wanted to make a simple .js based library, I included a path to it in my qmldir file. For example for plugin named IzLibrary I have:

    module IzLibrary
    plugin IzLibraryPlugin
    typeinfo izlibrary.qmltypes
    classname IzQMLComponents
    IzToast 1.0 qrc:///src/JS/IzToast.js
    IzMark 1.0 qrc:///src/JS/IzMark.js
    IzBusy 1.0 qrc:///src/JS/IzBusy.js
    

    Where IzMark is just:

    .pragma library
    .import QtQml 2.0 as Qml
    
    function mark(target, color) {
    	var component = Qt.createComponent("qrc:/src/QML/IzMark.qml");
    	if (component.status === Qml.Component.Ready) {
    		finishCreation(component, target, color);
    	} else {
    		component.statusChanged.connect(finishCreation(component, target, color));
    	}
    }
    
    function finishCreation(component, target, color) {
    	if (component.status === Qml.Component.Ready) {
    		var object = component.createObject(target,
    		{
    			"target": target,
    			"border.color": color
    		});
    		if (object === null) {
    			console.log("Error creating mark.");
    		}
    	} else if (component.status === Qml.Component.Error) {
    		console.log("Error loading mark:", component.errorString());
    	}
    }
    
    

    What I would like to do, is to register it like I do with .qml files in my QQmlExtensionPlugin derived classes:

    qmlRegisterType(QUrl(QStringLiteral("qrc:/src/QML/IzModalBlur.qml")), "IzLibrary", 1, 0, "IzModalBlur");
    

    Is something like that possible? I have found Simon Hausmann comment in this issue which mentions .js file and regular qmlRegisterType() function but when I do this:

    qmlRegisterType(QUrl(QStringLiteral("qrc:/src/JS/IzMark.qml")), "IzLibrary", 1, 0, "IzMark");
    

    and later call it like this:

    IzMark.mark(object, Material.color(Material.Orange));
    

    all I get is:

    WARNING   | qrc:/src/QML/Pages/TestPage.qml[49] | QML: TypeError: Property 'mark' of object [object Object] is not a function
    
    1 Reply Last reply
    0
    • IzowiuzI Offline
      IzowiuzI Offline
      Izowiuz
      wrote on last edited by
      #2

      I can't edit my post due to some Akismet.com shenanigans but of course I meant:

      qmlRegisterType(QUrl(QStringLiteral("qrc:/src/JS/IzMark.js")), "IzLibrary", 1, 0, "IzMark");
      
      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