Re: Adding a Progress bar
call update() on the widget (in your case the progressbar) to make sure your changes are updated directly.
Re: Adding a Progress bar
Either use threads for the heavy computing..
or call qApp->processEvents() from your heavy computation loop...
Re: Adding a Progress bar
Quote:
Originally Posted by
srohit24
Hi
I need a progress bar, that keeps increasing from 0% to 5% to 10% and so on till 100 is reached and in 25 seconds. A constant moving bar.
i cant make QProgreeBar update in a regular fashion but htis code will be useful for u ..
use timer ..
Code:
timer->start(5000);
connect(timer, SIGNAL(timeout()), this, SLOT(updateProgressBar()));
in update updateProgressBar slot
Code:
::updateProgressBar(){
int curVal = progressbar->value();
if(curVal == 100){
timer->stop();
return ;
}else
progressbar->setValue(curVal + 25);
}
Quote:
When the control goes inside the function, all the ui commands in there arent shown in realtime. i.e. the execution is not shown as the app has only a white screen.
can anybody help?
thanks
use separate event loop for that function .. it is blocking the user interface ..
use QThread ..
use this link
http://doc.trolltech.com/qq/qq27-responsive-guis.html
Re: Adding a Progress bar
thanks for replying guys.
I went through your link, wagmare.
I think that Waiting in a Local Event Loop or Parallel Programming method will work fine for me.
but i am not sure as to how to use it.
My programs flow is something like this
I press a button, this in turn calls the function that reads the data from the device.
the data is read from the device from 2 separate locations. 1st time its very quick.
the 2nd once takes 25 seconds.
after the reading is over, it performs some calculations and displays the result within 2 seconds.
i dont know where to and how to modify this code
Code:
QNetworkAccessManager manager;
tT.setSingleShot(true);
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
connect(&manager, SIGNAL(finished(QNetworkReply*)),
&q, SLOT(quit()));
QNetworkReply *reply = manager.get(QNetworkRequest(
QUrl("http://www.qtcentre.org")));
tT.start(5000); // 5s timeout
q.exec();
if(tT.isActive()){
// download complete
tT.stop();
} else {
// timeout
}
or
Code:
QList<QImage> images = loadImages(directory);
ThumbThread *thread = new ThumbThread;
connect(thread, SIGNAL(finished(QList<QImage>)),
this, SLOT(showThumbnails(QList<QImage>)));
thread->start(images);
it would be great if you can help.
Re: Adding a Progress bar
QThread is the much better one to use ..... because u need to wait for 25 sec ... so ur event loop will resist or block the user interface for 25 seconds freezing the GUI ..to update()
best go for QThread ... a separate event loop ...
this example does what u need exactly ....
http://doc.trolltech.com/4.5/network...uneclient.html
have a good day ....
Re: Adding a Progress bar
thanks for the promt reply mate. :)
but the whole program is way over my head.
I have a huge application now, about 600 lines of code, to redo everything is a bit tough.
Is there a simple function, using which i can get back the control for the GUI while the reading takes place in the background??
can i use the sleep command in the the reading function to get a small amount of work done?
thanks.
Re: Adding a Progress bar
Quote:
Originally Posted by
srohit24
thanks for the promt reply mate. :)
Is there a simple function, using which i can get back the control for the GUI while the reading takes place in the background??
can i use the sleep command in the the reading function to get a small amount of work done?
no sleep will do no good ... it still freeze the gui main event loop
u can use qApp->processEvents()
void QCoreApplication::processEvents ( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) [static]
Re: Adding a Progress bar
Only if u had read Post #3 a little carefully :p ;)
Re: Adding a Progress bar
Quote:
Originally Posted by
wagmare
no sleep will do no good ... it still freeze the gui main event loop
u can use qApp->processEvents()
void QCoreApplication::processEvents ( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) [static]
should i place this code in the main.cpp file? or in the class file that i am using to get the work done?
can you be more specific as to what i must do to get the freezing to go away?
Should i place the 25 seconds execution function in the above mentioned function?
Re: Adding a Progress bar
can anyone guide me as to where i should place the processevents() function so that the GUI doesnt freeze?
Re: Adding a Progress bar
Something like ..
Code:
do
{
...
// Do you stuff
qApp->processEvents(); // Call process events here..
} while ( ! 25 seconds);
Re: Adding a Progress bar
ok. thanks
i have build my app both in release and debug mode.
when i double click on the exe in release folder, i get this error
du.exe - Entry point not founf
The procedure entry point ?? 0QCoreapplicaiton @@QAE@ABV0@@Z could not be located in the dynamic link library QtCore4.dll
I have added #include <QCoreApplication> as a header in both main and the class file i have used.
the exe in the debug folder works fine.
how can i solve this?
Re: Adding a Progress bar
you may be having more than one version of Qt dlls in your system...
check your PATH variable.
also check where is QtCore4d.dll(or QtCored4.dll i dont remember whats the name) ...
make changes to your PATH and delete the old path to QtCore4.dll... and point it to the one where the debug dlls are located.. because there you will find the exact release dlls also
or u can simply check your compiler/linker flags to see the paths
Re: Adding a Progress bar
As soon as you have one Qt application on your system which requires to be in the path, the dlls of your Qt Installation are likely not to be used. Therefor you must put all necessary dlls into your binary folder.
Re: Adding a Progress bar
thanks it solved the problem.