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. block C++ and waiting for a qml signal to continue execution
Forum Updated to NodeBB v4.3 + New Features

block C++ and waiting for a qml signal to continue execution

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 786 Views 2 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.
  • G Offline
    G Offline
    Guigui64
    wrote on last edited by
    #1

    Hello everyone, I'm currently working on a qml/c++ application (Qt 5.14.2) and please I need your help.
    I want from the c++ side set visible a popup that is on the Qml side and block the C++ execution until the closing of the popup.

    To achieve this, I use a QEventloop to block the execution and i connect the signal "closed" of the popup to the "quit" slot of the QEventLoop. But I have a problem, when I do that the GUI is blocked and i can do nothing. Would you know how I can solve this problem ?

    You can see below a sample of my application:

    the C++ function in which we want to wait the signal

    void backend::press(){  
        setPopupVisible(true); //dispay popup on the qml side
        wait(); //wait for the close of the popup
        doSomeWork();//do something after....
    }
    

    The wait function

    void backend::wait(){
        qDebug()<<"wait.....";
        QEventLoop loop;
        loop.connect(qmlPopup,SIGNAL(closed()),SLOT(quit()));
        loop.exec();
    

    Thank you in advance for your help!

    artwawA 1 Reply Last reply
    0
    • G Guigui64

      Hello everyone, I'm currently working on a qml/c++ application (Qt 5.14.2) and please I need your help.
      I want from the c++ side set visible a popup that is on the Qml side and block the C++ execution until the closing of the popup.

      To achieve this, I use a QEventloop to block the execution and i connect the signal "closed" of the popup to the "quit" slot of the QEventLoop. But I have a problem, when I do that the GUI is blocked and i can do nothing. Would you know how I can solve this problem ?

      You can see below a sample of my application:

      the C++ function in which we want to wait the signal

      void backend::press(){  
          setPopupVisible(true); //dispay popup on the qml side
          wait(); //wait for the close of the popup
          doSomeWork();//do something after....
      }
      

      The wait function

      void backend::wait(){
          qDebug()<<"wait.....";
          QEventLoop loop;
          loop.connect(qmlPopup,SIGNAL(closed()),SLOT(quit()));
          loop.exec();
      

      Thank you in advance for your help!

      artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #2

      @Guigui64 GUI freezes because you are blocking the main event loop. Don't.

      Redesign your approach to take advantage of the signal / slot mechanism used in Qt.

      For more information please re-read.

      Kind Regards,
      Artur

      1 Reply Last reply
      6
      • G Offline
        G Offline
        Guigui64
        wrote on last edited by
        #3

        Hi arwaw and thank you for your answer. The point is that it's completely the subject of my question, I want to find a way of not blocking the main event loop , I want to "wait" in the middle of the function and I have seen on some posts that using a QEventLoop might be a viable solution...
        However I think that, as you recommend, I will turn to another solution, maybe split the code in 2 separate functions and avoid the "blocking" solution....

        kshegunovK 1 Reply Last reply
        0
        • G Guigui64

          Hi arwaw and thank you for your answer. The point is that it's completely the subject of my question, I want to find a way of not blocking the main event loop , I want to "wait" in the middle of the function and I have seen on some posts that using a QEventLoop might be a viable solution...
          However I think that, as you recommend, I will turn to another solution, maybe split the code in 2 separate functions and avoid the "blocking" solution....

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Guigui64 said in block C++ and waiting for a qml signal to continue execution:

          However I think that, as you recommend, I will turn to another solution, maybe split the code in 2 separate functions and avoid the "blocking" solution....

          That's much better, and what you should do, yes.

          As a side note, QEventLoop is used correctly, as far as your code goes and as far as I can tell, but you should avoid it in principle.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          2

          • Login

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