Results 1 to 3 of 3

Thread: problem with emiting a signal

  1. #1
    Join Date
    Dec 2008
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem with emiting a signal

    Hello everybody. I'm just testing how to emit a custom signal . For example, i have a button and , when I press it, ai want a signal called MySignal to be emited. I've done that quite easy

    Qt Code:
    1. emit MySignal();
    To copy to clipboard, switch view to plain text mode 

    I now declare this signal in the "h" file :

    Qt Code:
    1. signals:
    2. void MySignal();
    To copy to clipboard, switch view to plain text mode 

    The problem is in the "cpp" file where i define this signal:

    Qt Code:
    1. void App1::MySignal()
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 

    When it compiles it gives the following error:

    Qt Code:
    1. tmp/obj/release_shared/moc_app.o(.text+0x60):moc_app.cpp: multiple de
    2. `App1::MySignal()'
    3. tmp/obj/release_shared/app.o(.text+0x0):app.cpp: first defined here
    To copy to clipboard, switch view to plain text mode 

    What seems to be the problem ?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem with emiting a signal

    you don't need to implement signal, the moc does it. you need just emit a signal like this
    Qt Code:
    1. ....
    2. connect(myButton, SIGNAL(clicked()), this, SIGNAL(processButtonClick()));
    3. ....
    4. void App::processButtonClick()
    5. {
    6. ...
    7. emit MySignal();
    8. ...
    9. }
    To copy to clipboard, switch view to plain text mode 
    or in your case (of cource if you don't need to process a button click)
    Qt Code:
    1. ...
    2. connect(myButton, SIGNAL(clicked()), myWidget, SIGNAL(MySignal()));
    3. ...
    To copy to clipboard, switch view to plain text mode 
    myWidget -- is the widget which has MySignal.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Dec 2008
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with emiting a signal

    10x ... i didn't know that.

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  3. QDateEdit emiting signal problem
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 17th June 2008, 07:59
  4. Possible signal mapper problem
    By MarkoSan in forum Qt Programming
    Replies: 13
    Last Post: 25th January 2008, 13:11
  5. Replies: 3
    Last Post: 15th April 2007, 19:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.