views:

122

answers:

3
class myslot
    {

public:
    Q_OBJECT

    myslot()
        {

        }
    ~myslot()
        {

        }

    typedef enum  Emycars{volvo,benz,tata}cars;


public slots: 
void hellowslot(myslot::cars);
    };

void myslot::hellowslot(myslot::cars cars1)
    {

    }


class mysignal
    {
public:
    Q_OBJECT

public:
      mysignal(myslot *ourslot)
          {

     bool val = QObject::connect(this,SIGNAL(hellowsignal(myslot::Emycars)),ourslot,SLOT(hellowslot(myslot::Emycars)));
          }
      ~mysignal()
          {

          }

signals: 
void hellowsignal(myslot::Emycars);


    };

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    myslot slot;
    mysignal sig(&slot);


   // DeleteNow w;
   // w.showMaximized();
    return a.exec();
}

what is the mistake in mycode, the way which i have written connect for the function which recive enum is right or not? please let me know where i am wrong.

+6  A: 

In order to use the signal/slot mechanism the classes must inherit from QObject (either directly or from a subclass of QObject like QWidget) and declare themselves as such using the Q_OBJECT macro.

So, both your mysignaland myslot must inherit from QObject.

Moreover you must place the macro right after the opening brace of your class, this should give:

class myslot : public QObject
{
    Q_OBJECT
public:
// .../... 
};

class mysignal : public QObject
{
    Q_OBJECT
public:
// .../... 
};
gregseth
A: 

@gregseth is right. But wasn't there any clue in compiler's output?

Lucian
A: 

You have problem with signal/slot connection ? If yes, then maybe you should do:

bool val = QObject::connect( this, SIGNAL(hellowsignal(myslot::cars)), ourslot, SLOT(hellowslot(myslot::cars)));

becouse you declared your slots with myslot::cars and not myslot::Emycars. Metaobject compiler simply creates strings that are related to your slots, thats why your connection may not work.

Kamil Klimek