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. Occasionly error with internal error When using QEventLoop
Forum Updated to NodeBB v4.3 + New Features

Occasionly error with internal error When using QEventLoop

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 737 Views 1 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.
  • Q Offline
    Q Offline
    qiuyuFengye
    wrote on last edited by qiuyuFengye
    #1
    QThead thread; //call slots
    
    QEventLoop* eLoop;
    QTimer *timer;
    bool timeOutFlag=false;
    
    bool TimeOut()
    {        
            timer->start(interval);
            connect(&timer,QTimer::timeout,[]()
            {
                    eloop->quit();
                    timeOutFlag=true;
            })
            eloop->exec()
            return timeOutFlag;
    }
    
    /*
    Functionality:DoSomeThing once its according signal emits at specifi code running time.If there is not emitted singal during the specific code running time,skip DoSomeThing 
    */
    while(1)
    {
            if(TimeOut())
            {
                    break;
            }
            DoSomeThing();
    }
    

    Codes above is outline of my code using QEventLoop. It may error with "internal error"(i have read the soure of QEventloop but cannot understand the errorhint).Can you give me a solution or any suggestion?
    Thanks!

    jsulmJ 1 Reply Last reply
    0
    • Q qiuyuFengye
      QThead thread; //call slots
      
      QEventLoop* eLoop;
      QTimer *timer;
      bool timeOutFlag=false;
      
      bool TimeOut()
      {        
              timer->start(interval);
              connect(&timer,QTimer::timeout,[]()
              {
                      eloop->quit();
                      timeOutFlag=true;
              })
              eloop->exec()
              return timeOutFlag;
      }
      
      /*
      Functionality:DoSomeThing once its according signal emits at specifi code running time.If there is not emitted singal during the specific code running time,skip DoSomeThing 
      */
      while(1)
      {
              if(TimeOut())
              {
                      break;
              }
              DoSomeThing();
      }
      

      Codes above is outline of my code using QEventLoop. It may error with "internal error"(i have read the soure of QEventloop but cannot understand the errorhint).Can you give me a solution or any suggestion?
      Thanks!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @qiuyuFengye Can you please explain what you are trying to achieve? Using blocking loops and additional event loops is most of the time bad idea. Also, you connect the timeout signal each time you call Timeout() function!

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      2
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Don't use QEventLoop but signals/slots.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • jsulmJ jsulm

          @qiuyuFengye Can you please explain what you are trying to achieve? Using blocking loops and additional event loops is most of the time bad idea. Also, you connect the timeout signal each time you call Timeout() function!

          Q Offline
          Q Offline
          qiuyuFengye
          wrote on last edited by
          #4

          @jsulm DoSomeThing once its according signal emits at specifi code running time.If there is not emitted singal during the specific code running time,skip DoSomeThing

          jsulmJ 1 Reply Last reply
          0
          • Q qiuyuFengye

            @jsulm DoSomeThing once its according signal emits at specifi code running time.If there is not emitted singal during the specific code running time,skip DoSomeThing

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @qiuyuFengye There is no need for a loop and event loop for that. Simply start the timer and connect that signal ("If there is not emitted singal") to a slot. In that slot check if the timer is still running, if it is call DoSomeThing.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            Q 1 Reply Last reply
            2
            • jsulmJ jsulm

              @qiuyuFengye There is no need for a loop and event loop for that. Simply start the timer and connect that signal ("If there is not emitted singal") to a slot. In that slot check if the timer is still running, if it is call DoSomeThing.

              Q Offline
              Q Offline
              qiuyuFengye
              wrote on last edited by qiuyuFengye
              #6

              @jsulm expain my purpose in detail:
              i have two device(host,slave).When needed ,i should let host communiction with slave(host send messgaes to slave,and slave responses it).According to slave's response,i decide to do something.
              Code is : host.send(msg),msgs=host.response(),process(msgs),AnyOtherFunction().I must keep the order , host communcations with slave and then AnyOtherFunction.
              when slave responses ,code emits response signal(connected to repsonsed slot).now my repsonsed slot is just storing responsed msg.

              jsulmJ 1 Reply Last reply
              0
              • Q qiuyuFengye

                @jsulm expain my purpose in detail:
                i have two device(host,slave).When needed ,i should let host communiction with slave(host send messgaes to slave,and slave responses it).According to slave's response,i decide to do something.
                Code is : host.send(msg),msgs=host.response(),process(msgs),AnyOtherFunction().I must keep the order , host communcations with slave and then AnyOtherFunction.
                when slave responses ,code emits response signal(connected to repsonsed slot).now my repsonsed slot is just storing responsed msg.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @qiuyuFengye All this can be done with signals slots. You send message, you get response in a slot and process the response. Qt is asynchronous, you should not try to make it synchronous using loops and local event loops. Use signals/slots as they are meant to be used.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                Q 1 Reply Last reply
                3
                • jsulmJ jsulm

                  @qiuyuFengye All this can be done with signals slots. You send message, you get response in a slot and process the response. Qt is asynchronous, you should not try to make it synchronous using loops and local event loops. Use signals/slots as they are meant to be used.

                  Q Offline
                  Q Offline
                  qiuyuFengye
                  wrote on last edited by
                  #8

                  @jsulm My purpose is that host communcations with slave sequentially(communication1,communication2,communication3,...),the latter communication depends on former communication.if not blockig qthread,how
                  should i achieve it?

                  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