Results 1 to 12 of 12

Thread: QSplashScreen Weirdness

  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

    Question QSplashScreen Weirdness

    I have a problem using QSplashScreen. My application generates a log (text) file and has a menu item to let the user view a parsed display of this file in a table in a dialog. Since the file can be up to 500k, it takes a while to parse so I use a QSplashScreen to distract the user during the parsing (sometimes more than 5000 lines). The QSplashScreen is semi-transparent and displays a message indicating how many lines of the log file have been parsed.

    I know this is not normal usage of a QSplashScreen but it works fine except for the following.

    My problem is that if a user repeatedly clicks outside the QSplashScreen, in the main window title bar for example, after reading between 700 and 1200 lines of the > 5000 line file:
    • the message in the QSplashScreen freezes at a line number (but the file continues to be parsed)
    • the main window MAY be drawn over the QSplashScreen
    • the client area of the main window goes away (repainted in white)
    • when the file is finished being read, the dialog displays the log file contents correctly but the QSplashScreen is drawn on top and never goes away until the application closes

    While all of the results above are irritating, the worst is that the splash screen never goes away (even after the dialog is gone).

    I have tried trapping (and ignoring) the mousePressEvents in both the main window and the dialog but the mousePressEvent() function never gets the mouse events while the QSplashScreen is active. This is not surprising since it appears that the QSplashScreen has focus.

    I noticed that a mouse press should cause the splash screen to become hidden, but in this case it doesn't happen.

    BTW, I'm using 4.2.2 with VS2005.

    Any suggestions for fixing this weird mouse click problem?

    Qt Code:
    1. // From the class definition...
    2. QTableWidget* m_logTable;
    3. MainWin* m_pMainWin;
    4. QSplashScreen* m_pSplash;
    5. QFile m_logFile;
    6.  
    7. // Show Log file dialog ctor
    8. ShowLog::ShowLog( QWidget *pParent ) : QDialog( pParent )
    9. {
    10. m_pMainWin = static_cast<MainWin*>( pParent );
    11. QDir::setCurrent( QDir::currentPath() );
    12.  
    13. m_logFile.setFileName( LOG_FILENAME );
    14.  
    15. QIODevice::OpenMode nOpenMode = QIODevice::ReadOnly | QIODevice::Text;
    16.  
    17. if ( !m_logFile.exists() )
    18. reject();
    19.  
    20. if ( !m_logFile.open( nOpenMode ) )
    21. reject();
    22.  
    23. QPixmap pMap( SHOWLOG_SPLASH_IMG );
    24.  
    25. // Make the corners fully transparent (rounded-corner bitmap)
    26. if ( !pMap.mask().isNull() )
    27. {
    28. QImage img( SHOWLOG_SPLASH_IMG );
    29. if ( img.hasAlphaChannel() )
    30. pMap.setMask( QBitmap::fromImage( img.createAlphaMask() ) );
    31. else
    32. pMap.setMask( QBitmap::fromImage( img.createHeuristicMask() ) );
    33. }
    34.  
    35. ui.setupUi( this );
    36.  
    37. QPalette palette = ui.centralWidget->palette();
    38. palette.setColor( ui.centralWidget->backgroundRole(), COLOR_ManageBkg );
    39. ui.centralWidget->setPalette( palette );
    40.  
    41. m_logTable = new QTableWidget( 0, 4, this );
    42.  
    43. // Layout the Show Logfile dialog
    44. .
    45. .
    46. .
    47. // Initialize the text stream
    48. QTextStream logStream( &m_logFile );
    49. QString sLine, sSrc, sType, sTime, sMsg;
    50. QString sMsgText( " Reading %1: line %2" );
    51. Qt::ItemFlags flags;
    52. int start, end, nRow = 0;
    53.  
    54. // Skip the header
    55. while ( (sLine = logStream.readLine())[0] == '*' );
    56.  
    57. // Set up the splash screen
    58. m_pSplash = new QSplashScreen( pParent, pMap );
    59. m_pSplash->setWindowOpacity( 0.8 ); // make the image semi-transparent
    60. palette = m_pSplash->palette();
    61. palette.setBrush( QPalette::Window, QBrush( pMap ) );
    62. m_pSplash->setPalette( palette );
    63. m_pSplash->setFixedSize( pMap.size() );
    64. m_pSplash->setMask( pMap.mask() );
    65. QFont font = m_pSplash->font();
    66. font.setBold( true );
    67. m_pSplash->setFont( font ); // Set the m_pSplash font to bold
    68.  
    69. // Center the splash screen in the main application window
    70. m_pSplash->move( m_pMainWin->pos().x() +
    71. (m_pMainWin->frameGeometry().width() / 2) -
    72. (m_pSplash->frameGeometry().width() / 2),
    73. m_pMainWin->pos().y() +
    74. (m_pMainWin->frameGeometry().height() / 2) -
    75. (m_pSplash->frameGeometry().height() / 2) );
    76. m_pSplash->show();
    77.  
    78. // Load the text
    79. while ( !logStream.atEnd() || !sLine.isEmpty() )
    80. {
    81. if ( sLine.isEmpty() ) // skip any empty lines
    82. {
    83. sLine = logStream.readLine();
    84. continue;
    85. }
    86.  
    87. // Parse the Source
    88. .
    89. .
    90. .
    91. // Fill a table row
    92. m_logTable->insertRow( nRow );
    93. .
    94. .
    95. .
    96. nRow++;
    97. sLine = logStream.readLine();
    98.  
    99. // Incremental splash message
    100. m_pSplash->showMessage( sMsgText.arg( LOG_FILENAME ).arg( nRow ),
    101. nMsgAlignment, textColor );
    102. }
    103.  
    104. // Close the QFile
    105. if ( m_logFile.isOpen() )
    106. m_logFile.close();
    107.  
    108. // Set sort indicator in column headers
    109. m_logTable->horizontalHeader()->setSortIndicatorShown( true );
    110. m_logTable->setSortingEnabled( true );
    111.  
    112. m_pSplash->finish( this );
    113.  
    114. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSplashScreen Weirdness

    hi,
    Maybe disabling main window while splash is active would fix your error?
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

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

    Default Re: QSplashScreen Weirdness

    Why not use QProgressDialog or another modal dialog instead?

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

    Post Re: QSplashScreen Weirdness

    Quote Originally Posted by mchara View Post
    disabling main window while splash is active
    Disabling the main window would seem like the way to go, unfortunately it doesn't seem to take effect until after the splash screen goes away and after the dialog is shown.
    Qt Code:
    1. void MainWin::showLog( void )
    2. {
    3. setEnabled( false );
    4.  
    5. ShowLog showDlg( this );
    6. showDlg.exec();
    7.  
    8. setEnabled( true );
    9.  
    10. } // showLog(
    To copy to clipboard, switch view to plain text mode 
    This call is a slot for the menu selection triggered() signal and it appears that the setEnabled() is preempted by the splash screen action in the dialog ctor.


    Quote Originally Posted by wysota
    Why not use QProgressDialog or another modal dialog instead?
    I wanted to use a splash screen because I don't know in advance what the maximum number of parsable (is this a word?) lines I have to deal with. Although, I may be able to get similar functionality with some other type of modal dialog. I just liked the idea of having a semi-transparent, rounded corner bitmap and the QSplashScreen allowed me to do that with just a few lines of code.

    Do you have another modal dialog type in mind?

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

    Default Re: QSplashScreen Weirdness

    Quote Originally Posted by mclark View Post
    Do you have another modal dialog type in mind?
    Subclass QDialog, make it frameless and display a label on it that contains the bitmap of your choice. You can also use QWidget::setMask to make it round or something...

  6. The following user says thank you to wysota for this useful post:

    mclark (16th November 2007)

  7. #6
    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

    Quote Originally Posted by wysota View Post
    Subclass QDialog, make it frameless and display a label on it that contains the bitmap of your choice. You can also use QWidget::setMask to make it round or something...
    Thanks for the suggestion wysota.

    The code below 'kind of' works. A semi-transparent, rounded-corner dialog appears with the pixmap in it. If I only add the label with the pixmap, the pixmap appears as if it is inside the dialog. What I mean by that is there is a band of semi-transparent area around all 4 sides of the pixmap. Shrinking the dialog size only clips the pixmap.

    For parsing progress display, I thought I could add a second label to display the message text (similar to what QSplashScreen offers.) This never shows.

    Is there a way to have the pixmap in the label to completely fill the dialog area without clipping, and, for a line of text to be superimposed on the pixmap?

    Qt Code:
    1. QPixmap pMap( SHOWLOG_SPLASH_IMG );
    2.  
    3. // Make the corners fully transparent (rounded-corner bitmap)
    4. if ( !pMap.mask().isNull() )
    5. {
    6. QImage img( SHOWLOG_SPLASH_IMG );
    7. if ( img.hasAlphaChannel() )
    8. pMap.setMask( QBitmap::fromImage( img.createAlphaMask() ) );
    9. else
    10. pMap.setMask( QBitmap::fromImage( img.createHeuristicMask() ) );
    11. }
    12.  
    13. QDialog splashDlg( this, Qt::FramelessWindowHint );
    14.  
    15. splashDlg.setWindowOpacity( 0.8 ); // make the dialog semi-transparent
    16. palette = splashDlg.palette();
    17. palette.setBrush( QPalette::Window, QBrush( pMap ) );
    18. splashDlg.setPalette( palette );
    19. splashDlg.setFixedSize( pMap.size().width(), pMap.size().height() + 40 );
    20. splashDlg.setMask( pMap.mask() );
    21.  
    22. QFont font = splashDlg.font();
    23. font.setBold( true );
    24. splashDlg.setFont( font ); // Set the splashDlg font to bold
    25.  
    26. QLabel* pTxtLabel = new QLabel();
    27. QLabel* pImgLabel = new QLabel();
    28. pImgLabel->resize( pMap.size() );
    29. pImgLabel->setPixmap( pMap );
    30.  
    31. QVBoxLayout *vSplashBox = new QVBoxLayout( &splashDlg );
    32. vSplashBox->addWidget( pTxtLabel, Qt::AlignTop | Qt::AlignLeft );
    33. vSplashBox->addWidget( pImgLabel, Qt::AlignCenter );
    34.  
    35. splashDlg.show();
    36. .
    37. .
    38. .
    39. while ( !logStream.atEnd() || !sLine.isEmpty() )
    40. {
    41. .
    42. .
    43. .
    44. // Increment splash message every 50 iterations
    45. if ( !(nRow % 50) )
    46. pTxtLabel->setText( sMsgText.arg( LOG_FILENAME ).arg( nRow ) );
    47. }
    48.  
    49. splashDlg.close();
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QSplashScreen Weirdness

    If you override paint event of the dialog and draw the image there yourself, it should work. You can also use a label for that - just make sure it's not part of the layout and that it is lowered behind other widgets of the dialog. I'd suggest reimplementing the paint event though.

  9. #8
    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.

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.

  11. #10
    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.

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.

  13. #12
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSplashScreen Weirdness

    Hi,
    disabling main window may fail because you are not processing event loop while reading log and setEnabled is queued there so it's done after log reading.
    Even if you want to use progress dialog, you shall call QCoreApplication:rocessEvents from time to time according to qt manual.

    And one another approach - maybe read your log file in separate thread.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.