如何运行导入 QtQuick2.0 和 QtQuick.Controls 1.1 的应用程序

     2023-02-16     145

关键词:

【中文标题】如何运行导入 QtQuick2.0 和 QtQuick.Controls 1.1 的应用程序【英文标题】:How to run an application which import QtQuick2.0 and QtQuick.Controls 1.1 【发布时间】:2014-01-23 15:07:45 【问题描述】:

我是第一次创建 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. 

【问题讨论】:

【参考方案1】:

您需要使用选项“Qt Quick Control 1.0”而不是“Qt Quick 2.0”来生成 Qt Quick Application 项目。它将生成QtQuick2ControlsApplicationViewer 类,它不使用QQuickView,而只是使用QQmlComponent

【讨论】:

感谢您的建议。当我使用选项“Qt Quick Control 1.0”创建项目时它可以工作。我误解了组件集。

如何使用 android studio 导入和运行项目

】如何使用androidstudio导入和运行项目【英文标题】:Howtoworkwithandroidstudioforimportandrunproject【发布时间】:2015-02-1514:28:12【问题描述】:我从github下载了项目,我想将它导入到androidstudio。我尝试了几次,但我无法运行它。任何人... 查看详情

运行 Sqoop 导入和导出时如何找到最佳映射器数量?

】运行Sqoop导入和导出时如何找到最佳映射器数量?【英文标题】:HowtofindoptimalnumberofmapperswhenrunningSqoopimportandexport?【发布时间】:2013-05-1722:23:53【问题描述】:我使用的是Sqoop1.4.2版和Oracle数据库。运行Sqoop命令时。比如这样:.... 查看详情

如何在 tf2 中导出、导入和运行自定义模型?

】如何在tf2中导出、导入和运行自定义模型?【英文标题】:Howtoexport,import,andruncustommodelintf2?【发布时间】:2021-12-0301:48:17【问题描述】:我正在使用tf2在虚拟数据上训练自定义文本分类模型。该模型似乎训练得很好。然后我导... 查看详情

使用 SVG 插件部署 QtQuick 2.0 应用程序

】使用SVG插件部署QtQuick2.0应用程序【英文标题】:DeployingQtQuick2.0ApplicationwithSVGPlugin【发布时间】:2013-02-1520:48:55【问题描述】:我的应用程序是使用Qt5.0.1和QtQuick2.0构建的。它在QtCreator中运行良好,但我无法正确部署它。我将... 查看详情

如何在运行 CLI 和 Apache2Handler 时将系统环境变量导入 PHP?

】如何在运行CLI和Apache2Handler时将系统环境变量导入PHP?【英文标题】:HowtogetsystemenvironmentvariablesintoPHPwhilerunningCLI&Apache2Handler?【发布时间】:2012-11-1403:03:02【问题描述】:我的系统是Ubuntu,我已经在/etc/environment中设置了我... 查看详情

如何防止多处理继承导入和全局?

】如何防止多处理继承导入和全局?【英文标题】:Howtopreventmultiprocessingfrominheritingimportsandglobals?【发布时间】:2022-01-1217:59:50【问题描述】:我在较大的代码库中使用多处理,其中一些导入语句有副作用。如何在后台进程中运... 查看详情

如何设置导入,以便在任务正常运行时气流不显示错误

】如何设置导入,以便在任务正常运行时气流不显示错误【英文标题】:HowcanIsetupimportsothatairflowdoesn\'tshowerrorswhereasthetasksarerunningproperly【发布时间】:2020-07-0710:39:39【问题描述】:我们正在GCP上使用CloudComposer在Airflow1.10.6上开发... 查看详情

如果您的项目有 dart html 导入,如何在模拟器上运行颤振

】如果您的项目有darthtml导入,如何在模拟器上运行颤振【英文标题】:Howtorunflutterontheemulatorifyouprojecthasdarthtmlimports【发布时间】:2020-10-2401:04:12【问题描述】:我正在为移动和网络应用程序使用颤振。我需要从移动应用程序和... 查看详情

如何将用户和团队导入 grafana?

】如何将用户和团队导入grafana?【英文标题】:HowcanIimportusersandteamstografana?【发布时间】:2020-05-1008:00:45【问题描述】:我正在配置grafana并在没有数据库的情况下运行它。我正在使用Terraform和Helm来执行此操作。我已经知道我可... 查看详情

运行时导入 Vue 组件的 webpack 块时如何添加授权标头

】运行时导入Vue组件的webpack块时如何添加授权标头【英文标题】:HowtoaddauthorizationheaderwhenruntimeimportwebpackchunksofVuecomponents【发布时间】:2018-09-1818:20:54【问题描述】:这个任务的目的是让知道组件地址但没有访问令牌的情况下... 查看详情

QtQuick 2.0 下拉按钮

】QtQuick2.0下拉按钮【英文标题】:QtQuick2.0Dropdownbutton【发布时间】:2013-10-2716:23:24【问题描述】:我有一个工具栏ToolBar,我希望在其上有一个下拉按钮。我尝试使用ComboBox,但按钮的大小会根据列表模型项的长度进行调整。而... 查看详情

如何安装和导入openmp通过numba使用?

】如何安装和导入openmp通过numba使用?【英文标题】:Howtoinstallandimportopenmptouseitthroughnumba?【发布时间】:2022-01-1908:42:07【问题描述】:我正在python中使用numba构建程序,我需要使用openmp作为numba线程层。我正在努力让它启动并运... 查看详情

如何在 TypeScript 中正确导出和导入模块

】如何在TypeScript中正确导出和导入模块【英文标题】:HowtoProperlyExportandImportModulesinTypeScript【发布时间】:2018-06-1006:29:40【问题描述】:注意:我知道有很多关于这个主题的帖子,而且我已经查看了很多没有成功的帖子(请参阅... 查看详情

postman——集合——执行集合——分享(导出导入)集合运行结果

...到可以在其Postman应用程序中导入的收件人。本主题描述如何导出和导入收集运行。导出运行要导出收集运行,请单击将鼠标悬停在运行上时出现的下载图标。然后,您可以将生成的JSON文件保存在任意位置。您还可以选择一个收... 查看详情

如何解决运行导入tensorflow包的python文件报错

要运行的文件名为First_TensorFlow_Project.py,在存放该文件的文件夹中,有另一个命名为string.py的文件,而string和Python原生库中的string重名。当我在终端运行First_TensorFlow_Project.py文件之后,会自动生成一个string.pyc文件,只要有这个... 查看详情

androidstudio如何导入运行项目

参考技术A1.首先打开AndroidStuio左上角file选择open2.第二步选择项目的setting.gradle文件点击ok即可注意:导入安卓项目的项目路径不能有中文 查看详情

Ember 如何运行 Angular 指令以及如何导入 Angular

】Ember如何运行Angular指令以及如何导入Angular【英文标题】:EmberHowtoRunAngularDirectiveandHowtoImportAngular【发布时间】:2017-06-0313:51:13【问题描述】:我正在尝试在Ember上使用angular-filemanager插件,但根本没有成功。我在***上发现了另一... 查看详情

如何编译 java 文件并使用 pyjnius 和 kivy 导入它们

】如何编译java文件并使用pyjnius和kivy导入它们【英文标题】:howdoIcompilejavafilesandimportthemwithpyjniuswithkivy【发布时间】:2021-08-2001:05:34【问题描述】:在运行buildozer之前,我在ga/chatme/web/WebHandler.java中放置了一个java文件。然后,我... 查看详情