简体   繁体   English

Qt-QQuickWidget setSource无需冻结UI

[英]Qt - QQuickWidget setSource without freezing UI

Im working on a management project in which i gotta manage clients data from a database , and i have to add a map widget which shows a client's position (by fetching his coordinates from the database) .. i created a little prototype to learn how to use QML + Map Plugin because i never used them before , and i decided to use QQuickWidget to show my Map (the Map's QML was taken from Qt's examples with a few modifications) .. but im facing an issue , when i execute my program , it takes minutes to show the UI , which i assumed is related to my slow internet connection to fetch the map's data and all , but what i need here is to show the UI and eveything (execute database queries and all). 我正在管理一个项目,在该项目中,我必须从数据库中管理客户数据,而且我必须添加一个地图小部件,该部件显示客户的位置(通过从数据库中获取他的坐标)..我创建了一个小原型来学习如何使用QML + Map Plugin,因为我以前从未使用过它们,所以我决定使用QQuickWidget来显示我的地图(该地图的QML取自Qt的示例,并进行了一些修改)..但是当我执行程序时,我遇到了一个问题,显示UI需要花费几分钟,我认为这与我缓慢的互联网连接以获取地图数据及所有信息有关,但是我在这里需要显示UI和eveything(执行数据库查询等)。 So what i need is to execute the Map's widget (fetch the map) WHILE processing the UI normally so the user can select , search , delete and do whatever he wants (the map's widget would be empty because it hasnt been loaded yet) , UNTIL the map is ready to show. 所以我需要的是在正常处理UI的同时执行Map的小部件(获取地图),以便用户可以选择,搜索,删除并做任何他想做的事情(该地图的小部件将为空,因为尚未加载),直到地图已准备好显示。

Here my code: MainWindow: 这是我的代码:MainWindow:

ui->quickWidget->setSource(QUrl("qrc:/new/prefix1/main.qml"));
QObject *object = ui->quickWidget->rootObject();
object->setProperty("_title" , "Oslo");
object->setProperty("_x" , "59.93");
object->setProperty("_y" , "10.76"); 

Map's QML Script (main.qml): 地图的QML脚本(main.qml):

import QtQuick 2.0
import QtQuick.Window 2.0
import QtLocation 5.6
import QtPositioning 5.6

Item
{
    width: 512
    height: 512
    visible: true
    property var _x: 0
    property var _y: 0
    property string _title: ""

    Plugin
    {
        id: mapPlugin
        name: "osm"
    }

    Map
    {
        anchors.fill: parent
        plugin: mapPlugin
        center: QtPositioning.coordinate(_x , _y)
        zoomLevel: 15

        ListModel
        {
            id: locationModel
            ListElement {lat: 0; lon: 0; color: "blue"}
            ListElement {lat: 5; lon: 12.5; color: "green"}
            ListElement {lat: 10; lon: 25; color: "red"}
        }

        MapItemView
        {
            model: locationModel
            delegate: MapQuickItem
            {
                coordinate: QtPositioning.coordinate(_x , _y)
                anchorPoint: Qt.point(10 , 10)
                sourceItem: Column
                {
                    Image {source: "marker.png"}
                    Text {text: _title}
                }
            }
        }
    }
}

Thank you ! 谢谢 !

I've figured out that problem is caused by absence of OpenSSL libraries. 我发现问题是由于缺少OpenSSL库引起的。 You can read related topic here : 您可以在此处阅读相关主题:

Solution, that works for me: 解决方案,对我有用:

  • download .zip file from https://indy.fulgan.com/SSL/ https://indy.fulgan.com/SSL/下载.zip文件
  • extract libeay32.dll and ssleay32.dll 提取libeay32.dll和ssleay32.dll
  • copy them to qt binary folder (for example in my case \\QT\\Qt5.11.0\\5.11.0\\mingw53_32\\bin\\ ) 将它们复制到qt二进制文件夹(例如,在我的情况下\\ QT \\ Qt5.11.0 \\ 5.11.0 \\ mingw53_32 \\ bin \\)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM