first qml example
-
i'm just getting started with qml and qtquick.
the first example i wrote is:// main.qml import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") } // qml.qrc <RCC> <qresource prefix="/"> <file>main.qml</file> </qresource> </RCC> // main.cpp #include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }i changed
main.qmlto this and rebuild the project and no widget is showing up:import QtQuick 2.9 Rectangle { width: 360 height: 360 Text { anchors.centerIn: parent text: "Hello World" } MouseArea { anchors.fill: parent onClicked: { Qt.quit(); } } }what's the problem?
-
Hello @user4592357.
Use your Rectangle component code inside the Window component. Then fit the size of the window optionally. It should work.
you must include import QtQuick.Window 2.2 or you can use the ApplicationWindow component. Refer to Qt help to get a description of these main components.If you are a QML beginner I recommend you Qt Cadaques book. It is the best tutorial about qml.
Good luck
-
Hello @user4592357.
Use your Rectangle component code inside the Window component. Then fit the size of the window optionally. It should work.
you must include import QtQuick.Window 2.2 or you can use the ApplicationWindow component. Refer to Qt help to get a description of these main components.If you are a QML beginner I recommend you Qt Cadaques book. It is the best tutorial about qml.
Good luck
thanks. so it's like
QMainWindoworQWidget.
i'm using that book for reference, also some videos.and there's one thing that i find uncomfortable. it's that i'm doing clean build after every change in .qml file (because i use in inside .qrc ).
how else can i use the .qml file so that i don't have to rebuild every time?EDIT: found out it's not possible :( https://forum.qt.io/topic/87085/avoid-manual-rebuild-after-modifying-qml-files-in-qt-creator
-
@user4592357 Hello. I use the qml components inside .qrc too, but I had not encountered with this problem. What version of Qt, compiler and OS are you using? When I change something in my components, I only compile and the changes are included in the new compilation. Can you provide your example via Github or Gitlab?
-
Do change your data in QML document only.
QML is not used that way.
Maybe you need a fully-functional IDE source code to know how it works. -
@user4592357 Hello. I use the qml components inside .qrc too, but I had not encountered with this problem. What version of Qt, compiler and OS are you using? When I change something in my components, I only compile and the changes are included in the new compilation. Can you provide your example via Github or Gitlab?
@oria66
here's the code: https://paste.ee/p/plf9Di'm on windows, qt 5.10.0, vs2017 compiler.