PDA

View Full Version : Error to declare signal



guidupas
14th February 2014, 11:46
Hello All!

I am trying to declare a signal as the code below shows:
bancodados.h


#ifndef BANCODADOS_H
#define BANCODADOS_H

#include <QObject>

class bancoDados : public QObject
{
Q_OBJECT

public:
explicit bancoDados(QObject *parent = 0);

signals:
void conectar();

public slots:

};

bancodados.cpp


#include "bancodados.h"

#include <QSqlDatabase>

bancoDados::bancoDados(QObject *parent) :
QObject(parent)
{

}
void bancoDados::conectar()
{
bool retorno = true;

emit retorno;
}


Well, when I run this code it show the error:

:-1: error: 1 duplicate symbol for architecture x86_64

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.

sakya
14th February 2014, 12:46
Signals don't have code.

This code is wrong:

void bancoDados::conectar()
{
bool retorno = true;

emit retorno;
}

To emit a signal you just need to declare it (with arguments if needed):

signals:
void conectar();

And then emit it when needed:

emit conectar();

If you need to pass that boolean value to the signal you declare it and pass the boolean as argument:

signals:
void conectar(bool);


emit conectar(true);

guidupas
14th February 2014, 14:26
Thaks a lot