qt - Modal QDialog still allows timers to call slots? -


in qt program, have modal qdialogs meant halt , not continue execution of code until after dismissed. , works function it's in--i put breakpoint on next line of code after qdialog::exec() , doesn't break until after dismiss dialog.

however, there qtimer connected slot on timeout, , continue go when modal dialog , execute code in slot.

i suppose stop timer before showing modal dialog. however, there may cases when dialog in totally different class timer. there way halt execution of program until qdialog dismissed?

example:

qtimer* ptesttimer = new qtimer( ); connect( ptesttimer , signal( timeout() ), this, slot( timerslot() ) );  //slot code elsewhere void cmyclass::deletemetimerslot() {     qdebug() << "see me during modal?"; }  //starting modal dialog ptesttimer->start( 1000 );  qdialog* pmodaldlg = new qdialog( this, qt::dialog | qt::framelesswindowhint     | qt::windowstaysontophint );  pmodaldlg->setmodal(true); pmodaldlg->exec(); 

output still shows "see me during modal?" while in exec();

i suppose stop timer before showing modal dialog. however, there may cases when dialog in totally different class timer.

yes, can operate timers accessible within parent context (it seems generic solution).

// halt timers within parent context. // if timers have parent maybe top app widget pointer // should used parentobj qlist<qtimer*> listoftimers = parentobj->findchildren<qtimer*>(    qstring(), qt::findchildrenrecursively); for(qtimer* ptimer : listoftimers)    ptimer->stop(); 

is there way halt execution of program until qdialog dismissed?

unless mean stop threads: no, qdialog part of program , not imply halting execution modal dialog runs in own event loop , prevents user operating other program ui. suppose can restart stopped timers after exiting modal dialog.

pmodaldlg->exec();  // restart timers within parent context for(qtimer* ptimer : listoftimers)    ptimer->start(); 

you can peek @ qt source code (at qdialog , event loop uses) , create own sophisticated dialog class specific event loop it.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -