Results 1 to 3 of 3

Thread: Error to declare signal

  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Error to declare signal

    Hello All!

    I am trying to declare a signal as the code below shows:
    bancodados.h
    Qt Code:
    1. #ifndef BANCODADOS_H
    2. #define BANCODADOS_H
    3.  
    4. #include <QObject>
    5.  
    6. class bancoDados : public QObject
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. explicit bancoDados(QObject *parent = 0);
    12.  
    13. signals:
    14. void conectar();
    15.  
    16. public slots:
    17.  
    18. };
    To copy to clipboard, switch view to plain text mode 
    bancodados.cpp
    Qt Code:
    1. #include "bancodados.h"
    2.  
    3. #include <QSqlDatabase>
    4.  
    5. bancoDados::bancoDados(QObject *parent) :
    6. QObject(parent)
    7. {
    8.  
    9. }
    10. void bancoDados::conectar()
    11. {
    12. bool retorno = true;
    13.  
    14. emit retorno;
    15. }
    To copy to clipboard, switch view to plain text mode 

    Well, when I run this code it show the error:
    Qt Code:
    1. :-1: error: 1 duplicate symbol for architecture x86_64
    To copy to clipboard, switch view to plain text mode 

    But, if I change "void conectar();" from signals to public, it runs, but I need to it stays as a signal

    Can anyone help me?

    Thanks a lot.

  2. #2
    Join Date
    Jul 2011
    Location
    Italy
    Posts
    24
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Error to declare signal

    Signals don't have code.

    This code is wrong:
    Qt Code:
    1. void bancoDados::conectar()
    2. {
    3. bool retorno = true;
    4.  
    5. emit retorno;
    6. }
    To copy to clipboard, switch view to plain text mode 

    To emit a signal you just need to declare it (with arguments if needed):
    Qt Code:
    1. signals:
    2. void conectar();
    To copy to clipboard, switch view to plain text mode 

    And then emit it when needed:
    Qt Code:
    1. emit conectar();
    To copy to clipboard, switch view to plain text mode 

    If you need to pass that boolean value to the signal you declare it and pass the boolean as argument:
    Qt Code:
    1. signals:
    2. void conectar(bool);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. emit conectar(true);
    To copy to clipboard, switch view to plain text mode 
    Last edited by sakya; 14th February 2014 at 14:17.

  3. #3
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Error to declare signal

    Thaks a lot

Similar Threads

  1. Another signal error message
    By gib in forum Qt Tools
    Replies: 4
    Last Post: 28th October 2013, 21:36
  2. error with a signal - slot
    By mmm286 in forum Newbie
    Replies: 1
    Last Post: 10th November 2009, 18:41
  3. segv error in signal
    By Sheng in forum Qt Programming
    Replies: 7
    Last Post: 8th April 2009, 19:14
  4. ERROR: /qtopia/build/bin/sxe_installer does not declare
    By learning_qt in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 18th September 2008, 08:00
  5. How to declare signal in qt designer??
    By hesummar in forum Qt Tools
    Replies: 4
    Last Post: 27th October 2006, 14:31

Tags for this Thread

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.