In Qt you can connect two objects by setting up a signal in one object a slot in the other and then connecting them using "connect()".
Now by emitting a signal in one object it is sent to the second object. I have a system that takes user inputs and if there are too many user inputs I want my "queue" to fill up and not accept any more inputs.
I could implement a reply mechanism on the receiving object, but I want to know if we can make a queue size of (for example) 1. So only one message will be handled, and any new emittions are simply chucked away until the "pipe" is has space.
Is this possible in Qt?
In my case the two objects are in different threads and have a queued connection (if that makes any difference)...
MainWindow::MainWindow()
{
// Make object 1, stick it in another thread
MyObjType1 *obj1 = new MyObjType1();
anotherThread = new QThread; // anotherThread is type QThread *
obj1->moveToThread(anotherThread);
anotherThread->start();
// Make object 2, connect a signal to obj1
MyObjType2 *obj2 = new MyObjType2();
connect(obj2, SIGNAL(obj2Signal(int), obj1, SLOT(obj1Slot(int), Qt::QueuedConnection);
// Hammer obj1 with signals to its queue
for (int i = 0; i < 100000; i++)
{
emit obj2->obj2Signal(i);
}
}
So the idea would be that obj1 gets lots of signals, it handles the first one, and somehow throws the others away until it finishes, then takes on the next one that is emitted.