2014-01-23 20 views
0

我第一次創建qtquick應用程序。我使用QtCreator 3.0,Qt5.2.0和MSVC2012。 當我編寫下面的代碼時,我收到錯誤消息。我明白它說了什麼。但如果可能的話,我想使用QtQuick 2.0而不是1.0。如何運行導入QtQuick2.0和QtQuick.Controls 1.1的應用程序

有誰知道如何解決這個錯誤? 任何幫助,將不勝感激。提前致謝。

示例代碼

[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. 

回答

2

您需要使用選項「Qt Quick Control 1.0」而不是「Qt Quick 2.0」來生成Qt Quick Application項目。它將生成QtQuick2ControlsApplicationViewer類,它不使用QQuickView,而只是QQmlComponent

+0

謝謝您的建議。它在我使用「Qt Quick Control 1.0」選項創建項目時起作用。我誤解了組件集。 –

相關問題