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
#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
To copy to clipboard, switch view to plain text mode
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);
}
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);
}
To copy to clipboard, switch view to plain text mode
Rgds
Casey
Bookmarks