PDA

View Full Version : QObject::connect: No such signal



caseyong
18th February 2008, 08:59
Hi,

I am a newbie to qt... I thought I followed the obvious steps to define "signal" for a customized widget (in my example, BinaryButtonWg). i.e.,

1. declare the signal in BinaryButtonWg.h
2. connect signal and slot with same arguments
3. emit signal

... But, somehow, there is always a complain of QObject::connect No such signal, when I try to connect the signal in my application of the BinaryButtonWg class.

And, when I use dumpObjectInfo(), it showed

OBJECT BinaryButtonWg::mask
SIGNALS OUT
<None>
SIGNALS IN
QHButtonGroup::unnamed


I believe I could have missed out something fundamental.. I will appreciate your help.. Following are my codes of BinaryButtonWg:

BinaryButtonWg.h

#ifndef BINARYBUTTONWG_H
#define BINARYBUTTONWG_H

#include <qwidget.h>
#include <qhbuttongroup.h>
#include <qvbox.h>
#include <qsize.h>

class BinaryButtonWg : public QWidget
{
Q_OBJECT
public:
BinaryButtonWg(QSize bsize, unsigned int bitsize=8, QWidget *parent = 0, const char *name = 0 , const char *title = 0);
~BinaryButtonWg() {};


public slots:
void enableBits(unsigned int bits);

private slots:
void buttonPressed(int buttonId);
signals:
void bbChanged(unsigned int newValue);
private:
QHButtonGroup* _bg;
QVBox* _vb;
unsigned int _value;
unsigned int _bitsize;

};

#endif

In BinaryButtonWg.cpp,


BinaryButtonWg::BinaryButtonWg(QSize bsize, unsigned int bitsize, QWidget *parent, const char *name , const char* title ): QWidget(parent, name, 0)
{
_bg = new QHButtonGroup(_vb);
.
.
// this one work fine
connect( _bg, SIGNAL( clicked(int) ), this, SLOT( buttonPressed(int)));
}

void BinaryButtonWg::buttonPressed( int buttonId)
{
_value ^= (1 << buttonId);
printf("buttonPressed! new value: 0x%02X\n", _value);
emit this->bbChanged(_value);
}


Rgds

Casey

marcel
18th February 2008, 09:16
The connect statement must contain the exact signature of the signal and slot.
The slot and signal take an unsigned int parameter, however you pass them to connect as taking an int.

Modify the connect.

caseyong
19th February 2008, 06:41
Hello Marcel,

thanks.. But, I actually did connect with unsigned int as seen in the test codes below:


#include <qapplication.h>
#include <qlayout.h>
#include "BinaryButtonWg.h"

int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
QWidget* widget = new QWidget();
widget->setFixedSize(QSize(500,300));
QHBoxLayout* hlayout = new QHBoxLayout(widget);
BinaryButtonWg maskbb(QSize(200, 40), 12, widget);
BinaryButtonWg valuebb(QSize(200, 40), 12, widget);
hlayout->addWidget( &maskbb);
hlayout->addWidget( &valuebb);
app.setMainWidget( widget );
QObject::connect(&maskbb, SIGNAL( bbChanged(unsigned int newValue) ),
&valuebb, SLOT( enableBits(unsigned int bits) ));

widget->show();
return app.exec();
}

But, still has the same complaint:


QObject::connect: No such signal BinaryButtonWg::bbChanged(unsigned int newValue)
QObject::connect: (sender name: 'unnamed')
QObject::connect: (receiver name: 'unnamed')

Thanks...

Casey

jpn
19th February 2008, 06:48
Do not put parameter names to connect-statement:

QObject::connect(&maskbb, SIGNAL( bbChanged(unsigned int) ),
&valuebb, SLOT( enableBits(unsigned int) ));

caseyong
19th February 2008, 06:52
If dumpObjectInfo() shows
SIGNALS OUT
<None>
SIGNALS IN
QHButtonGroup::unnamed

will that have confirmed there is no out signal from the object? Are there alternatives of checking for SIGNALs other than dumpObjectInfo()?

Thanks..

Casey

caseyong
19th February 2008, 07:23
Hello J-P,

thankyou !! that is the error...

Casey