QSplashScreen, how to add my QWidget!

Page  
2

July 12, 2012

Andre Andre
Area 51 Engineer
6075 posts

Or just make sure you have an eventloop spinning quickly, and that you return to it regulary.

/me thinks processEvents() is evil. A sometimes nessecairy evil, but an evil nonetheless.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

July 12, 2012

Lukas Geyer Lukas Geyer
Dinosaur Breeder
2074 posts

I’m not quite sure if it is actually evil, but it usually indicates that you might be doing something evil (which requires you to use processEvents()).

But as you said, a necessary evil sometimes. A prime example beeing splash screens.

July 12, 2012

dcbasso dcbasso
Robot Herder
335 posts

Man that’s a complex task to do!
I made something like this:

  1. int main(int argc, char *argv[])
  2. {
  3.     QApplication a(argc, argv);
  4.     MainWindow w;
  5.     DialogIniciandoSistema splash(0);
  6.     splash.show();
  7.     splash.raise();
  8.     Database db(0);
  9.     QTimer::singleShot(500, &db, SLOT(init()));
  10.     QTimer::singleShot(3000, &splash, SLOT(close()));
  11.     QTimer::singleShot(3000, &w, SLOT(show()));
  12.     return a.exec();
  13. }

Well, when the “init()” is executed my animated icon on the Splash freezes!
I think that I will need user Threads!!!! Real theard…

the init() code:

  1. oid Database::init()
  2. {
  3.     if (database.open()) {
  4.         QSqlQuery query(database);
  5.         if (createTables(query))
  6.         {
  7.             if (populateTables(query))
  8.             {
  9.                 qDebug() << "Populado com sucesso.";
  10.             } else {
  11.                 qDebug() << "Erro ao popular tabelas. " << query.lastError() ;
  12.             }
  13.         } else {
  14.             qDebug() << "Erro ao criar tabelas. " << query.lastError();
  15.         }
  16.     }
  17. }
  18. QSqlDatabase Database::getDatabase()
  19. {
  20.     return this->database;
  21. }
  22. bool Database::createTables(QSqlQuery query)
  23. {
  24.     bool retorno = true;
  25.     bool temp = false;
  26.     QStringList lista = readCreateTable().split("//");
  27.     for (int i=1; i<lista.length(); i++)
  28.     {
  29.         temp = query.exec( lista[i] );
  30.         retorno &= temp;
  31.     }
  32.     return retorno;
  33. }
  34. bool Database::populateTables(QSqlQuery query)
  35. {
  36.     bool retorno = true;
  37.     bool temp = false;
  38.     QStringList lista = readPopulateTable().split("//");
  39.     for (int i=1; i<lista.length(); i++)
  40.     {
  41.         temp = query.exec( lista[i] );
  42.         if (! temp)
  43.         {
  44.             qDebug() << query.lastError() << " --> SQL: " << lista[i];
  45.         }
  46.         retorno &= temp;
  47.     }
  48.     return retorno;
  49. }
  50. QString Database::readCreateTable()
  51. {
  52.    QFile file(":/database/CreateTable.sql");
  53.    if(!file.open(QIODevice::ReadOnly))
  54.    {
  55.        qDebug() << "error opening file: " << file.error();
  56.        return "";
  57.    }
  58.    QTextStream instream(&file);
  59.    QString createTable = instream.readAll();
  60.    file.close();
  61.    return createTable;
  62. }
  63. QString Database::readPopulateTable()
  64. {
  65.    QFile file(":/database/PopulateTable.sql");
  66.    if(!file.open(QIODevice::ReadOnly))
  67.    {
  68.        qDebug() << "error opening file: " << file.error();
  69.        return "";
  70.    }
  71.    QTextStream instream(&file);
  72.    QString populateTable = instream.readAll();
  73.    file.close();
  74.    return populateTable;
  75. }

July 13, 2012

dcbasso dcbasso
Robot Herder
335 posts

I resolved using QThread, connect, QDialog!
Thanks all!

Page  
2

  ‹‹ setExtraSelections in QGraphicsTextItem      Sanity tests and Bots ››

You must log in to post a reply. Not a member yet? Register here!