Note that there are some explanatory texts on larger screens.

plurals
  1. POQt two or multiple same signals calling slot only once
    primarykey
    data
    text
    <p>I'm sending two (or more) same signals, which receives one slot, but it is only called once instead of two times.. What I'm doing wrong?</p> <p>main.cpp:</p> <pre><code>#include &lt;QCoreApplication&gt; #include "app.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); App app; QMetaObject::invokeMethod(&amp;app, "run", Qt::QueuedConnection); return a.exec(); } </code></pre> <p>app.h:</p> <pre><code>#ifndef APP_H #define APP_H #include &lt;QObject&gt; #include "tcpserver.h" #include "tcpsocket.h" class App : public QObject { Q_OBJECT public: explicit App(QObject *parent = 0); signals: public slots: void run() { qDebug() &lt;&lt; "run()"; server.server_start(1111); socket.connectToHost("127.0.0.1", 1111); socket.write("hello", 5); socket.write("olleh", 5); // should execute slot two times. } private: TcpServer server; TcpSocket socket; }; #endif // APP_H </code></pre> <p>TcpSocket.h:</p> <pre><code>#ifndef TCPSOCKET_H #define TCPSOCKET_H #include &lt;QTcpSocket&gt; class TcpSocket : public QTcpSocket { Q_OBJECT public: explicit TcpSocket(QObject *parent = 0); signals: void dataReady(QByteArray data); public slots: void readyRead() { qDebug() &lt;&lt; "Bytes available:" &lt;&lt; this.bytesAvailable(); // called only once. data = this.readAll(); // just for testing. emit dataReady(data); // } void disconnected(); private: QByteArray data; }; #endif // TCPSOCKET_H </code></pre> <p>as you can see, I'm doing two socket.write functions, which should be handled two readyRead slots, but it is called only once. I honestly don't understand what I'm doing wrong.</p> <p>Regards.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload