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. When come many signals, slot waits for finish and it starts another
Forum Updated to NodeBB v4.3 + New Features

When come many signals, slot waits for finish and it starts another

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 236 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.
  • BondrusiekB Offline
    BondrusiekB Offline
    Bondrusiek
    wrote on last edited by
    #1

    Hi,
    I have gui app. I created 3 QUdpSocket which listen data on specific port and this data control gui app. This 3 sockets use one slot:

    connect(socket1, &QUdpSocket::readyRead, this, &MyClass::parseData);
    connect(socket2, &QUdpSocket::readyRead, this, &MyClass::parseData);
    connect(socket3, &QUdpSocket::readyRead, this, &MyClass::parseData);
    

    And now when i immadietly send 3 frames on sockets i want to achive that result:
    When 1 slots finish job, start second, when second finishes start third but these actions don't block GUI.
    Greetings

    artwawA 1 Reply Last reply
    0
    • M Offline
      M Offline
      MrShawn
      wrote on last edited by
      #2

      Assuming MyClass is not your main window, move MyClass to another thread using moveToThread, and start the thread. It should provide you with what you're looking for.

      In your case it might not be as simple as that. When you make objects in one thread, moving a parent object to another thread will not work. Usually what I do is add a "start" function slot that will instantiate all the objects. I connected the started signal from the thread I move to to the start slot. this will execute the start method on the new thread once that thread is started.

      here is an example of what I mean:

          QThread handlerThread;
          LocalServerHandler mLocalServerHandler;
          QObject::connect(&app,&QGuiApplication::aboutToQuit,&handlerThread,&QThread::quit);
          QObject::connect(&app,&QGuiApplication::aboutToQuit,&handlerThread,&QThread::deleteLater);
          mLocalServerHandler.moveToThread(&handlerThread);
          QObject::connect(&handlerThread,&QThread::started,&mLocalServerHandler,&LocalServerHandler::start);
          QObject::connect(&app,&QGuiApplication::aboutToQuit,&mLocalServerHandler,&LocalServerHandler::deleteLater);
      

      The event loop in that new thread will still run first event in first event out but your main event loop will keep the UI unlocked.

      1 Reply Last reply
      1
      • BondrusiekB Bondrusiek

        Hi,
        I have gui app. I created 3 QUdpSocket which listen data on specific port and this data control gui app. This 3 sockets use one slot:

        connect(socket1, &QUdpSocket::readyRead, this, &MyClass::parseData);
        connect(socket2, &QUdpSocket::readyRead, this, &MyClass::parseData);
        connect(socket3, &QUdpSocket::readyRead, this, &MyClass::parseData);
        

        And now when i immadietly send 3 frames on sockets i want to achive that result:
        When 1 slots finish job, start second, when second finishes start third but these actions don't block GUI.
        Greetings

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

        @Bondrusiek What exactly is your question? Behaviour you described is sound, works as it should.
        If you'd like to modify the default behaviour please see https://doc.qt.io/qt-5/qt.html#ConnectionType-enum for options available.

        For more information please re-read.

        Kind Regards,
        Artur

        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