Trouble getting QML file to work
-
Hello,
I have built a C++ application that has a QDeclarativeView designed to show a QML file. Whenever I try and run the application however, I get this compiler message:
module "QtQuick" version 2.0 is not installed import QtQuick 2.0 ^
What am I doing wrong?
here is my hud.qml:
import QtQuick 2.0 Rectangle { width: 100 height: 62 opacity: 0.5 color: "red" }
here is my hud.cpp:
#include "hud.h" hud::hud(QWidget *parent) : QMainWindow(parent) { this->setAttribute( Qt::WA_TranslucentBackground ); //this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint); this->setStyleSheet( "background-color:rgba(255,255,255,0.5);" ); QDeclarativeView *hudView = new QDeclarativeView; hudView->setSource(QUrl::fromLocalFile("/Users/nick/Desktop/Development/QT dev/hud_v4/hud.qml")); hudView->setStyleSheet( "background-color:rgba(255,255,255,0.5);" ); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(hudView); this->setLayout(layout); setCentralWidget(hudView); } hud::~hud() { }
and the hud.pro:
QT += core gui QT += quick QT += declarative greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = hud_v4 TEMPLATE = app SOURCES += main.cpp\ hud.cpp HEADERS += hud.h FORMS += OTHER_FILES += \ hud.qml
Thank you!
-
QDeclarativeView is for Qt Quick 1. Use QQuickView instead.
You also seem to have made your HUD inherit a QMainWIndow -- is this intentional? I thought you wanted your HUD to display on top your your main window.
-
@nicky-j said:
Are there any plans to update QDEclarativeView for Qt Quick?
QQuickView IS the updated version of QDeclarativeView: http://doc.qt.io/qt-5/qtquick-porting-qt5.html#c-code
-
@nicky-j said:
Can QQuickView be embedded in a QMainWindow?
Yes. Use http://qt-project.org/forums/viewthread/38501/
Qt 5.3 will make it even easier with the introduction of a QQuickWidget class.
-
@nicky-j said:
oh then I may just work on the QML part right now and wait for QQuickWidget to come out to integrate it to the rest of my program. Is 5.3 coming out soon?
This is the release plan: http://qt-project.org/wiki/Qt-5.3-release
The Alpha release was scheduled for today, but the previous step was delayed by a few days.