Results 1 to 7 of 7

Thread: Understanding argument `const char * uri` of `qmlRegisterType`

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Understanding argument `const char * uri` of `qmlRegisterType`

    From: http://qt-project.org/doc/qt-4.8/dec...r1-basics.html

    Qt Code:
    1. import Charts 1.0
    2. import QtQuick 1.0
    3.  
    4. Item {
    5. width: 300; height: 200
    6.  
    7. PieChart {
    8. id: aPieChart
    9. anchors.centerIn: parent
    10. width: 100; height: 100
    11. name: "A simple pie chart"
    12. color: "red"
    13. }
    14.  
    15. Text {
    16. anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 }
    17. text: aPieChart.name
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 



    Qt Code:
    1. #include "piechart.h"
    2. #include <qdeclarative.h>
    3. #include <QDeclarativeView>
    4. #include <QApplication>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app (argc, argv);
    9.  
    10. qmlRegisterType<PieChart> ("Charts", 1, 0, "PieChart");
    11.  
    12. QDeclarativeView view;
    13. view.setSource (QUrl::fromLocalFile("app.qml"));
    14. view.show ();
    15. return app.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    Question:
    The QML file contains:
    import Charts 1.0

    That must be some special module for PieCharts drawing.
    How do I know what module should be imported for drawing "lines", "circles", etc?

    and the main.cpp contains:
    qmlRegisterType<PieChart> ("Charts", 1, 0, "PieChart");

    From: http://qt-project.org/doc/qt-5.0/qtq...mlRegisterType
    This template function registers the C++ type in the QML system with the name qmlName, in the library imported from uri having the version number composed from versionMajor and versionMinor.
    What is it about 'uri'?
    I couldn't understand that argument, Please explain.
    For example instead of Piechart, if I draw a line, then what would be uri argument?

  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: Understanding argument `const char * uri` of `qmlRegisterType`

    The uri is the module identifier, the thing you write after import in QML.

    E.g. the uri for QtQuick itself is "QtQuick", the uri for that Chart library/module seems to be "Chart".

    As you can see it is very often only a single word, but it could also be things like "com.ourcompany.OurComponents" and then the respective import would be
    Qt Code:
    1. import com.ourcompany.OurComponents 1.0
    To copy to clipboard, switch view to plain text mode 
    where 1.0 is the two numbers given at the type register call.

    So if we look at
    Qt Code:
    1. qmlRegisterType<PieChart> ("Charts", 1, 0, "PieChart");
    To copy to clipboard, switch view to plain text mode 
    we can determine the arguments as
    "Charts": name of the module
    "PieChart": name of the element
    1: major version number
    0: minor version number

    Cheers,
    _

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

    TheIndependentAquarius (20th October 2013)

  4. #3
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: Understanding argument `const char * uri` of `qmlRegisterType`

    Thanks for your response, but

    Quote Originally Posted by anda_skoa View Post
    The uri is the module identifier, the thing you write after import in QML.
    E.g. the uri for QtQuick itself is "QtQuick", the uri for that Chart library/module seems to be "Chart".
    For example, If I have to draw a "line" through "QPainter", what would be the module's name for uri argument?

  5. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Understanding argument `const char * uri` of `qmlRegisterType`

    It;s up to you -- how you name it using qmlRegisterType it's how it will have to appear in Qml's import section.
    So, for instance, you can have several classes which represent business logic, so you can give uri as "business", UI stuff you can put into "ui" uri.
    So, basically, it's like "libraries" in C++ terms.
    Last edited by spirit; 20th October 2013 at 17:15.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. The following user says thank you to spirit for this useful post:

    TheIndependentAquarius (20th October 2013)

  7. #5
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: Understanding argument `const char * uri` of `qmlRegisterType`

    Quote Originally Posted by spirit View Post
    It;s up to you -- how you name it using qmlRegisterType it's how it will appear in Qml's import section.
    So, for instance, you can have several classes which represent business logic, so you can give uri as "business", UI stuff you can put into "ui" uri.
    So, basically, it's like "libraries" in C++ terms.
    Thanks.
    I see now, you mean to say that "whatever" name we choose to register with qmlRegisterType, same will be imported in QtQuick.

  8. #6
    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: Understanding argument `const char * uri` of `qmlRegisterType`

    Quote Originally Posted by Anisha Kaul View Post
    I see now, you mean to say that "whatever" name we choose to register with qmlRegisterType, same will be imported in QtQuick.
    Yes. The first string is the name that appears after "import" the second string is the name of the element that can be used in QML.

    Cheers,
    _

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

    TheIndependentAquarius (22nd October 2013)

  10. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Understanding argument `const char * uri` of `qmlRegisterType`

    Also if you are using Qt 5.0 + , do check out this link .

    There has been lot of difference in QML between 4.8.x and 5.x . Its confusing sometimes as when you cant find classes you see on net. The examples are mostly of Qt 4.8.x on internet.

Similar Threads

  1. Passing a (char) to a (int) argument - Is it safe?
    By lgb3 in forum General Programming
    Replies: 4
    Last Post: 1st October 2011, 23:17
  2. DBus adaptor and 'const QDBusMessege &messege' argument.
    By MarekR22 in forum Qt Programming
    Replies: 2
    Last Post: 11th February 2011, 09:15
  3. Connect with const char*
    By grazyna in forum Qt Programming
    Replies: 7
    Last Post: 14th August 2009, 19:13
  4. Cast to const char *
    By brevleq in forum Qt Programming
    Replies: 3
    Last Post: 3rd January 2009, 10:39
  5. char to const char* with atof
    By mickey in forum General Programming
    Replies: 5
    Last Post: 29th February 2008, 05:10

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.