Newbie signal set up confusion
-
Ok, I am really lost at the idea of declaring a signal but not implementing it, i.e. letting MOC do it.
'I have a mainwindow class with 2 objects - 1 is a plot window, 2 is a data analyzer.
The data analyzer goes over data coming in over tcp port and identified peak.
I want the peak plotted in the plot window.
I set up a signal, setPeakVal and connect it to a slot update Graph.
How do I actually Pass the peak value from the signal to the slot for plotting?
defining the setPeakVal to pass peak resulted in multiple definition of function error.
-
Hi,
To setup a signal you have to do the following:
Make sure your class is derived from
@QObject@
Have the
@Q_OBJECT @
macro in the class headerin class header under signals:
define the signal:
@void setPeakVal()@In your case I would recommend to rename the signal to peakIdentified or something, because that is what happened.
If you want to pass a value (e.g. an integer) you define the signal as follows:
@void peakIdentified(int value)@
Before the code is compiled, Qt will run moc which will generate code for you (i.e. write header and implementation files) that will implement peakIdentified.
You connect the your SLOT which should take as an argument an int:
@
void updateGraph(int value)@and when you want to notify the slots connected to peakIdentified, you write
@emit peakIdentified(2) @(if the value was 2). Note that you don't even need to write emit.
Hope this helps