PDA

View Full Version : error: 'connect' was not declared in this scope ??



Morea
14th January 2007, 14:32
error: 'connect' was not declared in this scope

this is the error I get when trying to compile this code:




------ cpp file --------

#include "Fraga.h"
#include <QtGui>
#include <QtCore>
Fraga::Fraga()
{
_nyttsvar = new QAction("new answer",0);
qDebug()<<"hej"<<connect(_nyttsvar,SIGNAL(triggered()),this,SLOT(ad dNewSvar()));
}
----------- h file-----------
#ifndef FRAGA_H
#define FRAGA_H
#include <QtCore>
#include <QtGui>

class Fraga:public QGraphicsRectItem{
Q_OBJECT
public:
Fraga();
public slots:
void addNewSvar();
protected:
QAction* _nyttsvar;
};


#endif

I do not understand what's wrong.

Gopala Krishna
14th January 2007, 15:14
class Fraga:public QGraphicsRectItem{
Q_OBJECT
public:
Fraga();


I do not understand what's wrong.

You are forgetting a fact that QGraphics*Item do not inherit QObject and connect method is provided by QObject.
Try this, it should most probably work


class Fraga : public QObject, public QGraphicsRectItem

Morea
14th January 2007, 16:27
Great. It works now.