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. Newbie signal set up confusion

Newbie signal set up confusion

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 706 Views
  • 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.
  • K Offline
    K Offline
    kpks
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      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 header

      in 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

      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