PDA

View Full Version : speed of the gif



KillGabio
12th February 2012, 04:35
Hi guys!

This is a very simple question. I have a QLabel with a QMovie that reproduces a .gif... The thing is that I dont know how to show it smoothly, I mean the gif shows perfectly but it`s like "stucking". I tried increasing the speed but that doesn`t change anything...here is my code:


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
LoadingWidget *loadwidg = new LoadingWidget ();
loadwidg->show ();
qApp->processEvents ();
QApplication::setStyle (new IconSize ());
QCoreApplication::addLibraryPath (".");
MainWindow mainWin;
ajustarPreferenciasVentanaPrincipal (&mainWin);
//----------------------------------------------------------
//-----------------CONTROLADOR------------------------------
//----------------------------------------------------------
//some not interesting code
//----------------------------------------------------------
//-----------------FIN CONTROLADOR--------------------------
//----------------------------------------------------------
if (handler >= 0 && aux ==0 && capacidad >0){
mainWin.setHandler (handler);
loadwidg->~LoadingWidget ();
mainWin.show();
return a.exec();
}else{
if (capacidad == 0){
QMessageBox::critical (0, QString ("NO MORE REGISTERS TO STORE DATA"), QString ("No quedan más registros para guardar información fiscal\n\nNo se podrá realizar ninguna operación\nrelacionada con el controlador."), QMessageBox::Ok);
}else QMessageBox::information (0, QString ("NO FISCAL PRINTER"),QString ("No se ha encontrado el controlador fiscal\nconectado, no se podrá facturar"));
mainWin.setHandler (-1);
mainWin.show ();
loadwidg->~LoadingWidget ();
return a.exec ();
}
}


And the cpp of the LoadingWidget:


LoadingWidget::LoadingWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::LoadingWidget)
{
ui->setupUi(this);
var_timer = 0;
load_gif = new QMovie (":/ImagesMilk/Iconos/zombiewalk.gif");
ui->label_gif->setMovie (load_gif);
timer = new QTimer (this);
this->setWindowFlags (Qt::Window |Qt::CustomizeWindowHint);
connect (timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start (1000);
load_gif->start ();
}

LoadingWidget::~LoadingWidget()
{
delete timer;
delete load_gif;
delete ui;
}

void LoadingWidget::update (){
var_timer = (var_timer+1) %4;
switch (var_timer){
case 0:
ui->label_text_loading->setText ("Loading");
break;
case 1:
ui->label_text_loading->setText ("Loading.");
break;
case 2:
ui->label_text_loading->setText ("Loading..");
break;
case 3:
ui->label_text_loading->setText ("Loading...");
break;
}
}

Thank you all in advance... Maybe its my slow computer, maybe its something i cant change...BTW QSplash window does not work for me, its not a solution :P

ChrisW67
12th February 2012, 22:31
Your QMovie requires an event loop to be running, or processEvents() called often enough, so that its frame timing (QTimer) can work. The timer expiry will not be processed until the next time the events are processed after the time has expired.

Also, at line 20 and 29 you directly call the destructor. This is an unusual thing to do. Normally you would just:


delete loadwidg;

to free the memory in use and let C++ look after destruction.

KillGabio
12th February 2012, 23:41
code updated thanks for pointing that out i dont know why i call that destructor because I usually just delete them :/