So, after one and a half day, i found 2 possible solutions that work which i would like to share with other newbies:
{
// embed resources into binary
// infos: http://doc.qt.io/qt-5/resources.html
Q_INIT_RESOURCE(qmlsources);
this->resize(1024, 768);
layout->setMargin(5);
layout->addWidget(topFiller);
//layout->addWidget(_infoLabel);
layout->addWidget(bottomFiller);
//this->setLayout(layout);
createActions();
createMenus();
//WORKS!!!
// uses QQmlEngine and QQuickWidget
QQmlEngine *engine = new QQmlEngine(this);
QQuickWidget *view = new QQuickWidget(engine, this);
view
->setSource
(QUrl("qrc:/test.qml"));
this->setCentralWidget(view);
/* //WORKS!!!
// uses QQuickView and QWidget
QQuickView *view = new QQuickView(QUrl("qrc:/test.qml"));
QWidget *container = QWidget::createWindowContainer(view);
this->setCentralWidget(container);
*/
}
MainWindow::MainWindow() : QMainWindow ()
{
// embed resources into binary
// infos: http://doc.qt.io/qt-5/resources.html
Q_INIT_RESOURCE(qmlsources);
this->resize(1024, 768);
QWidget *topFiller = new QWidget;
topFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QWidget *bottomFiller = new QWidget;
bottomFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(5);
layout->addWidget(topFiller);
//layout->addWidget(_infoLabel);
layout->addWidget(bottomFiller);
//this->setLayout(layout);
createActions();
createMenus();
//WORKS!!!
// uses QQmlEngine and QQuickWidget
QQmlEngine *engine = new QQmlEngine(this);
QQuickWidget *view = new QQuickWidget(engine, this);
view->setSource(QUrl("qrc:/test.qml"));
this->setCentralWidget(view);
/* //WORKS!!!
// uses QQuickView and QWidget
QQuickView *view = new QQuickView(QUrl("qrc:/test.qml"));
QWidget *container = QWidget::createWindowContainer(view);
this->setCentralWidget(container);
*/
}
To copy to clipboard, switch view to plain text mode
Since this is a library, you have to embed the qml-file in the resources otherwise the application will not find you qml-file since it is located in the directory tree of the library.
To be honest, the information are described in the documentation but hard to understand since the examples only show snippets of the code.
Bookmarks