[SOLVED] Opening QML file from C++
Hello Qt community.
I'm trying to open QML file from C++ with this code:
@QQmlEngine *engine = new QQmlEngine;
QQmlComponent component(engine, QUrl::fromLocalFile("form.qml"));
QObject *myObject = component.create();
QQuickItem *item = qobject_cast<QQuickItem *>(myObject);@
But window don't show.
Not that I'm a qml specialist but you are giving a relative path to your file. It's probably not where you think it is. You should rather give the absolute path to your QML file in order to load it.
Hope it helps
I think this could suit you needs "QdeclarativeComponent":http://qt-project.org/doc/qt-4.8/qdeclarativecomponent.html
EDIT : I didn't see that you usiing qt5 so ignore my post.Both are the same anyway
Your problem should be your path like SGaist already said. After compiling it won't take your QML-File to your Compilepath, even if it's declared in your .pro file. I am using a QRC for that. Just create a QRC, add your QML file into it and use the QRC path to your QML.
Path was problem.
When using absolute path code works.
Alright. Please add [solved] at the beginning of your threadtitle.