PDA

View Full Version : Signal and Slots



waynew
19th November 2009, 22:33
I'm trying to set up a class with a signal, but it fails to compile.



#ifndef CONTROLDB_H
#define CONTROLDB_H

#include <QString>

class ControlDB:public QObject
{
public:
ControlDB();
void ControlDB::makeControlDB();
void ControlDB::setLastLog(QString);
void ControlDB::setOper(QString);
QString ControlDB::getLastLog();
QString ControlDB::getOper();

signals:
void valueChanged(QString);
};

#endif // CONTROLDB_H



Here is the error:
error: expected class-name before '{' token

What am I doing wrong here?

positive_4_life
19th November 2009, 23:24
AFAIK, you should try including the Q_OBJECT, and see if that helps:



#ifndef CONTROLDB_H
#define CONTROLDB_H

#include <QString>

class ControlDB:public QObject
{
Q_OBJECT

public:
ControlDB();
void makeControlDB();
void setLastLog(QString);
void setOper(QString);
QString getLastLog();
QString getOper();

signals:
void valueChanged(QString);
};

#endif // CONTROLDB_H

I don't particularly see the point in placing the ControlDB:: for your member functions when it is already implied they belong to the ControlDB class.

waynew
20th November 2009, 00:57
Ok positive_4_life. I have changed the code to this:



#ifndef CONTROLDB_H
#define CONTROLDB_H

#include <QString>

class ControlDB:public QObject
{
Q_OBJECT

public:
ControlDB();
void makeControlDB();
void setLastLog(QString);
void setOper(QString);
QString getLastLog();
QString getOper();

//signals:
//void valueChanged(QString);
};

#endif // CONTROLDB_H


Now I still get this error:
controldb.h:7: error: expected class-name before '{' token

I can't see anything wrong with it.

ChrisW67
20th November 2009, 03:50
You might want to #include a definition for QObject because QString doesn't:

#include <QObject>