Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to show a Dialog from loop - wait - return to caller
Forum Updated to NodeBB v4.3 + New Features

How to show a Dialog from loop - wait - return to caller

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 468 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ademmlerA Offline
    ademmlerA Offline
    ademmler
    wrote on last edited by
    #1

    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
    }
    
    M Pl45m4P 2 Replies Last reply
    0
    • ademmlerA ademmler

      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
      }
      
      M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      @ademmler said in How to show a Dialog from loop - wait - return to caller:

      mColorList->show();

      Why not call exec() instead ?

      ademmlerA 1 Reply Last reply
      1
      • M mpergand

        @ademmler said in How to show a Dialog from loop - wait - return to caller:

        mColorList->show();

        Why not call exec() instead ?

        ademmlerA Offline
        ademmlerA Offline
        ademmler
        wrote on last edited by
        #3

        @mpergand

        I tried and it did not worked also.

        M 1 Reply Last reply
        0
        • ademmlerA ademmler

          @mpergand

          I tried and it did not worked also.

          M Offline
          M Offline
          mpergand
          wrote on last edited by
          #4

          @ademmler
          Show your code.

          ademmlerA 1 Reply Last reply
          0
          • M mpergand

            @ademmler
            Show your code.

            ademmlerA Offline
            ademmlerA Offline
            ademmler
            wrote on last edited by
            #5

            @mpergand

            my mistake - I have overseen and had

            loop.exec(); instead of mColorList->exec();

            Hence you are right and provided the correct answer. Thank you!

            1 Reply Last reply
            0
            • ademmlerA ademmler has marked this topic as solved on
            • ademmlerA ademmler

              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
              }
              
              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @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);
              

              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              ademmlerA 1 Reply Last reply
              1
              • Pl45m4P Pl45m4

                @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);
                
                ademmlerA Offline
                ademmlerA Offline
                ademmler
                wrote on last edited by
                #7

                @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.

                JonBJ 1 Reply Last reply
                0
                • ademmlerA ademmler

                  @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.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @ademmler
                  We could spend time discussing/diagnosing this (hint: closing dialog does not generate destroyed signal, so QEventLoop::quit() is not called and loop continues to run). But it's pointless since what you want is mColorList->exec() anyway, no QEventLoop, no connect()s.

                  ademmlerA 1 Reply Last reply
                  2
                  • JonBJ JonB

                    @ademmler
                    We could spend time discussing/diagnosing this (hint: closing dialog does not generate destroyed signal, so QEventLoop::quit() is not called and loop continues to run). But it's pointless since what you want is mColorList->exec() anyway, no QEventLoop, no connect()s.

                    ademmlerA Offline
                    ademmlerA Offline
                    ademmler
                    wrote on last edited by
                    #9

                    @JonB You are right - I use mColorList->exec() now!

                    But I took the chance, which @Pl45m4PI gave me,
                    to check the syntax of the connect statement also.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved