{ Qt5.0.2/QML/QtQuick2.0/C++ } Example Projects that run without errors? [closed]

烈酒焚心 提交于 2019-12-02 15:18:55

There aren't really all that much detailed resources on QML, most of what is available is just short snippet examples and documentation examples. This is a problem for people who are new to programming, because such materials don't really give an idea of how to put together something that is useful in practice.

This is true even more so for QtQuick2, which is brand new, and even the documentation and many of the official examples are still incomplete. And I know from experience how frustrating it is to follow a tutorial, type everything, expect it to work, and get something unexpected, with no idea what really went wrong and how to fix it.

That being said, there are a few examples of complete, albeit trivial games, that are implemented in QtQuick1. This is not that big of an issue since QtQuick2 elements are backward compatible and the code will work with QtQuick2 with little to no modifications at all.

The official examples, while occasionally broken or incomplete, can also be of help, plus they will likely be fixed soon (it's about time):

Last but not least, QML snippets from the Qt project website wiki:

EDIT: To add another good resource for learning QML: http://qmlbook.org

A rather minimal example would be:

main.cpp

#include <QGuiApplication>
#include <QQuickView>

int main(int argc, char** argv)
{
    QGuiApplication app(argc, argv);
    QQuickView view;
    view.resize(800, 480);
    view.setResizeMode(QQuickView::SizeRootObjectToView);
    view.setSource(QUrl("qrc:///foo.qml"));
    view.show();
    return app.exec();
}

foo.qml (here bundled as resource):

import QtQuick 2.0

Rectangle {
    color: "lightsteelblue"

    Text {
        anchors.centerIn: parent
        text: "Hello"
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!