Results 1 to 8 of 8

Thread: Qt import library - creating a QML function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2015
    Location
    West Sussex, England
    Posts
    8
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Qt import library - creating a QML function

    Hi All,

    Im probably being really dumb and staring right at the issue but can't see the solution.. I've written an import library that we use for various Qt 4.8 QML applications. I have various objects that i can instantiate inside QML without any problem e.g.

    Qt Code:
    1. Logger {
    2. id: write;
    3. name: "Main.qml";
    4. Component.onCompleted: {
    5. log("log started");
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    and as expected, have access to this "Logger" components "log" method e.g.

    Qt Code:
    1. MouseArea {
    2. anchors.fill: parent;
    3. onClicked: {
    4. write.log("Mouse area clicked)
    5. console.log(convert.time_ms_to_sec(-1));
    6. console.log(convert.time_ms_to_sec(15000));
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    This all works fine. My problem is that i now want to create some global functions inside my import library that can be called from anywhere without having to instantiate an object in every QML file. For example, i made a test function that converts milliseconds to seconds, but in order to use it i have to declare my "Conversion" object in each QML file, like..

    Qt Code:
    1. Conversion {
    2. id: convert;
    3. }
    4.  
    5. MouseArea {
    6. anchors.fill: parent;
    7. onClicked: {
    8. console.log(convert.time_ms_to_sec(15000));
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Is there a way of doing this without having to declare the "Conversion {}"?!? I want to be able to simply call convert.time_ms_to_sec(<val>) in any script that has my import.

    Thanks in advanced,

    Raab.
    Last edited by teh_raab; 15th May 2015 at 16:33.

Similar Threads

  1. Best way of creating a library in qt
    By ehnuh in forum Qt Programming
    Replies: 1
    Last Post: 24th November 2012, 16:10
  2. Delphi dll function import under QT
    By Gep in forum General Programming
    Replies: 6
    Last Post: 19th April 2011, 12:27
  3. dll build not creating import lib...
    By rickbsgu in forum Qt Tools
    Replies: 1
    Last Post: 11th August 2010, 19:45
  4. Replies: 4
    Last Post: 14th October 2009, 04:28
  5. import library linking
    By bruce1007 in forum Qt Programming
    Replies: 6
    Last Post: 19th May 2006, 10:27

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
  •  
Qt is a trademark of The Qt Company.