Hi Peppe,

 
> Dear all,
> can someone say to me what I have to do in order to use a Qt Progress
> Bar that shows progression during the loading of dataset? I'm devoloping
> an application using OpenSG and Qt. My problem is that in my application
> I use very huge datasets (.vrlm), and OpenSG (OSG::SceneFileHandler
> class) needs more than 5 minute to load them. So I would like to update
> the Qt GUI interface during the loading (now the
> OSG::SceneFileHandler.the().read(...) method freezes my GUI, appearing
> such as a computer dead-lock) and also to use a progress bar that shows
> to the user the time remaining for the complete load of the dataset (and
> that says that the program has not blocked).


Best way to do this is to spin off an QThread (you'll
have to derivate from QThread, and implement the "run"
method...).

In "run" you load the opensg file as usual, but before that
you set a callback to get the progress:

osg::SceneFileHandler::the().setReadProgressCB(
(osg::SceneFileHandler::progresscbfp)yourClass::progressFuncCB );

Where yourClass is the derived QThread class and progressFuncCB
is a static method of this class (you'll probably need to have
access to the actual instance of yourClass, so make yourClass 
a singleton or something similar).

Don't forget to register the thread in OpenSG by calling (right at the
beginning of "run" I'd recommend).

        OSG::ExternalThread *tr;
        tr = OSG::ExternalThread::get(NULL); 
        tr->initialize (0); // 0 == OSG Aspect you want to use

Else your calls to OpenSG methods will crash


So, instead of loading the file in your main thread you start
your "loader" thread. This thread emits progress signals which you intercept
in your main qt application loop which updates your progress
bar. You'll probably do that by calling the qt signal handling
explicitly in a busy loop until the loading is done:


// spin off loader thread...
...

// intercept qt signals and update interface
while (m_bThreadActive)
        QApplication::processEvents();


Your thread should also emit a different signal when the loading
is done in order to exit from the busy loop!

I hope that doesn't sound too confusing!

Regards,

  Antonio


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to