Results 1 to 12 of 12

Thread: QSplashScreen Weirdness

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSplashScreen Weirdness

    I went with you're earlier suggestion of using a progress dialog. I get the file size and use that as my max value. In my line reading loop I increment the progress value with the length of the current line.

    But, if clicking around the main window during the progress dialog progression, when the progress dialog goes away and the log display dialog shows, I get some unexpected data in the table in the dialog, and when closing it, a crash. This only happens in the release version of the app, I assume that the MS IDE is handling these problems in the debug version although I get no indications of problems.

    I'm doing the file parsing in a loop in the log display dialog constructor, could this be a problem? If so, I'm not sure how else to do this using QDialog.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSplashScreen Weirdness

    I'd have to see the exact code. What you describe shouldn't happen, provided your progress dialog is modal.

  3. #3
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSplashScreen Weirdness

    UPDATE: The crashing is due to bad data (log file stored in the debug directory is good while the file in the release directory was bad). So, I'll skip the QSplashScreen for now - still has the white-out problem I mentioned in the beginning of this thread - and go with the QProgressDialog. Thanks for your time, you do a great service!

    Here is the whole bloody mess... I'm going to remove all progress dialog modifications (FramelessWindowHint, opacity, font type and color...) and see what happens. Thanks for taking the time to review this with me. I very much appreciate it.

    Doing only the following has no effect. Still get a crash if multi-clicking on the main window header.
    Qt Code:
    1. QProgressDialog progDlg( QString( "Reading %1 . . ." ).arg( LOG_FILENAME ),
    2. "Cancel", 0, nProgDlgMax, this );
    3. progDlg.setModal( true );
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. class ShowLog : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. ShowLog( QWidget* pParent = 0 );
    7. virtual ~ShowLog() {}
    8.  
    9. private:
    10. Ui::ShowLogClass ui;
    11.  
    12. QTableWidget* m_logTable;
    13. MainWin* m_pMainWin;
    14.  
    15. private slots:
    16. void on_okBtn_clicked( void ) { accept(); }
    17. void on_clearBtn_clicked( void );
    18.  
    19. };
    20.  
    21. ShowLog::ShowLog( QWidget *pParent ) : QDialog( pParent )
    22. {
    23. m_pMainWin = static_cast<MainWin*>( pParent );
    24. QDir::setCurrent( QDir::currentPath() );
    25.  
    26. QFile logFile( LOG_FILENAME );
    27.  
    28. QIODevice::OpenMode nOpenMode = QIODevice::ReadOnly | QIODevice::Text;
    29.  
    30. if ( !logFile.exists() || !logFile.open( nOpenMode ) )
    31. reject();
    32.  
    33. ui.setupUi( this );
    34.  
    35. QPalette palette = ui.centralWidget->palette();
    36. palette.setColor( ui.centralWidget->backgroundRole(), COLOR_ManageBkg );
    37. ui.centralWidget->setPalette( palette );
    38.  
    39. m_logTable = new QTableWidget( 0, 4, this );
    40.  
    41. // Layout the Show Logfile dialog
    42. QStringList sLabels;
    43. sLabels << "Source" << "Type" << "Time" << "Message";
    44.  
    45. m_logTable->setHorizontalHeaderLabels( sLabels );
    46. m_logTable->verticalHeader()->hide();
    47. m_logTable->setColumnWidth( COL0_Src, 78 );
    48. m_logTable->setColumnWidth( COL1_Type, 70 );
    49. m_logTable->setColumnWidth( COL2_Time, 130 );
    50. m_logTable->setColumnWidth( COL3_Msg, 510 );
    51. m_logTable->setMinimumWidth( 775 );
    52. // Enable sorting after the table is populated, otherwise sorting
    53. // may interfere with the insertion order
    54. m_logTable->setSortingEnabled( false );
    55.  
    56. QSize bs = ui.okBtn->sizeHint().expandedTo( ui.clearBtn->sizeHint() );
    57. ui.okBtn->setFixedSize( bs );
    58. ui.clearBtn->setFixedSize( bs );
    59. ui.okBtn->setDefault( true );
    60.  
    61. // Set the "What's This?" text for controls
    62. m_logTable->setWhatsThis( WT_LOG_TABLE );
    63. ui.okBtn->setWhatsThis( WT_OK_BTN );
    64. ui.clearBtn->setWhatsThis( WT_CLEARLOG_BTN );
    65.  
    66. QVBoxLayout *vbox = new QVBoxLayout( this );
    67. vbox->addSpacing( 10 );
    68. vbox->addWidget( m_logTable, Qt::AlignHCenter );
    69. vbox->addStretch( 0 );
    70. vbox->addSpacing( 15 );
    71.  
    72. // Add a stretch to either side of the box to keep the
    73. // button centered whenever stretching horizontally
    74. QHBoxLayout* hbox = new QHBoxLayout();
    75. hbox->addStretch();
    76. hbox->addSpacing( 100 );
    77. hbox->addWidget( ui.clearBtn );
    78. hbox->addSpacing( 60 );
    79. hbox->addWidget( ui.okBtn );
    80. hbox->addSpacing( 100 );
    81. hbox->addStretch();
    82.  
    83. vbox->addLayout( hbox );
    84. vbox->addSpacing( 7 );
    85.  
    86. resize( sizeHint() );
    87.  
    88. // Create a splash-like dialog
    89. qint64 nProgDlgMax = logFile.size();
    90. QProgressDialog progDlg( QString( "Reading %1 . . ." ).arg( LOG_FILENAME ),
    91. "Cancel", 0, nProgDlgMax, this, Qt::FramelessWindowHint );
    92. progDlg.setModal( true );
    93. progDlg.setWindowOpacity( 0.92 ); // make the dialog semi-transparent
    94. palette = progDlg.palette();
    95. palette.setColor( QPalette::WindowText, QColor( 64, 64, 64 ) );
    96. progDlg.setPalette( palette );
    97. progDlg.setFixedSize( 350, 110 );
    98. QFont font = progDlg.font();
    99. font.setBold( true );
    100. progDlg.setFont( font ); // Set the splash font to bold
    101. progDlg.setForegroundRole( QPalette::WindowText );
    102.  
    103. // Center the splash screen in the main application window
    104. progDlg.move( m_pMainWin->pos().x() +
    105. (m_pMainWin->frameGeometry().width() / 2) -
    106. (progDlg.frameGeometry().width() / 2),
    107. m_pMainWin->pos().y() +
    108. (m_pMainWin->frameGeometry().height() / 2) -
    109. (progDlg.frameGeometry().height() / 2) );
    110.  
    111. // Initialize the text stream
    112. QTextStream logStream( &logFile );
    113. QString sLine, sSrc, sType, sTime, sMsg;
    114. Qt::ItemFlags flags;
    115. int start, end, nRow = 0;
    116. int nProgDlgValue = 0;
    117.  
    118. const int nTextAlignment = Qt::AlignCenter;
    119. const int nMsgTextAlign = Qt::AlignLeft | Qt::AlignVCenter;
    120. const Qt::ItemFlags itemFlags = Qt::ItemIsEditable | Qt::ItemIsSelectable;
    121.  
    122. // Skip the header
    123. while ( (sLine = logStream.readLine())[0] == '*' )
    124. nProgDlgValue += sLine.length();
    125.  
    126. // Load the text
    127. while ( !logStream.atEnd() || !sLine.isEmpty() )
    128. {
    129. if ( sLine.isEmpty() ) // skip any empty lines
    130. {
    131. sLine = logStream.readLine();
    132. continue;
    133. }
    134.  
    135. sSrc.clear();
    136. sType.clear();
    137. sTime.clear();
    138. sMsg.clear();
    139. start = 0;
    140.  
    141. // Parse the Source
    142. end = sLine.indexOf( ' ', start, Qt::CaseSensitive );
    143. for ( int i = 0; i < 3; i++ )
    144. sSrc[i] = sLine[start + i];
    145.  
    146. if ( sSrc == "LIB" )
    147. sSrc = "Library";
    148. else if ( sSrc == "APP" )
    149. sSrc = "GCE";
    150. else if ( sSrc == "DBG" )
    151. sSrc = "Debug";
    152. else if ( sSrc == "SYS" )
    153. sSrc = "System";
    154. else if ( sSrc == "SEC" )
    155. sSrc = "Security";
    156. else
    157. sSrc = "Unknown";
    158.  
    159. start = end + 1;
    160.  
    161. // Parse the Type
    162. end = sLine.indexOf( ' ', start, Qt::CaseSensitive );
    163. for ( int i = 0; i < 3; i++ )
    164. sType[i] = sLine[start + i];
    165.  
    166. if ( sType == "INF" )
    167. sType = "Information";
    168. else if ( sType == "ERR" )
    169. sType = "Error";
    170. else if ( sType == "WRN" )
    171. sType = "Warning";
    172. else
    173. sType = "Unknown";
    174.  
    175. start = end + 1;
    176.  
    177. // Parse the Time
    178. end = sLine.indexOf( CDL_COOKIE, start, Qt::CaseSensitive );
    179. for ( int i = 0; i < 19; i++ )
    180. sTime[i] = sLine[start + i];
    181.  
    182. sTime[sTime.indexOf( ' ', 0 )] = '/'; // for year/month
    183. sTime[sTime.indexOf( ' ', 0 )] = '/'; // for month/day
    184. start = end + 4;
    185.  
    186. // Get the message
    187. sMsg = sLine.right( sLine.count() - start );
    188.  
    189. // Fill a table row
    190. m_logTable->insertRow( nRow );
    191.  
    192. // Add message source
    193. m_logTable->setItem( nRow, COL0_Src, new QTableWidgetItem( sSrc ) );
    194. m_logTable->item( nRow, COL0_Src )->setTextAlignment( nTextAlignment );
    195. // Set as read-only
    196. flags = m_logTable->item( nRow, COL0_Src )->flags();
    197. flags ^= itemFlags;
    198. m_logTable->item( nRow, COL0_Src )->setFlags( flags );
    199.  
    200. // Add message type
    201. m_logTable->setItem( nRow, COL1_Type, new QTableWidgetItem( sType ) );
    202. m_logTable->item( nRow, COL1_Type )->setTextAlignment( nTextAlignment );
    203. // Set as read-only
    204. flags = m_logTable->item( nRow, COL1_Type )->flags();
    205. flags ^= itemFlags;
    206. m_logTable->item( nRow, COL1_Type )->setFlags( flags );
    207.  
    208. // Add message time
    209. m_logTable->setItem( nRow, COL2_Time, new QTableWidgetItem( sTime ) );
    210. m_logTable->item( nRow, COL2_Time )->setTextAlignment( nTextAlignment );
    211. // Set as read-only
    212. flags = m_logTable->item( nRow, COL2_Time )->flags();
    213. flags ^= itemFlags;
    214. m_logTable->item( nRow, COL2_Time )->setFlags( flags );
    215.  
    216. // Add message
    217. m_logTable->setItem( nRow, COL3_Msg, new QTableWidgetItem( sMsg ) );
    218. m_logTable->item( nRow, COL3_Msg )->setTextAlignment( nMsgTextAlign );
    219. // Set as read-only
    220. flags = m_logTable->item( nRow, COL3_Msg )->flags();
    221. flags ^= itemFlags;
    222. m_logTable->item( nRow, COL3_Msg )->setFlags( flags );
    223.  
    224. nRow++;
    225. sLine = logStream.readLine();
    226.  
    227. // Increment progress bar
    228. progDlg.setValue( nProgDlgValue += sLine.length() );
    229. m_pMainWin->m_pApp->processEvents();
    230.  
    231. if ( progDlg.wasCanceled() )
    232. break;
    233. }
    234.  
    235. // Close the QFile
    236. if ( logFile.isOpen() )
    237. logFile.close();
    238.  
    239. // Enable sorting
    240. m_logTable->setSortingEnabled( true );
    241.  
    242. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by mclark; 16th November 2007 at 22:27.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSplashScreen Weirdness

    I'd suggest doing it a bit another way. You need to implement your functionality in a slot that can be called multiple times - once for every iteration. Then create the progress dialog, make a connection between a single shot timer and your slot and call exec() on the dialog.

    Set a 0 timeout for the timer and at the end of your slot start a 0-timeout single shot timer again. Something like:
    Qt Code:
    1. QProgressDialog dlg(this);
    2. iteration = 0;
    3. startSlot();
    4. dlg.exec();
    5. //...
    6. void X:startSlot(){
    7. iteration++;
    8. if(iteration<1000)
    9. QTimer::singleShot(0, this, SLOT(startSlot()));
    10. }
    To copy to clipboard, switch view to plain text mode 

    The main idea is to make sure you call exec on the progress dialog. See if your app crashes then.

Similar Threads

  1. Alpha channel weirdness with QGLContext
    By renaissanz in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2006, 16:10

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
  •  
Qt is a trademark of The Qt Company.