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. QWebChannel signal Qt::ConnectionType
Qt 6.11 is out! See what's new in the release blog

QWebChannel signal Qt::ConnectionType

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 827 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.
  • G Offline
    G Offline
    gpioloco
    wrote on last edited by
    #1

    Hello there

    To explain my problem i have to explain my situation first. My Project contains a Server and a Client. My code on the server looks like this :

    void LongFunction(){
       emit Log("Start doing something that might take some time");
       //do something that takes much time
       std::this_thread::sleep_for(20s);
       emit Log("Done doing something that might take some time");
    }
    

    When i call the "LongFunction" from my client i want to show the log messages in the Client GUI. Therefore i connect to the "Log" signal. But here comes my problem the signals will be emitted / triggered after "LongFunction" returns. Which makes my logs not so usefull.
    While doing some tests on the Server only i experienced that my problems does not occur on the Server if i use the Qt::ConnectionType "Qt::DirectConnection".

    My question now is: Is it possible to set the Qt::ConnectionType from the QWebChannel JS Client? If thats not possible is there some kind of other workaround that allows me to emit / trigger my signals immediately instead of when the function returns.

    Kind Rregards
    Gino Pio Loco

    jsulmJ 1 Reply Last reply
    0
    • G gpioloco

      Hello there

      To explain my problem i have to explain my situation first. My Project contains a Server and a Client. My code on the server looks like this :

      void LongFunction(){
         emit Log("Start doing something that might take some time");
         //do something that takes much time
         std::this_thread::sleep_for(20s);
         emit Log("Done doing something that might take some time");
      }
      

      When i call the "LongFunction" from my client i want to show the log messages in the Client GUI. Therefore i connect to the "Log" signal. But here comes my problem the signals will be emitted / triggered after "LongFunction" returns. Which makes my logs not so usefull.
      While doing some tests on the Server only i experienced that my problems does not occur on the Server if i use the Qt::ConnectionType "Qt::DirectConnection".

      My question now is: Is it possible to set the Qt::ConnectionType from the QWebChannel JS Client? If thats not possible is there some kind of other workaround that allows me to emit / trigger my signals immediately instead of when the function returns.

      Kind Rregards
      Gino Pio Loco

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

      @gpioloco To explain your problem: Qt::DirectConnection means that the slot connected to the signal will be executed as if you would call the slot directly. This is why it works in this case.
      If you do not use Qt::DirectConnection and emit a signal then the signal is put into a queue and will be fetched from the queue next time event loop runs. But, since you do long lasting stuff after emitting signal the event loop is blocked.
      What you could do to let the event loop do its work after emitting the signal is calling https://doc.qt.io/qt-5/qcoreapplication.html#processEvents after first emit.
      Alternative would be to use a one shot timer with 0 as time out value and move the long lasting stuff into a slot connected to the time out signal of the timer.

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

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

        I already tried to call "QCoreApplication::processEvents();" after the emit but that did not help. I will try the timer workaround and write back to you if it worked.
        Thanks for the quick response

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gpioloco
          wrote on last edited by
          #4

          Update:
          I figured out a workaround using the a timer. Thanks for the help.

          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