Understanding argument `const char * uri` of `qmlRegisterType`
From: http://qt-project.org/doc/qt-4.8/dec...r1-basics.html
Code:
import Charts 1.0
import QtQuick 1.0
Item {
width: 300; height: 200
PieChart {
id: aPieChart
anchors.centerIn: parent
width: 100; height: 100
name: "A simple pie chart"
color: "red"
}
Text {
anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 }
text: aPieChart.name
}
}
Code:
#include "piechart.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QApplication>
int main(int argc, char *argv[])
{
qmlRegisterType<PieChart> ("Charts", 1, 0, "PieChart");
QDeclarativeView view;
view.
setSource (QUrl::fromLocalFile("app.qml"));
view.show ();
return app.exec();
}
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
Quote:
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?
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
Code:
import com.ourcompany.OurComponents 1.0
where 1.0 is the two numbers given at the type register call.
So if we look at
Code:
qmlRegisterType<PieChart> ("Charts", 1, 0, "PieChart");
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,
_
Re: Understanding argument `const char * uri` of `qmlRegisterType`
Thanks for your response, but
Quote:
Originally Posted by
anda_skoa
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?
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.
Re: Understanding argument `const char * uri` of `qmlRegisterType`
Quote:
Originally Posted by
spirit
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.
Re: Understanding argument `const char * uri` of `qmlRegisterType`
Quote:
Originally Posted by
Anisha Kaul
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,
_
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.