如何运行导入qtquick2.0和qtquick.controls 1.1的应用程序



i首次创建qtquick应用程序。我使用QTCreator 3.0,QT5.2.0和MSVC2012。当我编写以下代码时,我收到了错误消息。我了解它在说什么。但是,如果可能的话,我想使用qtquick 2.0而不是1.0。

有人知道如何解决错误吗?任何帮助,将不胜感激。预先感谢。

示例代码

[ main.qml ]

import QtQuick 2.0
import QtQuick.Controls 1.1
ApplicationWindow {
    width: 360
    height: 360
    menuBar:MenuBar {
        Menu {
            title: "File"
            MenuItem { text: "Open..." }
            MenuItem { text: "Close" }
        }
        Menu {
            title: "Edit"
            MenuItem { text: "Cut" }
            MenuItem { text: "Copy" }
            MenuItem { text: "Paste" }
        }
    }
    Text {
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }
    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
}

[ main.cpp ]

#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/QtQuickAppTest/main.qml"));
    viewer.showExpanded();
    return app.exec();
}

错误消息

QQuickView only supports loading of root objects that derive from QQuickItem. 
If your example is using QML 2, (such as qmlscene) and the .qml file you 
loaded has 'import QtQuick 1.0' or 'import Qt 4.7', this error will occur. 
To load files with 'import QtQuick 1.0' or 'import Qt 4.7', use the 
QDeclarativeView class in the Qt Quick 1 module. 

您需要使用选项" QT快速控制1.0"而不是" QT Quick 2.0"生成QT快速应用程序项目。它将生成QtQuick2ControlsApplicationViewer类,该类不使用QQuickView,而仅使用QQmlComponent

最新更新