Results 1 to 3 of 3

Thread: QProgressBar and DB connection

  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QProgressBar and DB connection

    Hello!

    I am with a problem to increment the QProgressBar before starting the DB connection. Cde below

    Qt Code:
    1. void defConexao::criaArquivoConfServidor(QString host, QString porta)
    2. {
    3. funcoesDB = new bancoDados;
    4. bool retorno = true;
    5. caixaMensagens mensagem;
    6.  
    7. this->barraProgresso->setMaximum(2);
    8. this->barraProgresso->setMinimum(0);
    9. int valorProgresso = 0;
    10.  
    11. if(!DB.isOpen())
    12. {
    13. DB = funcoesDB->adicionarBancoDados(DB);
    14. valorProgresso = 1;
    15. this->barraProgresso->setValue(valorProgresso);
    16. }
    17.  
    18. if(funcoesDB->conectar(DB, host, porta))
    19. {
    20. qDebug() << "Conectou";
    21. funcoesDB->fechar(DB);
    22.  
    23. valorProgresso = 2;
    24. this->barraProgresso->setValue(valorProgresso);
    25. }
    26. else
    27. {
    28. mensagem.fecharMensagem("erro", "Banco de dados", "Não foi possÃ*vel conectar ao banco de dados");
    29. this->barraProgresso->reset();
    30. retorno = false;
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 

    The problem is that the progress bar does not set the value of the first function before it try to connect, that occurs in the second function. It sets all the values just before trying to connect. Why is that?

    Thank you a lot.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QProgressBar and DB connection

    The thread never gets a chance to process the events triggered by the value update, e.g. can't process the paint event that the progress requests.

    Only after you return from the function and subsequently return to the event loop can it process those events, which is why you are seening the last state.

    As an immediate thing you can call QCoreApplication:rocessEvents() after changing the progess value.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProgressBar and DB connection

    Thank you very much

Similar Threads

  1. How to use a QProgressbar
    By Niamita in forum Qt Programming
    Replies: 5
    Last Post: 16th March 2012, 12:05
  2. Replies: 0
    Last Post: 11th November 2011, 19:18
  3. Replies: 1
    Last Post: 2nd April 2010, 06:42
  4. QProgressBar + Mac OS X
    By THRESHE in forum Qt Programming
    Replies: 5
    Last Post: 14th December 2007, 13:41
  5. QProgressBar & 200%
    By Dmitry in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 11:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.