{ Qt5.0.2/QML/QtQuick2.0/C++ } Example Projects th

2019-03-08 04:32发布

My setup is Qt5.0.2 MinGW 32-bit.

I am looking for { Qt5.0.2 / QML / QtQuick2.0 / C++ } code project examples (not Qt Quick 1.0) that have actual C++ classes or at least a main.cpp .

I ran through the web, browsed all examples I could possibly find:

but they were either old (Qt Quick 1.0) or pure QML+ QtQuick 2.0 or did not compile at all; or if they could compile, they showed me empty dialogs (for example, the "Status Shout!" in the Nokia code examples).

Any advice would be highly appreciated.

标签: c++ qt qml sample
2条回答
手持菜刀,她持情操
2楼-- · 2019-03-08 04:57

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

查看更多
霸刀☆藐视天下
3楼-- · 2019-03-08 05:07

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"
    }
}
查看更多
登录 后发表回答