Hello friends,
is there any possibility to execute a qml script with a non gui root element.
Thanx in advance
Hello friends,
is there any possibility to execute a qml script with a non gui root element.
Thanx in advance
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,
_
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:
import QtQuick 2.2 import QtQuick.Controls 1.2 import MySoft.labs.Plugs 1.0 Rectangle { id: root width: 300; height: 300 color: "white" QMyPlugin{ id: oPlug } Component.onCompleted: { oPlug.execute(); } }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,
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,
_
Hello,
the registering of the plugin is done in here:
Qt Code:
class QMyPlugPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "com.mysoft.Qt.QMyPlugin") public: virtual void registerTypes(const char *uri) { qmlRegisterType<QMyPlugin>(uri,1,0,"QMyPlugin"); } };To copy to clipboard, switch view to plain text mode
and I start the qml file with the qml.exe.
Right. The plugin should have taken care of the registring.
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:
import QtQml 2.0 Timer { id: timer interval: 500 onTriggered: console.log("timeout"); Component.onCompleted: timer.start() }To copy to clipboard, switch view to plain text mode
Cheers,
_
ok.
You mean I could embedd it this way:
Qt Code:
import QtQml 2.0 import MySoft.labs.Plugs 1.0 Timer { id: timer interval: 500 QMyPlugin{ id: oPlug } onTriggered: { oPlug.execute(); console.log("timeout and execute"); } Component.onCompleted: timer.start() }To copy to clipboard, switch view to plain text mode
codeman (25th July 2014)
Bookmarks