Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 11-Sep-16 21:19pm

1 solution

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[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900