I have two mysql connection on QMainWindow to load

i call a waiting dialog on this way:

Preload *waiter = new Preload(0,tr("Connect to host %1").arg(OneVar["dbhost1"]));
waiter->show();
/// waiter->exce();
qApp->processEvents();

/* Preload( int millisec to self close or 0 null to command close ,texttodisplay); */




if i switsch Preload to QDialog the progess bar running from 0-100 and back
just to mysql is connected .. and
i close preload

waiter->SettoClose(); and QDialog stay open ... infinite ... to wait exce int ....

if i switsch Preload to QWidget is open and close
but the progess bar stay on start and event is not processed by calling qApp->processEvents() why?






Qt Code:
  1. class Preload : public QWidget
  2. {
  3. Q_OBJECT
  4. //
  5. public:
  6. Preload( int msec , const QString tex );
  7. void SettoClose();
  8. protected:
  9. QPixmap display;
  10. QString textd;
  11. int timeemust;
  12. bool selfclose;
  13. int r_start;
  14. int r_stop;
  15. int r_status;
  16. void paintEvent(QPaintEvent *e);
  17. ////void resizeEvent( QResizeEvent * );
  18. private:
  19. signals:
  20. public slots:
  21. void Increment();
  22.  
  23.  
  24. Preload::Preload( int msec , const QString tex )
  25. {
  26. //////////QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  27. display = QPixmap(":/img/about_as_image.png");
  28. textd = tex;
  29. if (msec !=0) {
  30. selfclose = true;
  31. timeemust = msec;
  32. } else {
  33. selfclose = false;
  34. timeemust = 1200;
  35. }
  36. QRect screenSize = qApp->desktop()->availableGeometry();
  37. setWindowFlags ( Qt::Popup );
  38. ///////////qDebug() << "### screenSize -> " << screenSize;
  39. r_start = 33;
  40. r_status = r_start;
  41. r_stop = 469;
  42. ////////////display = QPixmap("test.png");
  43. QSize actual_result = display.size();
  44. resize(actual_result);
  45. qApp->processEvents();
  46. Increment();
  47. qApp->processEvents();
  48.  
  49. }
  50.  
  51. void Preload::paintEvent(QPaintEvent *e)
  52. {
  53. /////qDebug() << "### nullimage -> " << display.isNull();
  54. QColor textColor = QColor(147,147,147);
  55. QColor fillrectcolor = Qt::red;
  56. QColor shapepicture = Qt::white;
  57. QPainter painter(this);
  58. painter.setRenderHint(QPainter::Antialiasing, true);
  59. painter.drawPixmap(0,0,display);
  60. QPen pen;
  61. pen.setStyle( Qt::SolidLine );
  62. pen.setWidth( 3 );
  63. pen.setColor(fillrectcolor);
  64. painter.setPen( pen);
  65. painter.drawLine (QPoint(r_start,96),QPoint(r_status,96));
  66. pen.setWidth( 2 );
  67. pen.setColor(textColor);
  68.  
  69. QFont f( "arial", 12, QFont::Bold );
  70. painter.setFont( f );
  71. painter.setPen( pen);
  72.  
  73. QFontMetrics fm = painter.fontMetrics();
  74. int largo = fm.width(textd);
  75. painter.drawText(QPointF((display.width() / 2) - (largo / 2),118),textd);
  76.  
  77.  
  78. }
  79. void Preload::SettoClose()
  80. {
  81. selfclose = true;
  82. close();
  83. }
  84.  
  85. void Preload::Increment()
  86. {
  87.  
  88. if (r_status > r_stop) {
  89. if (selfclose) {
  90. close();
  91. return;
  92. } else {
  93. r_status = r_start;
  94. }
  95. }
  96.  
  97. int distance = r_stop - r_start;
  98. int piesesec = timeemust / distance; /* 100% */
  99. r_status = r_status + 1;
  100. update();
  101. QTimer::singleShot(piesesec, this, SLOT(Increment()));
  102. qApp->processEvents();
  103. }
To copy to clipboard, switch view to plain text mode