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. Catch emitted signal from multiple class
Forum Updated to NodeBB v4.3 + New Features

Catch emitted signal from multiple class

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.7k 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.
  • T Offline
    T Offline
    thehilmisu
    wrote on last edited by
    #1

    Hi everyone,

    I am developing an tcpserver application. I have newDataReceived slot and i emit a signal in it like,

    @
    void myclass::newDataReceived()
    {

    char data_received[1024] = {0};
    client->read(data_received, client->bytesAvailable());
    QString msg = data_received;
    QString client_ip = client->peerAddress().toString();
    
    emit dataReceived(msg,client_ip);
    

    }
    @
    i have catch the signal from MainWindow, there is no problem. But, i have another class which is QThread i want this class to catch this signal, too. But it does not do it. I connected the signal to my slot like,

    @
    srv_thread = new myclass();
    connect(srv_thread,SIGNAL(dataReceived(QString,QString)),this,SLOT(incoming_message(QString,QString)));
    @

    What am i missing ?

    Thanks in advance

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

      If objects that "live" in different threads are connected, a queued connection will be created, by default. However an object will only be able to process queued signals, if the thread to which that object belongs, is running an event loop! That's because in contrast to a direct connection (where the slot is called directly from the emit statement and thus from the context of the thread which called the emit), with a queued signal, the event loop of the thread where the receiver object "lives" will pick up the signal and then call the slot (i.e. the slot is now called from the context of the thread where the receiver object "lives", not from the sender's thread). So if you re-implemented QThead::run(), call QThead::exec() there in order to start an event loop in that thread...

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      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