PDA

View Full Version : Issue in using dynamic property in QT inherited classes.



Ratheendrans
25th August 2010, 15:38
Hi want to add a new Q_PROPERY into my subclass and use this in my application.

I tried the following test programe.

Scenario 1:
1. created the following class as a subclass of QPushButton.

class eSSlButton:public QPushButton
{
Q_OBJECT
// Q_PROPERTY(char val READ getVal)
public:
eSSlButton(QWidget * parent = 0);
~eSSlButton();
void keyPressEvent( QKeyEvent *e );
};

definition for the above class

eSSlButton::eSSlButton(QWidget * parent):QPushButton(parent)
{

}

void eSSlButton::keyPressEvent( QKeyEvent *e )
{

printf("In side dbasbd %c %x\n",QObject::property("val").toChar(),e->key());
}

eSSlButton::~eSSlButton()
{

}

2. Now added the properties 'val' as char type from property window of Qt Designer.

3. Now when I run the executable it gives a segmentation fault.


Kindly let me know how to set the dynamic property for the subclass with the help of QT Designer.

Thanks in Advance

Lykurg
25th August 2010, 16:21
You can't define new properties using the designer. You have to code them yourself. Which is your commented line and then you must of course provide the setter and getter function.