加载资源文件时更新QT进度条 [英] Update a QT progress bar on loading od a resource file

查看:441
本文介绍了加载资源文件时更新QT进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我要在c ++中实现一个用于加载资源文件的类,同时更新进度条(最好使用Observer Design Pattern),用QT Creator实现GUI。

我不知道怎么开始......

Teorically Subject是文件,Observer是我的进度条。

i用Google搜索了很多次但是我找不到任何可以帮助我的东西。

如果你知道如何实施某些方法或者以任何方式帮助我我会很高兴。

谢谢大家都回复我。



我尝试了什么:



i必须在几天内实现这个类,对我来说非常重要。

解决方案

提供进度显示你的加载例程必须间隔更新GUI控件。这通常是通过在块中执行加载并在处理每个数据块后更新进度条来完成的。



使用Qt,信号&插槽| Qt Core 5.7 [ ^ ]是用于对象之间的通信。 QProgressBar类| Qt Widgets 5.7 [ ^ ]已经提供 setValue()插槽,以便您的加载例程可以发出信号。但这要求您的加载例程基于 QObject



另一个解决方案是使用 QEvent Class | Qt Core 5.7 [ ^ ]基于自定义事件。然后必须在 QProgressBar 派生类或包含进度条的对话框中处理此自定义事件。事件可以由任何非Qt函数发送 - 甚至可以从另一个线程发送 - 使用 QCoreApplication :: postEvent



使用 QEvent 的例子可以在我前一段时间写的答案中找到:http://www.codeproject.com/Answers/1074217/update-change-QListWidget-item-值#answer1 [ ^ ]。

Hi Everyone, i've to implement in c++ a class for load a resource file while it update a progress bar (preferibly with Observer Design Pattern) implementing a GUI with QT Creator.
I don't know how to begin..
Teorically Subject is the file, and the Observer is my Progress Bar.
i have googled so much times but i didn't find anything that could help me.
If you know how to implement some methods or help me in any way I I'll be happy.
Thanks everyone will reply me.

What I have tried:

i have to implement this class in a few days and is so much important to me have suggestions.

解决方案

To provide a progress display your loading routine must update the GUI control in intervals. This is usually done by performing the loading in blocks and update the progress bar after handling each chunk of data.

With Qt, Signals & Slots | Qt Core 5.7[^] are used for communication between objects. The QProgressBar Class | Qt Widgets 5.7[^] already provides the setValue() slot so that your loading routine can emit the signal. But that requires that your loading routine is QObject based.

Another solution is using a QEvent Class | Qt Core 5.7[^] based custom event. This custom event must then be handled in a QProgressBar derived class or the dialog that contains the progress bar. The event can be send by any non-Qt function - even from another thread - using QCoreApplication::postEvent.

An example on using QEvent can be found in an answer I wrote some time ago: http://www.codeproject.com/Answers/1074217/update-change-QListWidget-item-value#answer1[^].


这篇关于加载资源文件时更新QT进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆