How to show a Dialog from loop - wait - return to caller
-
Hi there,
I have a question regarding loops and Events.
I loop through a list of colors. If a color is missing I show a search dialog.
When another color is selected the user fires a signal by pressing a button.
After this he closes the dialog ... the loop should proceed from here - but it simply stops.thx in advance
for (unsigned int i = 0; i < IP.inkList.size(); i++) { if(IP.inkList.name == "") { ColorList *mColorList = new ColorList("color", this); connect(mColorList, &ColorList::signalSetColor, this, &MyApp::slotSetColor); mColorList->setModal(true); mColorList->show(); //Stop loop until dialog is closed QEventLoop loop; connect(mColorList, SIGNAL(destroyed()), & loop, SLOT(quit())); loop.exec(); //How do I write the connect with new syntax - I tried this but it did not work: //connect(mColorList, &mColorList::destroyed, this, &loop::quit); } ... go ahead and do more }
-
A ademmler has marked this topic as solved on
-
@ademmler said in How to show a Dialog from loop - wait - return to caller:
//How do I write the connect with new syntax - I tried this but it did not work:
//connect(mColorList, &mColorList::destroyed, this, &loop::quit);connect(mColorList, &ColorList::destroyed, this, &QEventLoop::quit);
-
@Pl45m4 said in How to show a Dialog from loop - wait - return to caller:
onnect(mColorList, &ColorList::destroyed, this, &QEventLoop::quit);
thx for your suggestion. If I use this I get this error:
*/Users/ademmler/GitSpace/spectraproof3/spectraproof.cpp:1865: error: no matching member function for call to 'connect'
spectraproof.cpp:1865:17: error: no matching member function for call to 'connect'
connect(mColorList, &ColorList::destroyed, this, &QEventLoop::quit);/Users/ademmler/Qt/5.15.13/clang_64/lib/QtCore.framework/Headers/qobject.h:242:43: note: candidate function [with Func1 = void (QObject::*)(QObject ), Func2 = void (QEventLoop::)()] not viable: no known conversion from MyApp ' to 'const typename QtPrivate::FunctionPointer<void (QEventLoop::)()>::Object *' (aka 'const QEventLoop *') for 3rd argument
static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal,If I do this
connect(mColorList, &ColorList::destroyed, &loop, &QEventLoop::quit);
the app compiles, stops but does not run again after the window have closed. When I close the main window in the background, than the application finishes this task in the "background" ... kind of wired behavoir I think.
-
@ademmler
We could spend time discussing/diagnosing this (hint: closing dialog does not generatedestroyed
signal, soQEventLoop::quit()
is not called and loop continues to run). But it's pointless since what you want ismColorList->exec()
anyway, noQEventLoop
, noconnect()
s.