Results 1 to 8 of 8

Thread: Qml non Gui script

  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Qml non Gui script

    Hello friends,

    is there any possibility to execute a qml script with a non gui root element.



    Thanx in advance

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

    Default Re: Qml non Gui script

    QQmlEngine does not have any UI dependencies, you can instantiate any type you've registered as the top element.
    Only requirement for types is that they have QObject somewhere in their inheritance hierachy.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Qml non Gui script

    Hmm, I don´t know if I understand you correct. I think I have to explain it better:

    I have wrtitten some c++ qml plugins which I can import in qml with the import directives.

    But when I use my plugin:

    Qt Code:
    1. import QtQuick 2.2
    2. import QtQuick.Controls 1.2
    3. import MySoft.labs.Plugs 1.0
    4.  
    5. Rectangle {
    6. id: root
    7.  
    8. width: 300; height: 300
    9. color: "white"
    10.  
    11. QMyPlugin{
    12. id: oPlug
    13. }
    14. Component.onCompleted: {
    15. oPlug.execute();
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    So here I have to wrapp it with a rectangle.

    So my question in detail is, is there a qml element/container for executing non gui tasks or whatever.

    How can I register a type as top element?

    I know that I can register a type witj qmlregistertype etc., but your suggestions sounds new to me.


    Yours,

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

    Default Re: Qml non Gui script

    If your type is in a plugin, that plugin will have registered the type so you don't have to.

    How are you loading your QML?

    Cheers,
    _

  5. #5
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Qml non Gui script

    Hello,

    the registering of the plugin is done in here:

    Qt Code:
    1. class QMyPlugPlugin : public QQmlExtensionPlugin
    2. {
    3. Q_OBJECT
    4. Q_PLUGIN_METADATA(IID "com.mysoft.Qt.QMyPlugin")
    5.  
    6. public:
    7. virtual void registerTypes(const char *uri)
    8. {
    9. Q_ASSERT(QLatin1String(uri) == QLatin1String("MySoft.labs.Plugs"));
    10. qmlRegisterType<QMyPlugin>(uri,1,0,"QMyPlugin");
    11. }
    12. };
    To copy to clipboard, switch view to plain text mode 

    and I start the qml file with the qml.exe.

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

    Default Re: Qml non Gui script

    Quote Originally Posted by codeman View Post
    the registering of the plugin is done in here:
    Right. The plugin should have taken care of the registring.

    Quote Originally Posted by codeman View Post
    and I start the qml file with the qml.exe.
    Ah, I assumed you were loading that into an application of your own.

    Still, the QQmlEngine used by the "qml" runtime should still be able to runa non UI application, it even has an application type that creates a QCoreApplication.

    The following non-UI code runs fine for me
    Qt Code:
    1. import QtQml 2.0
    2.  
    3. Timer {
    4. id: timer
    5. interval: 500
    6.  
    7. onTriggered: console.log("timeout");
    8.  
    9. Component.onCompleted: timer.start()
    10. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  7. #7
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Qml non Gui script

    ok.

    You mean I could embedd it this way:

    Qt Code:
    1. import QtQml 2.0
    2. import MySoft.labs.Plugs 1.0
    3.  
    4. Timer {
    5. id: timer
    6. interval: 500
    7. QMyPlugin{
    8. id: oPlug
    9. }
    10. onTriggered: {
    11. oPlug.execute();
    12. console.log("timeout and execute");
    13. }
    14.  
    15. Component.onCompleted: timer.start()
    16. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Qml non Gui script

    Quote Originally Posted by codeman View Post
    You mean I could embedd it this way:
    No.
    I mean that TImer, being a non-UI type, works as expected. Even with -apptype core

    Cheers,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    codeman (25th July 2014)

Similar Threads

  1. script
    By wookoon in forum Newbie
    Replies: 1
    Last Post: 19th July 2010, 09:47
  2. Using QT Script...
    By minhaz in forum Newbie
    Replies: 1
    Last Post: 18th August 2009, 22:29
  3. Qt Script
    By c_srikanth1984 in forum Qt Programming
    Replies: 3
    Last Post: 9th June 2009, 10:35
  4. Can I include a script from script?
    By yycking in forum Qt Programming
    Replies: 1
    Last Post: 24th April 2009, 03:01
  5. Qt script
    By rajesh_clt3 in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 12:40

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.