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. Question about Qt::QueuedConnection
Forum Updated to NodeBB v4.3 + New Features

Question about Qt::QueuedConnection

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 423 Views
  • 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.
  • A Offline
    A Offline
    AccWhid
    wrote on last edited by
    #1

    I'm curious about the behavior of signals when connected to slots via Qt::QueuedConnection, specifically what if you call to emit the same signal from two different threads.

    i.e.:

    class A : public QObject
    {
        Q_OBJECT
    public:
    
        A()
        {
            auto worker = new B();
            auto thread = new QThread();
            worker.moveToThread(thread);
    
            connect(this, &A::fireTestSignal, worker, &B::testSlot);
    
        }
    
        void fireTestSignal()
        {
            emit fireTestSignal();
        }
    
    signals:
    
        void testSignal();
    
    };
    
    class B : public QObject
    {
        Q_OBJECT
    
    public:
    
        B()
        {
    
        }
    
    public slots:
    
        void testSlot()
        {
            qInfo() << "Test";
        };
    };
    
    int main()
    {
        
        //Assume QCoreApplication created here
    
        const auto testClass = std::make_shared<A>();
    
        QtConcurrent::run(QThreadPool(), [testClass]()
        {
            testClass->fireTestSignal();
        });
    
        testClass->fireTestSignal();
    
    
        return 0;
    }
    

    Does firing the same signal from two threads cause issues if the connection is a Queued Connection type? Is calling the signal itself thread safe?

    Thanks!

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2
      1. No
      2. Yes

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      1

      • Login

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