Creating events instead of signals/slots
-
[quote author="Andre" date="1301564768"]In his first reply, Gerolf already told you how to use custom events. It doesn't matter much if you want to post your own event or a Qt event. A QCloseEvent is just a subclass of QEvent that does not add any special members or methods.
[/quote]
I thinnk it will not. QCloseEvent is also a reaction on the close() slot (if close is no reaction to a system close event, there is an if in the code for that) :-).Sending a QCloseEvent will NOT close the widget!
@
... QWidget::event()
{
...
case QEvent::Close:
closeEvent((QCloseEvent *)event);
break;
...
}void QWidget::closeEvent(QCloseEvent *event)
{
event->accept();
}
@[quote author="Andre" date="1301564768"]
I am not sure if posting your own QCloseEvent is going to work, since the spontaneous flag would be false. AFAIK, there is no public API to manipulate that flag, and I don't know if it would affect the handling of the event.
[/quote]It's totaly internal, I was trying to use it once... Did not work. Needed it for a virtual key board.
-
I had already used it in my program and its working.My question is that can't we do the same by passing events between those widgets.in examples given in qt4,in mainwindows there is a sample program named application in which the QCloseEvent has been used but am not able take that and implement to my requirement.It throws a compile error as
@/usr/include/qt4/QtGui/qwidget.h:84: error: forward declaration of ‘struct QCloseEvent’
@Help me.
-
Well!I have multiple screens.I need to display a particular screen based on the event I pass from my first screen.With signal and slot,I need to write those lines of code in all the files.Suppose if I have some 20 screens then by passing an event from my first screen I should display 10th(or 15th whatever) or close that particular window by having all my control in my first screen.
-
OK, here's what I would do, and then I think I'll quit responding to this thread.
I would create a single QObject that is responsible for the communication with the C-based backend. This object receives the call-backs or events or whatever you call them from the backend, and emits corresponding signals for these events. The different windows connect to this object's signals to learn about the data they are interested in.
-
[quote author="Revu" date="1301986907"]@Andre:Thank you for your response.Could you explain the same with a code snippet please.So that I can understand better.[/quote]
Not without knowing what your back end looks like and how to communicate with it, no. And to be honest, I don't think I can or want to do that even if you provided the needed code and documentation. I think the concept should be clear though?
-
I have multiple screens for a outgoing call like Idle,Dial,Progress and Connect screen.My backend controller program is in C.I need to change from Idle to Dial.After I enter the number show progress screen and finally connect screen after the call is established.Based on the events I get from C,my screen will change.Its like with button click I will wait for an event and then display the screen.While showing the other screen,am closing the current(using signal and slot mechanism).So how could I do that with events.